Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,25 +4,39 @@ import requests
|
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
|
|
|
|
| 7 |
|
|
|
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
-
# (Keep Constants as is)
|
| 12 |
-
# --- Constants ---
|
| 13 |
-
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 14 |
-
|
| 15 |
# --- Basic Agent Definition ---
|
| 16 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 17 |
-
class
|
| 18 |
def __init__(self):
|
| 19 |
print("BasicAgent initialized.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
def __call__(self, question: str) -> str:
|
| 21 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 22 |
fixed_answer = "This is a default answer."
|
| 23 |
print(f"Agent returning fixed answer: {fixed_answer}")
|
| 24 |
return fixed_answer
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 27 |
"""
|
| 28 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
|
@@ -44,7 +58,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 44 |
|
| 45 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
| 46 |
try:
|
| 47 |
-
agent =
|
| 48 |
except Exception as e:
|
| 49 |
print(f"Error instantiating agent: {e}")
|
| 50 |
return f"Error initializing agent: {e}", None
|
|
|
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
|
| 7 |
+
# agent modules
|
| 8 |
|
| 9 |
+
from llama_index.agent.openai import OpenAIAgent
|
| 10 |
+
from llama_index.agent.openai import OpenAIAssistantAgent
|
| 11 |
|
| 12 |
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
# --- Basic Agent Definition ---
|
| 15 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 16 |
+
class OpenAIAgent:
|
| 17 |
def __init__(self):
|
| 18 |
print("BasicAgent initialized.")
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
|
| 24 |
def __call__(self, question: str) -> str:
|
| 25 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 26 |
fixed_answer = "This is a default answer."
|
| 27 |
print(f"Agent returning fixed answer: {fixed_answer}")
|
| 28 |
return fixed_answer
|
| 29 |
|
| 30 |
+
|
| 31 |
+
#####
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
|
| 40 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 41 |
"""
|
| 42 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
|
|
|
| 58 |
|
| 59 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
| 60 |
try:
|
| 61 |
+
agent = OpenAIAgent()
|
| 62 |
except Exception as e:
|
| 63 |
print(f"Error instantiating agent: {e}")
|
| 64 |
return f"Error initializing agent: {e}", None
|