Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,12 @@ import gradio as gr
|
|
3 |
import requests
|
4 |
import inspect
|
5 |
import pandas as pd
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
# (Keep Constants as is)
|
8 |
# --- Constants ---
|
@@ -40,7 +46,23 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
40 |
|
41 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
42 |
try:
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
except Exception as e:
|
45 |
print(f"Error instantiating agent: {e}")
|
46 |
return f"Error initializing agent: {e}", None
|
@@ -80,7 +102,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
80 |
print(f"Skipping item with missing task_id or question: {item}")
|
81 |
continue
|
82 |
try:
|
83 |
-
submitted_answer = agent(question_text)
|
84 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
85 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
86 |
except Exception as e:
|
|
|
3 |
import requests
|
4 |
import inspect
|
5 |
import pandas as pd
|
6 |
+
from langchain_community.chat_models import ChatOllama
|
7 |
+
from langchain_community.tools import DuckDuckGoSearchRun
|
8 |
+
from langchain.agents import Tool, AgentExecutor, initialize_agent
|
9 |
+
from langchain.agents.agent_types import AgentType
|
10 |
+
from langchain.prompts.chat import SystemMessagePromptTemplate, ChatPromptTemplate, HumanMessagePromptTemplate
|
11 |
+
|
12 |
|
13 |
# (Keep Constants as is)
|
14 |
# --- Constants ---
|
|
|
46 |
|
47 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
48 |
try:
|
49 |
+
llm = ChatOllama(model="llama3.1")
|
50 |
+
|
51 |
+
search = DuckDuckGoSearchRun()
|
52 |
+
tools = [
|
53 |
+
Tool(
|
54 |
+
name="DuckDuckGo Search",
|
55 |
+
func=search.run,
|
56 |
+
description="Useful for answering questions about current events or the web."
|
57 |
+
)
|
58 |
+
]
|
59 |
+
agent = initialize_agent(
|
60 |
+
tools,
|
61 |
+
llm,
|
62 |
+
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
|
63 |
+
verbose=True,
|
64 |
+
handle_parsing_errors=True
|
65 |
+
)
|
66 |
except Exception as e:
|
67 |
print(f"Error instantiating agent: {e}")
|
68 |
return f"Error initializing agent: {e}", None
|
|
|
102 |
print(f"Skipping item with missing task_id or question: {item}")
|
103 |
continue
|
104 |
try:
|
105 |
+
submitted_answer = agent.run(question_text)
|
106 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
107 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
108 |
except Exception as e:
|