Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,8 +2,9 @@ import os
|
|
| 2 |
import gradio as gr
|
| 3 |
import requests
|
| 4 |
import inspect
|
|
|
|
| 5 |
import pandas as pd
|
| 6 |
-
import
|
| 7 |
|
| 8 |
# (Keep Constants as is)
|
| 9 |
# --- Constants ---
|
|
@@ -12,31 +13,19 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 12 |
# --- Basic Agent Definition ---
|
| 13 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 14 |
class BasicAgent:
|
|
|
|
| 15 |
def __init__(self):
|
| 16 |
-
|
| 17 |
-
self.
|
| 18 |
-
"You are a helpful research assistant. "
|
| 19 |
-
"Only answer with the exact factual answer without explanation. "
|
| 20 |
-
"If you cannot answer exactly from the information, say 'Unknown'."
|
| 21 |
-
)
|
| 22 |
|
| 23 |
def __call__(self, question: str) -> str:
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
],
|
| 32 |
-
temperature=0
|
| 33 |
-
)
|
| 34 |
-
answer = response["choices"][0]["message"]["content"].strip()
|
| 35 |
-
print(f"Agent answer: {answer}")
|
| 36 |
-
return answer
|
| 37 |
-
except Exception as e:
|
| 38 |
-
print(f"OpenAI API error: {e}")
|
| 39 |
-
return "ERROR"
|
| 40 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 41 |
"""
|
| 42 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
+
from langchain_core.messages import HumanMessage
|
| 6 |
import pandas as pd
|
| 7 |
+
from agent import build_graph
|
| 8 |
|
| 9 |
# (Keep Constants as is)
|
| 10 |
# --- Constants ---
|
|
|
|
| 13 |
# --- Basic Agent Definition ---
|
| 14 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 15 |
class BasicAgent:
|
| 16 |
+
"""A langgraph agent."""
|
| 17 |
def __init__(self):
|
| 18 |
+
print("BasicAgent initialized.")
|
| 19 |
+
self.graph = build_graph()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
def __call__(self, question: str) -> str:
|
| 22 |
+
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 23 |
+
# Wrap the question in a HumanMessage from langchain_core
|
| 24 |
+
messages = [HumanMessage(content=question)]
|
| 25 |
+
result = self.graph.invoke({"messages": messages})
|
| 26 |
+
answer = result['messages'][-1].content
|
| 27 |
+
return answer[14:]
|
| 28 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 30 |
"""
|
| 31 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|