Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,8 @@ import gradio as gr
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
|
|
|
|
|
|
| 6 |
#from tavily import TavilyClient
|
| 7 |
from langchain_tavily import TavilySearch
|
| 8 |
from langgraph.prebuilt import create_react_agent
|
|
@@ -33,11 +35,22 @@ GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
|
|
| 33 |
##HUGGINGFACEHUB_API_TOKEN = os.getenv("HUGGINGFACEHUB_API_TOKEN")
|
| 34 |
|
| 35 |
#PROMPTS
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
prompt_recomendado = """You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template:
|
| 37 |
FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings.
|
| 38 |
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.
|
| 39 |
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.
|
| 40 |
-
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
prompt_search = """You are a web research agent.
|
| 43 |
INSTRUCTIONS:
|
|
@@ -113,21 +126,22 @@ class BasicAgent:
|
|
| 113 |
]
|
| 114 |
}
|
| 115 |
|
| 116 |
-
events = supervisor.stream(
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
)
|
| 120 |
|
| 121 |
-
for event in events:
|
| 122 |
-
|
| 123 |
|
| 124 |
-
answer = messages[-1].content
|
| 125 |
|
| 126 |
#print(f"Answer: {answer}...")
|
| 127 |
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
|
|
|
| 131 |
|
| 132 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 133 |
"""
|
|
@@ -193,6 +207,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 193 |
submitted_answer = agent(question_text)
|
| 194 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
| 195 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
|
|
|
| 196 |
except Exception as e:
|
| 197 |
print(f"Error running agent on task {task_id}: {e}")
|
| 198 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
|
|
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
+
import re
|
| 7 |
+
import time
|
| 8 |
#from tavily import TavilyClient
|
| 9 |
from langchain_tavily import TavilySearch
|
| 10 |
from langgraph.prebuilt import create_react_agent
|
|
|
|
| 35 |
##HUGGINGFACEHUB_API_TOKEN = os.getenv("HUGGINGFACEHUB_API_TOKEN")
|
| 36 |
|
| 37 |
#PROMPTS
|
| 38 |
+
#prompt_recomendado = """You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template:
|
| 39 |
+
# FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings.
|
| 40 |
+
# 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.
|
| 41 |
+
# 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.
|
| 42 |
+
# 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."""
|
| 43 |
+
|
| 44 |
prompt_recomendado = """You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template:
|
| 45 |
FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL 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 comma to write your number neither 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 of whether the element to be put in the list is a number or a string.
|
| 49 |
+
To assist in your task, you can supervise other agents who perform specific tasks that could not be handled by tools, since they require the processing of another LLM. Below, I will inform you about your assistants:
|
| 50 |
+
- web_research_agent. Assign web research related tasks to this agent
|
| 51 |
+
Assign work to one agent at a time, do not call agents in parallel.
|
| 52 |
+
Priorize the use of tools and another agents to help in reasoning.
|
| 53 |
+
When a file or URL is entered at the prompt, use it in tools or other agents, both are prepared to handle files and URLs."""
|
| 54 |
|
| 55 |
prompt_search = """You are a web research agent.
|
| 56 |
INSTRUCTIONS:
|
|
|
|
| 126 |
]
|
| 127 |
}
|
| 128 |
|
| 129 |
+
#events = supervisor.stream(
|
| 130 |
+
# messages,
|
| 131 |
+
# stream_mode="values",
|
| 132 |
+
#)
|
| 133 |
|
| 134 |
+
#for event in events:
|
| 135 |
+
# messages.extend(event["messages"])
|
| 136 |
|
| 137 |
+
#answer = messages[-1].content
|
| 138 |
|
| 139 |
#print(f"Answer: {answer}...")
|
| 140 |
|
| 141 |
+
answer = supervisor.invoke(messages)
|
| 142 |
+
final_answer = re.search(r"FINAL ANSWER:\s*(.*)", answer['output'])
|
| 143 |
+
print(f"Agent returning answer: {final_answer}")
|
| 144 |
+
return final_answer
|
| 145 |
|
| 146 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 147 |
"""
|
|
|
|
| 207 |
submitted_answer = agent(question_text)
|
| 208 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
| 209 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
| 210 |
+
time.sleep(60)
|
| 211 |
except Exception as e:
|
| 212 |
print(f"Error running agent on task {task_id}: {e}")
|
| 213 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
|