Commit
β’
69ad8db
1
Parent(s):
c6fb257
Update app.py
Browse files
app.py
CHANGED
@@ -7,12 +7,15 @@ from gradio_agentchatbot import (
|
|
7 |
)
|
8 |
from dotenv import load_dotenv
|
9 |
from langchain.agents import load_tools
|
|
|
|
|
10 |
from pathlib import Path
|
11 |
|
12 |
current_dir = Path(__file__).parent
|
13 |
|
14 |
load_dotenv()
|
15 |
|
|
|
16 |
# Import tool from Hub
|
17 |
image_generation_tool = load_tool("m-ric/text-to-image")
|
18 |
|
@@ -34,9 +37,25 @@ def interact_with_agent(prompt, messages):
|
|
34 |
yield messages
|
35 |
|
36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
with gr.Blocks() as demo:
|
38 |
with gr.Tabs():
|
39 |
-
with gr.Tab("Demo"):
|
40 |
gr.Markdown("# Chat with an LLM Agent π€ and see its thoughts π")
|
41 |
chatbot = AgentChatbot(
|
42 |
label="Agent",
|
@@ -47,6 +66,17 @@ with gr.Blocks() as demo:
|
|
47 |
)
|
48 |
text_input = gr.Textbox(lines=1, label="Chat Message")
|
49 |
text_input.submit(interact_with_agent, [text_input, chatbot], [chatbot])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
with gr.Tab("Docs"):
|
51 |
gr.Markdown(Path(current_dir / "docs.md").read_text())
|
52 |
|
|
|
7 |
)
|
8 |
from dotenv import load_dotenv
|
9 |
from langchain.agents import load_tools
|
10 |
+
from langchain_demo import agent_executor as langchain_agent
|
11 |
+
|
12 |
from pathlib import Path
|
13 |
|
14 |
current_dir = Path(__file__).parent
|
15 |
|
16 |
load_dotenv()
|
17 |
|
18 |
+
|
19 |
# Import tool from Hub
|
20 |
image_generation_tool = load_tool("m-ric/text-to-image")
|
21 |
|
|
|
37 |
yield messages
|
38 |
|
39 |
|
40 |
+
async def interact_with_langchain_agent(prompt, messages):
|
41 |
+
messages.append(ChatMessage(role="user", content=prompt))
|
42 |
+
yield messages
|
43 |
+
async for chunk in langchain_agent.astream(
|
44 |
+
{"input": prompt}
|
45 |
+
):
|
46 |
+
if "steps" in chunk:
|
47 |
+
for step in chunk["steps"]:
|
48 |
+
messages.append(ChatMessage(role="assistant", content=step.action.log,
|
49 |
+
thought_metadata={"tool_name": step.action.tool}))
|
50 |
+
yield messages
|
51 |
+
if "output" in chunk:
|
52 |
+
messages.append(ChatMessage(role="assistant", content=chunk["output"]))
|
53 |
+
yield messages
|
54 |
+
|
55 |
+
|
56 |
with gr.Blocks() as demo:
|
57 |
with gr.Tabs():
|
58 |
+
with gr.Tab("Transformers Demo"):
|
59 |
gr.Markdown("# Chat with an LLM Agent π€ and see its thoughts π")
|
60 |
chatbot = AgentChatbot(
|
61 |
label="Agent",
|
|
|
66 |
)
|
67 |
text_input = gr.Textbox(lines=1, label="Chat Message")
|
68 |
text_input.submit(interact_with_agent, [text_input, chatbot], [chatbot])
|
69 |
+
with gr.Tab("Langchain Demo"):
|
70 |
+
gr.Markdown("# Chat with a LangChain Agent π¦βοΈ and see its thoughts π")
|
71 |
+
chatbot_2 = AgentChatbot(
|
72 |
+
label="Agent",
|
73 |
+
avatar_images=[
|
74 |
+
None,
|
75 |
+
"https://em-content.zobj.net/source/twitter/141/parrot_1f99c.png",
|
76 |
+
],
|
77 |
+
)
|
78 |
+
input_2 = gr.Textbox(lines=1, label="Chat Message")
|
79 |
+
input_2.submit(interact_with_langchain_agent, [input_2, chatbot_2], [chatbot_2])
|
80 |
with gr.Tab("Docs"):
|
81 |
gr.Markdown(Path(current_dir / "docs.md").read_text())
|
82 |
|