Martin Bär
commited on
Commit
·
1889103
1
Parent(s):
09a402e
Update prompts and add ReAct agent info
Browse files- app.py +1 -1
- basic_agent.py +11 -6
- web_tools.py +0 -0
app.py
CHANGED
|
@@ -177,7 +177,7 @@ with gr.Blocks() as demo:
|
|
| 177 |
|
| 178 |
# Input field to test agent
|
| 179 |
gr.Markdown("""
|
| 180 |
-
#
|
| 181 |
|
| 182 |
Test the agent by submitting custom tasks and questions.
|
| 183 |
"""
|
|
|
|
| 177 |
|
| 178 |
# Input field to test agent
|
| 179 |
gr.Markdown("""
|
| 180 |
+
# Test the Agent
|
| 181 |
|
| 182 |
Test the agent by submitting custom tasks and questions.
|
| 183 |
"""
|
basic_agent.py
CHANGED
|
@@ -9,6 +9,7 @@ from llama_index.readers.web import SimpleWebPageReader
|
|
| 9 |
from llama_index.core.tools.ondemand_loader_tool import OnDemandLoaderTool
|
| 10 |
from langfuse.llama_index import LlamaIndexInstrumentor
|
| 11 |
from llama_index.llms.ollama import Ollama
|
|
|
|
| 12 |
|
| 13 |
class BasicAgent:
|
| 14 |
def __init__(self, ollama=False, langfuse=True):
|
|
@@ -48,18 +49,22 @@ class BasicAgent:
|
|
| 48 |
)
|
| 49 |
|
| 50 |
# Create Alfred with all the tools
|
| 51 |
-
self.agent = AgentWorkflow.from_tools_or_functions(
|
| 52 |
-
|
| 53 |
llm=llm,
|
| 54 |
-
verbose=True
|
| 55 |
-
system_prompt=("You are a helpful agent that can search Wikipedia and the Internet for answers. "
|
| 56 |
-
"Please be concise when answering questions and make sure your final outputs are relevant to the question.")
|
| 57 |
)
|
| 58 |
|
| 59 |
# self.ctx = Context(self.agent)
|
| 60 |
|
| 61 |
async def __call__(self, question: str) -> str:
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
if self.langfuse:
|
| 65 |
self.instrumentor.flush()
|
|
|
|
| 9 |
from llama_index.core.tools.ondemand_loader_tool import OnDemandLoaderTool
|
| 10 |
from langfuse.llama_index import LlamaIndexInstrumentor
|
| 11 |
from llama_index.llms.ollama import Ollama
|
| 12 |
+
from llama_index.core.agent.workflow import ReActAgent
|
| 13 |
|
| 14 |
class BasicAgent:
|
| 15 |
def __init__(self, ollama=False, langfuse=True):
|
|
|
|
| 49 |
)
|
| 50 |
|
| 51 |
# Create Alfred with all the tools
|
| 52 |
+
self.agent = AgentWorkflow.from_tools_or_functions( # ReActAgent(
|
| 53 |
+
wiki_spec.to_tool_list(), # webpage_tool does not work properly - cookies etc
|
| 54 |
llm=llm,
|
| 55 |
+
verbose=True
|
|
|
|
|
|
|
| 56 |
)
|
| 57 |
|
| 58 |
# self.ctx = Context(self.agent)
|
| 59 |
|
| 60 |
async def __call__(self, question: str) -> str:
|
| 61 |
+
prompt = (
|
| 62 |
+
"Reply to the user's question below by using tools if necessary. "
|
| 63 |
+
"Only output the answer to the question, no additional information or explanations. "
|
| 64 |
+
f"Question: {question}"
|
| 65 |
+
)
|
| 66 |
+
print(prompt)
|
| 67 |
+
response = await self.agent.run(user_msg=prompt) # ctx=self.ctx)
|
| 68 |
|
| 69 |
if self.langfuse:
|
| 70 |
self.instrumentor.flush()
|
web_tools.py
DELETED
|
File without changes
|