fffiloni's picture
Update app.py
c177f92
raw
history blame
1.19 kB
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, plugin_json):
tool = AIPluginTool.from_plugin_url(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(prompt)
title="""
<div style="text-align:center;">
<h1>ChatGPT Plugins playground</h1>
</div>
"""
with gr.Blocks() as demo:
with gr.Column():
gr.HTML(title)
prompt = gr.Textbox(label="Prompt", value="what t shirts are available in klarna?")
plugin = gr.Textbox(label="Plugin json", info="You need the .json plugin file of the plugin you want to use", value="https://www.klarna.com/.well-known/ai-plugin.json")
run_btn = gr.Button("Run")
response = gr.Textbox(label="Response")
run_btn.click(fn=run,
inputs=[prompt, plugin],
outputs=[response]
)
demo.launch()