Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,58 +16,32 @@ class BasicAgent:
|
|
| 16 |
print("BasicAgent initialized.")
|
| 17 |
|
| 18 |
# Create model using Hugging Face Inference API
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
# HF_TOKEN will be automatically used if set in environment
|
| 26 |
-
max_tokens=1024
|
| 27 |
-
)
|
| 28 |
-
print("Initialized Hugging Face Inference API model")
|
| 29 |
-
except Exception as e:
|
| 30 |
-
print(f"Error initializing HF model: {e}")
|
| 31 |
-
# Fallback to a simpler approach if model fails
|
| 32 |
-
self.model = None
|
| 33 |
|
| 34 |
-
# Create the CodeAgent with tools
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
)
|
| 46 |
-
print("CodeAgent with tools initialized successfully")
|
| 47 |
-
except Exception as e:
|
| 48 |
-
print(f"Error initializing CodeAgent: {e}")
|
| 49 |
-
self.agent = None
|
| 50 |
-
else:
|
| 51 |
-
self.agent = None
|
| 52 |
|
| 53 |
def __call__(self, question: str) -> str:
|
| 54 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
print(f"Agent returning answer: {answer[:100]}...")
|
| 61 |
-
return answer
|
| 62 |
-
except Exception as e:
|
| 63 |
-
print(f"Error in agent processing: {e}")
|
| 64 |
-
# Return a fallback answer in case of errors
|
| 65 |
-
return f"Error processing question: {str(e)}"
|
| 66 |
-
else:
|
| 67 |
-
# Fallback if agent initialization failed
|
| 68 |
-
fallback_answer = "Agent initialization failed. Please check model configuration."
|
| 69 |
-
print(f"Agent returning fallback answer: {fallback_answer}")
|
| 70 |
-
return fallback_answer
|
| 71 |
|
| 72 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
| 73 |
"""
|
|
|
|
| 16 |
print("BasicAgent initialized.")
|
| 17 |
|
| 18 |
# Create model using Hugging Face Inference API
|
| 19 |
+
self.model = LiteLLMModel(
|
| 20 |
+
model_id="huggingface/meta-llama/Llama-3.2-3B-Instruct",
|
| 21 |
+
api_base="https://api-inference.huggingface.co/models/",
|
| 22 |
+
max_tokens=1024
|
| 23 |
+
)
|
| 24 |
+
print("Initialized Hugging Face Inference API model")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
# Create the CodeAgent with tools
|
| 27 |
+
self.agent = CodeAgent(
|
| 28 |
+
tools=[
|
| 29 |
+
DuckDuckGoSearchTool(),
|
| 30 |
+
VisitWebpageTool(),
|
| 31 |
+
FinalAnswerTool()
|
| 32 |
+
],
|
| 33 |
+
model=self.model,
|
| 34 |
+
additional_authorized_imports=["wikipedia", "requests", "json", "re", "datetime", "os"]
|
| 35 |
+
)
|
| 36 |
+
print("CodeAgent with tools initialized successfully")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
def __call__(self, question: str) -> str:
|
| 39 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 40 |
|
| 41 |
+
# Use smolagents CodeAgent to process the question
|
| 42 |
+
answer = self.agent.run(question)
|
| 43 |
+
print(f"Agent returning answer: {answer[:100]}...")
|
| 44 |
+
return answer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
| 47 |
"""
|