Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,8 +14,17 @@ class BasicAgent:
|
|
| 14 |
def __init__(self):
|
| 15 |
print("Inicializando o agente GAIA...")
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
self.model = LiteLLMModel(
|
| 18 |
-
model_id="huggingface/Qwen/Qwen2.5-Coder-32B-Instruct"
|
|
|
|
| 19 |
)
|
| 20 |
self.agent = CodeAgent(
|
| 21 |
tools=[DuckDuckGoSearchTool()],
|
|
@@ -46,7 +55,21 @@ If a number is requested, return only that number.
|
|
| 46 |
if not question:
|
| 47 |
raise ValueError("Digite uma pergunta para testar o agente.")
|
| 48 |
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
return str(result).replace("FINAL ANSWER", "").strip()
|
| 51 |
|
| 52 |
|
|
|
|
| 14 |
def __init__(self):
|
| 15 |
print("Inicializando o agente GAIA...")
|
| 16 |
|
| 17 |
+
hf_token = os.getenv("HF_TOKEN")
|
| 18 |
+
if not hf_token:
|
| 19 |
+
raise RuntimeError(
|
| 20 |
+
"O secret HF_TOKEN não está configurado no Hugging Face Space. "
|
| 21 |
+
"Crie um token com permissão de inferência e adicione-o em "
|
| 22 |
+
"Settings > Secrets."
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
self.model = LiteLLMModel(
|
| 26 |
+
model_id="huggingface/Qwen/Qwen2.5-Coder-32B-Instruct",
|
| 27 |
+
api_key=hf_token,
|
| 28 |
)
|
| 29 |
self.agent = CodeAgent(
|
| 30 |
tools=[DuckDuckGoSearchTool()],
|
|
|
|
| 55 |
if not question:
|
| 56 |
raise ValueError("Digite uma pergunta para testar o agente.")
|
| 57 |
|
| 58 |
+
try:
|
| 59 |
+
result = self.agent.run(question)
|
| 60 |
+
except Exception as exc:
|
| 61 |
+
error_text = str(exc)
|
| 62 |
+
if (
|
| 63 |
+
"AuthenticationError" in error_text
|
| 64 |
+
or "401" in error_text
|
| 65 |
+
or "Unauthorized" in error_text
|
| 66 |
+
):
|
| 67 |
+
raise RuntimeError(
|
| 68 |
+
"Falha de autenticação no modelo. Verifique se o secret "
|
| 69 |
+
"HF_TOKEN contém um token válido com permissão para usar "
|
| 70 |
+
"Inference Providers."
|
| 71 |
+
) from exc
|
| 72 |
+
raise
|
| 73 |
return str(result).replace("FINAL ANSWER", "").strip()
|
| 74 |
|
| 75 |
|