Spaces:
Sleeping
Sleeping
Update agent.py
Browse files
agent.py
CHANGED
@@ -152,25 +152,41 @@ tools = [
|
|
152 |
]
|
153 |
|
154 |
# Build graph function
|
155 |
-
def build_graph(provider: str = "
|
156 |
"""Build the graph"""
|
157 |
-
|
158 |
if provider == "google":
|
159 |
# Google Gemini
|
160 |
-
llm = ChatGoogleGenerativeAI(
|
161 |
-
|
162 |
-
|
163 |
-
|
|
|
|
|
164 |
elif provider == "huggingface":
|
165 |
-
# Hugging Face
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
166 |
llm = ChatHuggingFace(
|
167 |
llm=HuggingFaceEndpoint(
|
168 |
-
url=
|
169 |
temperature=0,
|
170 |
-
|
|
|
171 |
)
|
|
|
172 |
else:
|
173 |
-
raise ValueError("Invalid provider. Choose 'google'
|
|
|
|
|
174 |
|
175 |
# Bind tools to LLM
|
176 |
llm_with_tools = llm.bind_tools(tools)
|
|
|
152 |
]
|
153 |
|
154 |
# Build graph function
|
155 |
+
def build_graph(provider: str = "huggingface", huggingface_model: str = "mistral"):
|
156 |
"""Build the graph"""
|
157 |
+
|
158 |
if provider == "google":
|
159 |
# Google Gemini
|
160 |
+
llm = ChatGoogleGenerativeAI(
|
161 |
+
model="gemini-2.0-flash",
|
162 |
+
temperature=0,
|
163 |
+
google_api_key=os.getenv("GOOGLE_API_KEY")
|
164 |
+
)
|
165 |
+
|
166 |
elif provider == "huggingface":
|
167 |
+
# Choose between supported Hugging Face models
|
168 |
+
if huggingface_model == "mistral":
|
169 |
+
model_url = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.1"
|
170 |
+
elif huggingface_model == "llama":
|
171 |
+
model_url = "https://api-inference.huggingface.co/models/Meta-DeepLearning/llama-2-7b-chat-hf"
|
172 |
+
else:
|
173 |
+
raise ValueError("Unsupported Hugging Face model")
|
174 |
+
|
175 |
+
hf_token = os.getenv("HUGGINGFACE_API_TOKEN")
|
176 |
+
headers = {"Authorization": f"Bearer {hf_token}"} if hf_token else {}
|
177 |
+
|
178 |
llm = ChatHuggingFace(
|
179 |
llm=HuggingFaceEndpoint(
|
180 |
+
url=model_url,
|
181 |
temperature=0,
|
182 |
+
headers=headers
|
183 |
+
)
|
184 |
)
|
185 |
+
|
186 |
else:
|
187 |
+
raise ValueError("Invalid provider. Choose 'google' or 'huggingface'.")
|
188 |
+
|
189 |
+
return llm
|
190 |
|
191 |
# Bind tools to LLM
|
192 |
llm_with_tools = llm.bind_tools(tools)
|