Commit
·
6a7aabe
1
Parent(s):
596e446
added stuff
Browse files
app.py
CHANGED
@@ -212,6 +212,7 @@ from smolagents import (
|
|
212 |
FinalAnswerTool,
|
213 |
PythonInterpreterTool
|
214 |
)
|
|
|
215 |
|
216 |
# (Keep Constants as is)
|
217 |
# --- Constants ---
|
@@ -223,6 +224,13 @@ from smolagents import CodeAgent, HfApiModel
|
|
223 |
import os
|
224 |
from smolagents import HfApiModel
|
225 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
226 |
|
227 |
# --- Agent Definition ---
|
228 |
class BasicAgent:
|
@@ -235,6 +243,15 @@ class BasicAgent:
|
|
235 |
raise ValueError("Missing OpenAI API token!")
|
236 |
|
237 |
# Initialize model and tools
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
238 |
model = OpenAIServerModel(
|
239 |
#api_base="openai",
|
240 |
api_key=openai_token,
|
@@ -254,7 +271,7 @@ class BasicAgent:
|
|
254 |
|
255 |
# Build the agent
|
256 |
self.agent = CodeAgent(
|
257 |
-
model=
|
258 |
prompt_templates=prompt_templates,
|
259 |
tools=[search_tool, reverse_tool, table_tool, veg_tool, python_tool, exfood_tool], #final_answer_tool
|
260 |
add_base_tools=True,
|
|
|
212 |
FinalAnswerTool,
|
213 |
PythonInterpreterTool
|
214 |
)
|
215 |
+
from huggingface_hub import login, InferenceClient
|
216 |
|
217 |
# (Keep Constants as is)
|
218 |
# --- Constants ---
|
|
|
224 |
import os
|
225 |
from smolagents import HfApiModel
|
226 |
|
227 |
+
class CustomModel(Model):
|
228 |
+
def generate(messages, stop_sequences=["Task"]):
|
229 |
+
response = client.chat_completion(messages, stop=stop_sequences, max_tokens=1024)
|
230 |
+
answer = response.choices[0].message
|
231 |
+
return answer
|
232 |
+
|
233 |
+
|
234 |
|
235 |
# --- Agent Definition ---
|
236 |
class BasicAgent:
|
|
|
243 |
raise ValueError("Missing OpenAI API token!")
|
244 |
|
245 |
# Initialize model and tools
|
246 |
+
|
247 |
+
model_id = "meta-llama/Llama-3.2-1B-Instruct"
|
248 |
+
|
249 |
+
|
250 |
+
client = InferenceClient(model=model_id)
|
251 |
+
|
252 |
+
custom_model = CustomModel(client)
|
253 |
+
|
254 |
+
|
255 |
model = OpenAIServerModel(
|
256 |
#api_base="openai",
|
257 |
api_key=openai_token,
|
|
|
271 |
|
272 |
# Build the agent
|
273 |
self.agent = CodeAgent(
|
274 |
+
model=custom_model,
|
275 |
prompt_templates=prompt_templates,
|
276 |
tools=[search_tool, reverse_tool, table_tool, veg_tool, python_tool, exfood_tool], #final_answer_tool
|
277 |
add_base_tools=True,
|