File size: 877 Bytes
f5d0f7b bbd1871 f5d0f7b 254147b f5d0f7b 254147b f5d0f7b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
import os
import gradio as gr
from langchain.chat_models import ChatOpenAI
from langchain.agents import load_tools, initialize_agent
from langchain.agents import AgentType
from langchain.tools import AIPluginTool
def run(prompt):
tool = AIPluginTool.from_plugin_url("https://www.klarna.com/.well-known/ai-plugin.json")
llm = ChatOpenAI(temperature=0)
tools = load_tools(["requests_all"] )
tools += [tool]
agent_chain = initialize_agent( tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True)
return agent_chain.run("what t shirts are available in klarna?")
with gr.Blocks() as demo:
with gr.Column():
prompt = gr.Textbox()
run_btn = gr.Button("Run")
response = gr.Textbox()
run_btn.click(fn=run,
inputs=[prompt],
outputs=[response]
)
demo.launch() |