Skip to content

Commit 308631a

Browse files
committed
Add LLM's HuggingFaceHub
1 parent 2ab51d0 commit 308631a

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

.env_example

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
OPENAI_API_KEY=FILL-IN-YOUR-OPENAI-API-KEY
2-
#OPENAI_API_BASE=optional-your_openai_api_base
3-
#GROQ_API_KEY=optional-your_groq_api_key
4-
#LMSTUDIO_API_BASE=http://localhost:1234/v1
1+
OPENAI_API_KEY="FILL-IN-YOUR-OPENAI-API-KEY"
2+
# OPENAI_API_BASE="optional-your_openai_api_base"
3+
# GROQ_API_KEY="optional-your_groq_api_key"
4+
# LMSTUDIO_API_BASE="http://localhost:1234/v1"
5+
GEMINI_API_KEY="FILL-IN-YOUR-GEMINI-API-KEY"
6+
HUGGINGFACEHUB_API_KEY="FILL-IN-YOUR-HUGGINGFACEHUB-API-TOKEN"

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ app/__pycache__/*
1717
data
1818
data/*
1919
db/
20-
db/*
20+
db/*
21+
stop_venv.bat

app/llms.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from langchain_openai import ChatOpenAI
33
from langchain_groq import ChatGroq
44
from langchain_google_genai import ChatGoogleGenerativeAI
5+
from langchain.llms import HuggingFaceHub
56

67
def create_openai_llm(model, temperature):
78
api_key = os.getenv('OPENAI_API_KEY')
@@ -25,6 +26,13 @@ def create_googleai_llm(model, temperature):
2526
else:
2627
raise ValueError("Google AI API key not set in .env file")
2728

29+
def create_huggingfacehub_llm(model, temperature):
30+
api_key = os.getenv('HUGGINGFACE_API_KEY')
31+
if api_key:
32+
return HuggingFaceHub(repo_id=model, model_kwargs={"temperature":temperature, "max_tokens": 4096})
33+
else:
34+
raise ValueError("HuggingFace API key not set in .env file")
35+
2836
def create_lmstudio_llm(model, temperature):
2937
api_base = os.getenv('LMSTUDIO_API_BASE')
3038
if api_base:
@@ -45,6 +53,10 @@ def create_lmstudio_llm(model, temperature):
4553
"models": ["gemini-1.5-pro","gemini-1.5-flash", "gemini-1.0-pro"],
4654
"create_llm": create_googleai_llm
4755
},
56+
"HuggingFaceHub": {
57+
"models": ["mistralai/Mistral-7B-Instruct-v0.2", "mistralai/Codestral-22B-v0.1", "EleutherAI/gpt-neo-2.7B"],
58+
"create_llm": create_huggingfacehub_llm
59+
},
4860
"LM Studio": {
4961
"models": ["default"],
5062
"create_llm": create_lmstudio_llm

0 commit comments

Comments
 (0)