AgentExecutor chain #3500
-
I want to host a python agent on Gradio. It all works good. Im struggling when wanting to display not only the answer but also the AgentExecutor chain. How can I edit the code, so that also the AgentExecutor chain will be printed in the Gradio app. The Code snippet for that part is the following:
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 6 replies
-
I assume you want the Thought, Action, Action Input, Observation steps to be printed in Gradio. You can access the First, enable the def answer_question(question):
agent_exe = initialize_agent(
llm=OpenAI(temperature=0, max_tokens=1000),
tool=PythonREPLTool(),
return_intermediate_steps=True,
verbose=True,
)
response = agent_exe({"input": question})
answer = response["output"]
steps = response["intermediate_steps"]
return answer, steps Then you can use something like the ifaces = gr.Interface(
fn=answer_question,
inputs=gr.Textbox(label="Question"),
outputs=[gr.Textbox(label="Answer"), gr.JSON(label="Steps")],
title="Question Answering Agent",
description="A simple question answering agent."
) |
Beta Was this translation helpful? Give feedback.
-
sure: Traceback (most recent call last): |
Beta Was this translation helpful? Give feedback.
-
Perfect, it worked!!! thank you! |
Beta Was this translation helpful? Give feedback.
-
I have one more question, do you know how I can edit the JSON output, so that it will have a more readable format? |
Beta Was this translation helpful? Give feedback.
I see. You should use the
load_tools
function to properly load the tools: