File size: 1,631 Bytes
f5d0f7b
 
 
 
 
bbd1871
f5d0f7b
 
254147b
f5d0f7b
ff89469
 
91abd8e
254147b
 
 
 
91abd8e
f5d0f7b
b815d0a
c177f92
 
fe9a4fe
 
 
 
c177f92
b815d0a
f5d0f7b
 
b815d0a
91abd8e
d544bf3
ff89469
f5d0f7b
91abd8e
f5d0f7b
ff89469
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
29
30
31
32
33
34
35
36
37
38
39
40
41
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, openai_api_key):
    os.environ["OPENAI_API_KEY"] = openai_api_key
    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>
<p>
This is a demo for the <a href="https://python.langchain.com/en/latest/modules/agents/tools/examples/chatgpt_plugins.html", target="_blank">ChatGPT Plugins LangChain</a> usecase<br />
Be aware that it currently only works with plugins that do not require auth.
</p>
</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 manifesto file of the plugin you want to use", value="https://www.klarna.com/.well-known/ai-plugin.json")
        openai_api_key = gr.Textbox(label="OpenAI API Key", type="password")
        run_btn = gr.Button("Run")
        response = gr.Textbox(label="Response")
    run_btn.click(fn=run, 
                 inputs=[prompt, plugin, openai_api_key],
                 outputs=[response]
                 )
demo.launch()