Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,12 +12,25 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 13 |
class BasicAgent:
|
| 14 |
def __init__(self):
|
|
|
|
|
|
|
| 15 |
print("BasicAgent initialized.")
|
| 16 |
def __call__(self, question: str) -> str:
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 23 |
"""
|
|
|
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 13 |
class BasicAgent:
|
| 14 |
def __init__(self):
|
| 15 |
+
from openai import OpenAI
|
| 16 |
+
self.llm = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
|
| 17 |
print("BasicAgent initialized.")
|
| 18 |
def __call__(self, question: str) -> str:
|
| 19 |
+
prompt = f"""Answer the following concisely and exactly:
|
| 20 |
+
{question}"""
|
| 21 |
+
try:
|
| 22 |
+
response = self.llm.chat.completions.create(
|
| 23 |
+
model="gpt-4o",
|
| 24 |
+
messages=[
|
| 25 |
+
{"role": "system", "content": "You are an expert AI assistant."},
|
| 26 |
+
{"role": "user", "content": prompt}
|
| 27 |
+
],
|
| 28 |
+
temperature=0.2,
|
| 29 |
+
)
|
| 30 |
+
return response.choices[0].message.content.strip()
|
| 31 |
+
except Exception as e:
|
| 32 |
+
return f"ERROR: {e}"
|
| 33 |
+
|
| 34 |
|
| 35 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 36 |
"""
|