Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,16 +2,15 @@ import os
|
|
| 2 |
import requests
|
| 3 |
import pandas as pd
|
| 4 |
import gradio as gr
|
| 5 |
-
from smolagents import CodeAgent, DuckDuckGoSearchTool,
|
| 6 |
|
| 7 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 8 |
-
MODEL_ID = "Qwen/Qwen2.5-Coder-32B-Instruct"
|
| 9 |
|
| 10 |
def create_agent(token: str):
|
| 11 |
-
|
| 12 |
-
model = HfApiModel(
|
| 13 |
model_id=MODEL_ID,
|
| 14 |
-
|
| 15 |
)
|
| 16 |
search_tool = DuckDuckGoSearchTool()
|
| 17 |
|
|
@@ -22,7 +21,7 @@ def create_agent(token: str):
|
|
| 22 |
"requests", "bs4", "re", "math", "datetime",
|
| 23 |
"json", "pandas", "numpy", "urllib"
|
| 24 |
],
|
| 25 |
-
max_steps=12,
|
| 26 |
verbosity_level=1
|
| 27 |
)
|
| 28 |
return agent
|
|
@@ -35,11 +34,9 @@ def solve_question(agent, question: str) -> str:
|
|
| 35 |
raw_ans = agent.run(question)
|
| 36 |
ans = str(raw_ans).strip()
|
| 37 |
|
| 38 |
-
# Берём последнюю строчку ответа агента
|
| 39 |
if "\n" in ans:
|
| 40 |
ans = ans.split("\n")[-1].strip()
|
| 41 |
|
| 42 |
-
# Жёстко обрезаем длинный текст, чтобы сервер оценки не падал с ошибкой 500
|
| 43 |
if len(ans) > 80:
|
| 44 |
ans = ans[:80].strip()
|
| 45 |
|
|
|
|
| 2 |
import requests
|
| 3 |
import pandas as pd
|
| 4 |
import gradio as gr
|
| 5 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, LiteLLMModel
|
| 6 |
|
| 7 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 8 |
+
MODEL_ID = "huggingface/Qwen/Qwen2.5-Coder-32B-Instruct"
|
| 9 |
|
| 10 |
def create_agent(token: str):
|
| 11 |
+
model = LiteLLMModel(
|
|
|
|
| 12 |
model_id=MODEL_ID,
|
| 13 |
+
api_key=token
|
| 14 |
)
|
| 15 |
search_tool = DuckDuckGoSearchTool()
|
| 16 |
|
|
|
|
| 21 |
"requests", "bs4", "re", "math", "datetime",
|
| 22 |
"json", "pandas", "numpy", "urllib"
|
| 23 |
],
|
| 24 |
+
max_steps=12,
|
| 25 |
verbosity_level=1
|
| 26 |
)
|
| 27 |
return agent
|
|
|
|
| 34 |
raw_ans = agent.run(question)
|
| 35 |
ans = str(raw_ans).strip()
|
| 36 |
|
|
|
|
| 37 |
if "\n" in ans:
|
| 38 |
ans = ans.split("\n")[-1].strip()
|
| 39 |
|
|
|
|
| 40 |
if len(ans) > 80:
|
| 41 |
ans = ans[:80].strip()
|
| 42 |
|