Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,8 @@ import inspect
|
|
| 5 |
import pandas as pd
|
| 6 |
import json
|
| 7 |
|
|
|
|
|
|
|
| 8 |
# (Keep Constants as is)
|
| 9 |
# --- Constants ---
|
| 10 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
@@ -20,46 +22,66 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 20 |
|
| 21 |
class BasicAgent:
|
| 22 |
def __init__(self):
|
| 23 |
-
|
| 24 |
-
|
| 25 |
print("BasicAgent initialized.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
def __call__(self, question: str) -> str:
|
| 27 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
response = requests.post(url, headers=headers, data=json.dumps(payload))
|
| 55 |
|
| 56 |
|
| 57 |
-
response_data = response.json()
|
| 58 |
-
assistant_reply = response_data["choices"][0]["message"]["content"]
|
| 59 |
|
| 60 |
|
| 61 |
-
fixed_answer = assistant_reply
|
| 62 |
-
#fixed_answer = "This is a default answer."
|
| 63 |
|
| 64 |
|
| 65 |
|
|
@@ -67,7 +89,7 @@ class BasicAgent:
|
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
-
print(f"Agent returning fixed answer: {fixed_answer}")
|
| 71 |
return fixed_answer
|
| 72 |
|
| 73 |
|
|
|
|
| 5 |
import pandas as pd
|
| 6 |
import json
|
| 7 |
|
| 8 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, InferenceClientModel, load_tool, tool
|
| 9 |
+
|
| 10 |
# (Keep Constants as is)
|
| 11 |
# --- Constants ---
|
| 12 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
|
|
| 22 |
|
| 23 |
class BasicAgent:
|
| 24 |
def __init__(self):
|
| 25 |
+
final_answer = FinalAnswerTool()
|
|
|
|
| 26 |
print("BasicAgent initialized.")
|
| 27 |
+
|
| 28 |
+
model = = OpenAIServerModel(
|
| 29 |
+
api_key="fw_3ZSrkw3Qv5eeA1yx65x1eD5H",
|
| 30 |
+
api_base="https://api.fireworks.ai/inference/v1",
|
| 31 |
+
model_id="accounts/fireworks/models/qwen2p5-72b-instruct",
|
| 32 |
+
temperature = 0.1,
|
| 33 |
+
max_tokens = 100
|
| 34 |
+
#top_p = 1
|
| 35 |
+
|
| 36 |
def __call__(self, question: str) -> str:
|
| 37 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
uav_agent = CodeAgent(
|
| 41 |
+
tools=[final_answer, DuckDuckGoSearchTool],#[detection_tool],
|
| 42 |
+
model=model,
|
| 43 |
+
max_steps=5,
|
| 44 |
+
verbosity_level=1,
|
| 45 |
+
planning_interval=2,
|
| 46 |
+
#additional_authorized_imports=["json", "from PIL import Image, ImageDraw, ImageFont", "import matplotlib.pyplot as plt", "from typing import List, Dict"],
|
| 47 |
+
#managed_agents=[detection_agent]
|
| 48 |
+
name="agent_instance",
|
| 49 |
+
description="Solves the task"
|
| 50 |
+
)
|
| 51 |
|
| 52 |
|
| 53 |
+
# url = "https://api.fireworks.ai/inference/v1/chat/completions"
|
| 54 |
+
# payload = {
|
| 55 |
+
# "model": "accounts/fireworks/models/qwen2p5-72b-instruct",
|
| 56 |
+
# "max_tokens": 100,
|
| 57 |
+
# "top_p": 1,
|
| 58 |
+
# "top_k": 40,
|
| 59 |
+
# "presence_penalty": 0,
|
| 60 |
+
# "frequency_penalty": 0,
|
| 61 |
+
# "temperature": 0.05,
|
| 62 |
+
# "messages": [
|
| 63 |
+
# {
|
| 64 |
+
# "role": "user",
|
| 65 |
+
# "content": f"""{question} Provide only what is requested in answer SHORTLY. If there is requested to provide ONE word, provide it.
|
| 66 |
+
# THis is for the Benchmark evaluation, so the answer should be REALLY SHORT and ACCURATE.
|
| 67 |
+
# """
|
| 68 |
+
# }
|
| 69 |
+
# ]
|
| 70 |
+
# }
|
| 71 |
+
# headers = {
|
| 72 |
+
# "Accept": "application/json",
|
| 73 |
+
# "Content-Type": "application/json",
|
| 74 |
+
# "Authorization": "Bearer fw_3ZSrkw3Qv5eeA1yx65x1eD5H"
|
| 75 |
+
# }
|
| 76 |
+
# response = requests.post(url, headers=headers, data=json.dumps(payload))
|
|
|
|
| 77 |
|
| 78 |
|
| 79 |
+
# response_data = response.json()
|
| 80 |
+
# assistant_reply = response_data["choices"][0]["message"]["content"]
|
| 81 |
|
| 82 |
|
| 83 |
+
# fixed_answer = assistant_reply
|
| 84 |
+
# #fixed_answer = "This is a default answer."
|
| 85 |
|
| 86 |
|
| 87 |
|
|
|
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
+
# print(f"Agent returning fixed answer: {fixed_answer}")
|
| 93 |
return fixed_answer
|
| 94 |
|
| 95 |
|