Update app.py
Browse files
app.py
CHANGED
@@ -14,6 +14,12 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
14 |
# --- Basic Agent Definition ---
|
15 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
16 |
class BasicAgent:
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
def __init__(self):
|
18 |
print("BasicAgent initialized.")
|
19 |
self.graph = build_graph()
|
@@ -21,7 +27,14 @@ class BasicAgent:
|
|
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 |
messages = self.graph.invoke({"messages": messages})
|
26 |
answer = messages['messages'][-1].content
|
27 |
return answer[14:]
|
|
|
14 |
# --- Basic Agent Definition ---
|
15 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
16 |
class BasicAgent:
|
17 |
+
system_prompt = """You are a helpful assistant tasked with answering questions using a set of tools.
|
18 |
+
Now, I will ask you a question. Report your thoughts, and finish your answer with the following template:
|
19 |
+
FINAL ANSWER: [YOUR FINAL ANSWER].
|
20 |
+
YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.
|
21 |
+
Your answer should only start with "FINAL ANSWER: ", then follows with the answer.
|
22 |
+
"""
|
23 |
def __init__(self):
|
24 |
print("BasicAgent initialized.")
|
25 |
self.graph = build_graph()
|
|
|
27 |
def __call__(self, question: str) -> str:
|
28 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
29 |
# Wrap the question in a HumanMessage from langchain_core
|
30 |
+
#messages = [HumanMessage(content=question)]
|
31 |
+
messages = [
|
32 |
+
SystemMessage(
|
33 |
+
content=system_prompt
|
34 |
+
),
|
35 |
+
HumanMessage(
|
36 |
+
content=question
|
37 |
+
)]
|
38 |
messages = self.graph.invoke({"messages": messages})
|
39 |
answer = messages['messages'][-1].content
|
40 |
return answer[14:]
|