better_bot / app.py
fynn3003's picture
Update app.py
08c6860
import gradio as gr
from langchain.llms.openai import OpenAI
import os
from langchain.agents import initialize_agent
from langchain.agents import load_tools
os.environ["OPENAI_API_KEY"] = "sk-dDPyQHpuXcMDDP5PmFgnT3BlbkFJLdhOV60RNrnf5xp5DUc"
os.environ["SERPAPI_API_KEY"] = "e109a79c9b6a844c889c8b3f65430f3ea17c4362de514eafeb6030414ec6f808"
llm = OpenAI(temperature=0, max_tokens=1000, model_name='text-davinci-003')
def answer_question(question):
agent_exe = initialize_agent(
llm=OpenAI(temperature=0),
tools=load_tools(["python_repl", "serpapi", "llm-math"], llm=llm),
return_intermediate_steps=True,
verbose=True,
)
response = agent_exe({"input": question})
answer = response["output"]
steps = response["intermediate_steps"]
return answer, steps
ifaces = gr.Interface(
fn=answer_question,
inputs=gr.Textbox(label="Question",
placeholder="What's the square root, of the age, of Leonardo DiCaprio's latest girlfriend"),
outputs=[gr.Textbox(label="Answer"), gr.JSON(label="Steps", show_label=False)],
title="Helpful Agent",
description="This is an Agent, which uses OpenAI's text-davinci-003 model, and the tools: SerpAPI, Python REPL, and Language Learning Machine Math, depending on your request"
)
ifaces.launch()