Spaces:
Sleeping
Sleeping
ajout de conditions
Browse files- agent.py +3 -3
- fonctions.py +44 -2
- requirements.txt +2 -1
agent.py
CHANGED
|
@@ -154,7 +154,7 @@ def create_agent_and_answer(dict_data, question) -> str:
|
|
| 154 |
|
| 155 |
|
| 156 |
research_agent = create_react_agent(
|
| 157 |
-
model=
|
| 158 |
tools=[wiki_search, arvix_search],
|
| 159 |
prompt=(
|
| 160 |
"You are a research agent.\n\n"
|
|
@@ -168,7 +168,7 @@ research_agent = create_react_agent(
|
|
| 168 |
)
|
| 169 |
|
| 170 |
web_search_openai_agent = create_react_agent(
|
| 171 |
-
model=
|
| 172 |
tools=[web_search_openai_tool],
|
| 173 |
prompt=(
|
| 174 |
"You are a websearch agent.\n\n"
|
|
@@ -236,7 +236,7 @@ supervisor = create_supervisor(
|
|
| 236 |
model=init_chat_model("openai:gpt-4.1", api_key = api_open_ai_agent_key),
|
| 237 |
agents=[research_agent, web_search_openai_agent, agent_excel_new, reflexion_agent],
|
| 238 |
prompt=(
|
| 239 |
-
"You are a supervisor managing
|
| 240 |
"- research_agent: Specialised in ArXiv and Wikipedia. Assign research-related tasks to this agent.\n"
|
| 241 |
"- reflexion: Called when the supervisor need a reflexion, not general knowledge. Can handle math-related tasks such as solving equations, performing calculations or working on abstract maths subject such as matrix or demonstrating subjects.\n"
|
| 242 |
"- web_search_openai_agent: Can browse the web to find up-to-date and relevant information. Assign web-related tasks to this agent.\n"
|
|
|
|
| 154 |
|
| 155 |
|
| 156 |
research_agent = create_react_agent(
|
| 157 |
+
model=llm_4_1,
|
| 158 |
tools=[wiki_search, arvix_search],
|
| 159 |
prompt=(
|
| 160 |
"You are a research agent.\n\n"
|
|
|
|
| 168 |
)
|
| 169 |
|
| 170 |
web_search_openai_agent = create_react_agent(
|
| 171 |
+
model=llm_4_1,
|
| 172 |
tools=[web_search_openai_tool],
|
| 173 |
prompt=(
|
| 174 |
"You are a websearch agent.\n\n"
|
|
|
|
| 236 |
model=init_chat_model("openai:gpt-4.1", api_key = api_open_ai_agent_key),
|
| 237 |
agents=[research_agent, web_search_openai_agent, agent_excel_new, reflexion_agent],
|
| 238 |
prompt=(
|
| 239 |
+
"You are a supervisor managing four agents:\n"
|
| 240 |
"- research_agent: Specialised in ArXiv and Wikipedia. Assign research-related tasks to this agent.\n"
|
| 241 |
"- reflexion: Called when the supervisor need a reflexion, not general knowledge. Can handle math-related tasks such as solving equations, performing calculations or working on abstract maths subject such as matrix or demonstrating subjects.\n"
|
| 242 |
"- web_search_openai_agent: Can browse the web to find up-to-date and relevant information. Assign web-related tasks to this agent.\n"
|
fonctions.py
CHANGED
|
@@ -4,10 +4,51 @@ import re
|
|
| 4 |
import pandas as pd
|
| 5 |
from openai import OpenAI
|
| 6 |
import os
|
|
|
|
| 7 |
|
| 8 |
|
| 9 |
api_open_ai_agent_key=os.environ["OPENAI_API_KEY"]
|
| 10 |
client = OpenAI(api_key=api_open_ai_agent_key)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
def clean_response(response):
|
| 12 |
match = re.search(r'FINAL ANSWER:\s*(.+)', response['supervisor']['messages'][-1].content)
|
| 13 |
answer = match.group(1).strip() if match else None
|
|
@@ -21,7 +62,7 @@ def response_from_agent(supervisor, question):
|
|
| 21 |
):
|
| 22 |
|
| 23 |
response = chunk
|
| 24 |
-
|
| 25 |
|
| 26 |
response = clean_response(response)
|
| 27 |
return response
|
|
@@ -72,4 +113,5 @@ def load_data(question):
|
|
| 72 |
return transcription.text
|
| 73 |
|
| 74 |
else :
|
| 75 |
-
return 'there is no attached file'
|
|
|
|
|
|
| 4 |
import pandas as pd
|
| 5 |
from openai import OpenAI
|
| 6 |
import os
|
| 7 |
+
from langchain_core.messages import convert_to_messages
|
| 8 |
|
| 9 |
|
| 10 |
api_open_ai_agent_key=os.environ["OPENAI_API_KEY"]
|
| 11 |
client = OpenAI(api_key=api_open_ai_agent_key)
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def pretty_print_message(message, indent=False):
|
| 15 |
+
pretty_message = message.pretty_repr(html=True)
|
| 16 |
+
if not indent:
|
| 17 |
+
print(pretty_message)
|
| 18 |
+
return
|
| 19 |
+
|
| 20 |
+
indented = "\n".join("\t" + c for c in pretty_message.split("\n"))
|
| 21 |
+
print(indented)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def pretty_print_messages(update, last_message=False):
|
| 25 |
+
is_subgraph = False
|
| 26 |
+
if isinstance(update, tuple):
|
| 27 |
+
ns, update = update
|
| 28 |
+
# skip parent graph updates in the printouts
|
| 29 |
+
if len(ns) == 0:
|
| 30 |
+
return
|
| 31 |
+
|
| 32 |
+
graph_id = ns[-1].split(":")[0]
|
| 33 |
+
print(f"Update from subgraph {graph_id}:")
|
| 34 |
+
print("\n")
|
| 35 |
+
is_subgraph = True
|
| 36 |
+
|
| 37 |
+
for node_name, node_update in update.items():
|
| 38 |
+
update_label = f"Update from node {node_name}:"
|
| 39 |
+
if is_subgraph:
|
| 40 |
+
update_label = "\t" + update_label
|
| 41 |
+
|
| 42 |
+
print(update_label)
|
| 43 |
+
print("\n")
|
| 44 |
+
|
| 45 |
+
messages = convert_to_messages(node_update["messages"])
|
| 46 |
+
if last_message:
|
| 47 |
+
messages = messages[-1:]
|
| 48 |
+
|
| 49 |
+
for m in messages:
|
| 50 |
+
pretty_print_message(m, indent=is_subgraph)
|
| 51 |
+
print("\n")
|
| 52 |
def clean_response(response):
|
| 53 |
match = re.search(r'FINAL ANSWER:\s*(.+)', response['supervisor']['messages'][-1].content)
|
| 54 |
answer = match.group(1).strip() if match else None
|
|
|
|
| 62 |
):
|
| 63 |
|
| 64 |
response = chunk
|
| 65 |
+
pretty_print_messages(chunk)
|
| 66 |
|
| 67 |
response = clean_response(response)
|
| 68 |
return response
|
|
|
|
| 113 |
return transcription.text
|
| 114 |
|
| 115 |
else :
|
| 116 |
+
return 'there is no attached file'
|
| 117 |
+
|
requirements.txt
CHANGED
|
@@ -13,4 +13,5 @@ tabulate
|
|
| 13 |
pandas
|
| 14 |
pydub
|
| 15 |
torch
|
| 16 |
-
numpy
|
|
|
|
|
|
| 13 |
pandas
|
| 14 |
pydub
|
| 15 |
torch
|
| 16 |
+
numpy
|
| 17 |
+
openpyxl
|