Spaces:
Sleeping
Sleeping
EtienneB
commited on
Commit
·
c4e5a43
1
Parent(s):
f333505
Update agent.py
Browse files
agent.py
CHANGED
|
@@ -41,13 +41,12 @@ tools = [
|
|
| 41 |
# Load system prompt
|
| 42 |
system_prompt = """
|
| 43 |
You are a general AI assistant. I will ask you a question.
|
| 44 |
-
Report your thoughts, and finish your answer with the
|
| 45 |
-
|
| 46 |
-
If you are asked for a number, don't use comma to write your number
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
put in the list is a number or a string.
|
| 51 |
"""
|
| 52 |
|
| 53 |
|
|
@@ -117,9 +116,16 @@ def build_graph():
|
|
| 117 |
# --- Nodes ---
|
| 118 |
def assistant(state: MessagesState):
|
| 119 |
"""Assistant node"""
|
| 120 |
-
# Prepend the system message to the state
|
| 121 |
messages_with_system_prompt = [sys_msg] + state["messages"]
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
def retriever_node(state: MessagesState):
|
| 125 |
"""
|
|
|
|
| 41 |
# Load system prompt
|
| 42 |
system_prompt = """
|
| 43 |
You are a general AI assistant. I will ask you a question.
|
| 44 |
+
Report your thoughts, and finish your answer with only the answer, no extra text, no prefix, and no explanation.
|
| 45 |
+
Your answer should be a number OR as few words as possible OR a comma separated list of numbers and/or strings.
|
| 46 |
+
If you are asked for a number, don't use a comma to write your number, nor use units such as $ or percent sign unless specified otherwise.
|
| 47 |
+
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.
|
| 48 |
+
If you are asked for a comma separated list, apply the above rules depending on whether the element to be put in the list is a number or a string.
|
| 49 |
+
Format your output as: Answers (answers): [{"task_id": ..., "submitted_answer": ...}]
|
|
|
|
| 50 |
"""
|
| 51 |
|
| 52 |
|
|
|
|
| 116 |
# --- Nodes ---
|
| 117 |
def assistant(state: MessagesState):
|
| 118 |
"""Assistant node"""
|
|
|
|
| 119 |
messages_with_system_prompt = [sys_msg] + state["messages"]
|
| 120 |
+
llm_response = llm_with_tools.invoke(messages_with_system_prompt)
|
| 121 |
+
# Extract the answer text (strip any "FINAL ANSWER:" if present)
|
| 122 |
+
answer_text = llm_response.content
|
| 123 |
+
if answer_text.strip().lower().startswith("final answer:"):
|
| 124 |
+
answer_text = answer_text.split(":", 1)[1].strip()
|
| 125 |
+
# Get task_id from state or set a placeholder
|
| 126 |
+
task_id = state.get("task_id", "1") # Replace with actual logic if needed
|
| 127 |
+
formatted = f'Answers (answers): [{{"task_id": "{task_id}", "submitted_answer": "{answer_text}"}}]'
|
| 128 |
+
return {"messages": [formatted]}
|
| 129 |
|
| 130 |
def retriever_node(state: MessagesState):
|
| 131 |
"""
|