Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,9 +6,13 @@ import pandas as pd
|
|
| 6 |
import logging
|
| 7 |
from typing import Optional, List
|
| 8 |
from smolagents import (
|
|
|
|
| 9 |
CodeAgent, InferenceClientModel, DuckDuckGoSearchTool, GoogleSearchTool,
|
| 10 |
VisitWebpageTool,
|
| 11 |
LiteLLMModel,AzureOpenAIServerModel, WikipediaSearchTool,PythonInterpreterTool)
|
|
|
|
|
|
|
|
|
|
| 12 |
# (Keep Constants as is)
|
| 13 |
# --- Constants ---
|
| 14 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
@@ -64,10 +68,26 @@ class BasicAgent:
|
|
| 64 |
api_key=os.environ.get("AZURE_OPENAI_API_KEY"),
|
| 65 |
api_version="2024-12-01-preview" #2024-02-15-preview
|
| 66 |
)
|
| 67 |
-
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
self.tools = [
|
| 70 |
WikipediaSearchTool(),
|
|
|
|
| 71 |
# DuckDuckGoSearchTool(),
|
| 72 |
# PythonInterpreterTool(),
|
| 73 |
# VisitWebpageTool()
|
|
@@ -192,6 +212,8 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 192 |
print("Agent did not produce any answers to submit.")
|
| 193 |
return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
|
| 194 |
|
|
|
|
|
|
|
| 195 |
# 4. Prepare Submission
|
| 196 |
submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
|
| 197 |
status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
|
|
|
|
| 6 |
import logging
|
| 7 |
from typing import Optional, List
|
| 8 |
from smolagents import (
|
| 9 |
+
MCPClient,
|
| 10 |
CodeAgent, InferenceClientModel, DuckDuckGoSearchTool, GoogleSearchTool,
|
| 11 |
VisitWebpageTool,
|
| 12 |
LiteLLMModel,AzureOpenAIServerModel, WikipediaSearchTool,PythonInterpreterTool)
|
| 13 |
+
from mcp import StdioServerParameters
|
| 14 |
+
|
| 15 |
+
|
| 16 |
# (Keep Constants as is)
|
| 17 |
# --- Constants ---
|
| 18 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
|
|
| 68 |
api_key=os.environ.get("AZURE_OPENAI_API_KEY"),
|
| 69 |
api_version="2024-12-01-preview" #2024-02-15-preview
|
| 70 |
)
|
| 71 |
+
|
| 72 |
+
server_parameters = StdioServerParameters(
|
| 73 |
+
command="uvx", # Using uvx ensures dependencies are available
|
| 74 |
+
args=["--quiet", "pubmedmcp@0.1.3"],
|
| 75 |
+
env={"UV_PYTHON": "3.12", **os.environ},
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
try:
|
| 80 |
+
self.mcp_client = MCPClient(server_parameters)
|
| 81 |
+
# tools = mcp_client.get_tools()
|
| 82 |
+
# agent = CodeAgent(tools=tools, model=model, add_base_tools=True)
|
| 83 |
+
# agent.run("Donner la definition de mesure pour un etudiant de licence 3 en mathematique")
|
| 84 |
+
except:
|
| 85 |
+
print("🥵 🥵erreur lors de la connexion au serveur mcp")
|
| 86 |
+
|
| 87 |
+
# Initialize tools
|
| 88 |
self.tools = [
|
| 89 |
WikipediaSearchTool(),
|
| 90 |
+
self.mcp_client.get_tools()
|
| 91 |
# DuckDuckGoSearchTool(),
|
| 92 |
# PythonInterpreterTool(),
|
| 93 |
# VisitWebpageTool()
|
|
|
|
| 212 |
print("Agent did not produce any answers to submit.")
|
| 213 |
return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
|
| 214 |
|
| 215 |
+
# se deconnecter du serveur mcp
|
| 216 |
+
self.mcp_client.disconnect()
|
| 217 |
# 4. Prepare Submission
|
| 218 |
submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
|
| 219 |
status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
|