Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,36 +11,26 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 11 |
|
| 12 |
# --- Basic Agent Definition ---
|
| 13 |
|
| 14 |
-
|
| 15 |
-
model = HfApiModel(
|
| 16 |
-
max_tokens=2096,
|
| 17 |
-
temperature=0.5,
|
| 18 |
-
model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud',# it is possible that this model may be overloaded
|
| 19 |
-
custom_role_conversions=None,
|
| 20 |
-
)
|
| 21 |
class BasicAgent:
|
| 22 |
-
def __init__(self):
|
|
|
|
| 23 |
print("BasicAgent initialized.")
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
If you are asked for a comma separated list, apply the above rules depending of whether the element
|
| 35 |
-
to be put in the list is a number or a string.
|
| 36 |
-
"""
|
| 37 |
-
self.agent.prompt_templates["system_prompt"] = self.agent.prompt_templates["system_prompt"] + SYSTEM_PROMPT
|
| 38 |
-
|
| 39 |
def __call__(self, question: str) -> str:
|
| 40 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 41 |
-
|
| 42 |
-
print(f"Agent returning
|
| 43 |
-
return
|
| 44 |
|
| 45 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 46 |
"""
|
|
|
|
| 11 |
|
| 12 |
# --- Basic Agent Definition ---
|
| 13 |
|
| 14 |
+
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
class BasicAgent:
|
| 16 |
+
def __init__(self, openai_key):
|
| 17 |
+
self.openai_key = openai_key
|
| 18 |
print("BasicAgent initialized.")
|
| 19 |
+
# Initialize the model
|
| 20 |
+
#model = HfApiModel()
|
| 21 |
+
model = OpenAIServerModel(model_id="gpt-4.1", api_key=self.openai_key)
|
| 22 |
+
# Initialize the search tool
|
| 23 |
+
search_tool = DuckDuckGoSearchTool()
|
| 24 |
+
# Initialize Agent
|
| 25 |
+
self.agent = CodeAgent(
|
| 26 |
+
model = model,
|
| 27 |
+
tools=[search_tool]
|
| 28 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
def __call__(self, question: str) -> str:
|
| 30 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 31 |
+
fixed_answer =self.agent.run(question)
|
| 32 |
+
print(f"Agent returning fixed answer: {fixed_answer}")
|
| 33 |
+
return fixed_answer
|
| 34 |
|
| 35 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 36 |
"""
|