Spaces:
Build error
Build error
Commit ·
a4c9a4a
1
Parent(s): 6387e77
+ error handling
Browse filesFiles changed (3)
- agents.py+9-1
- app.py+14-11
- system_prompt.txt+5-1
11 unmodified lines12131415161778 unmodified lines9697989910010110211 unmodified linesfrom opentelemetry.sdk.trace import TracerProviderfrom langfuse import get_clientfrom rich.pretty import pprint78 unmodified lines# Optionally set trace attributesspan.update_trace(user_id="user_123", input={"query": query})response = await self.alfred.run(query)# Optionally set trace outputspan.update_trace(output={"response": str(response)})11 unmodified lines1213141516171878 unmodified lines97989910010110210310410510610710810911011 unmodified linesfrom opentelemetry.sdk.trace import TracerProviderfrom langfuse import get_clientfrom rich.pretty import pprintimport aiohttp78 unmodified lines# Optionally set trace attributesspan.update_trace(user_id="user_123", input={"query": query})try:response = await self.alfred.run(query)except aiohttp.client_exceptions.ClientConnectionError as e:span.update_trace(output={"response": f"Connection error: {e}"})return f"AGENT ERROR: Connection error to LLM API: {e}"except Exception as e:span.update_trace(output={"response": f"General error: {e}"})return f"AGENT ERROR: {e}"# Optionally set trace outputspan.update_trace(output={"response": str(response)})
4 unmodified lines567891047 unmodified lines5859606162636465666768697071727374754 unmodified linesimport pandas as pdfrom agents import LlamaIndexAgentimport asyncio# (Keep Constants as is)# --- Constants ---47 unmodified linescached_questions = questions_datatotal = len(questions_data)progress(0, desc="Starting answer generation...")async def answer_one(item):task_id = item.get("task_id")question_text = item.get("question")if not task_id or question_text is None:print(f"Skipping item with missing task_id or question: {item}")return {"Task ID": task_id, "Question": question_text, "Submitted Answer": "SKIPPED"}, Nonetry:submitted_answer = await agent.aquery(question_text)return {"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer}, {"task_id": task_id, "submitted_answer": submitted_answer}except Exception as e:print(f"Error running agent on task {task_id}: {e}")return {"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"}, Nonetasks = [answer_one(item) for item in questions_data]results_log = []answers_payload = []4 unmodified lines56789101147 unmodified lines59606162636465666768697071727374757677784 unmodified linesimport pandas as pdfrom agents import LlamaIndexAgentimport asyncioimport aiohttp# (Keep Constants as is)# --- Constants ---47 unmodified linescached_questions = questions_datatotal = len(questions_data)progress(0, desc="Starting answer generation...")semaphore = asyncio.Semaphore(3) # Limit concurrency to 3async def answer_one(item):async with semaphore:task_id = item.get("task_id")question_text = item.get("question")if not task_id or question_text is None:print(f"Skipping item with missing task_id or question: {item}")return {"Task ID": task_id, "Question": question_text, "Submitted Answer": "SKIPPED"}, Nonetry:submitted_answer = await agent.aquery(question_text)return {"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer}, {"task_id": task_id, "submitted_answer": submitted_answer}except Exception as e:print(f"Error running agent on task {task_id}: {e}")return {"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"}, Nonetasks = [answer_one(item) for item in questions_data]results_log = []answers_payload = []
1give single word answer and reply.12345You are a helpful assistant tasked with answering questions using a set of tools.Now, I will ask you a question. Report your thoughts, and finish your answer with the following template: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. 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.Your answer should only start with "FINAL ANSWER: ", then follows with the answer.
agents.py+9-1
app.py+14-11
system_prompt.txt+5-1