Spaces:
Sleeping
Sleeping
File size: 1,304 Bytes
651f3d7 08c6860 651f3d7 |
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 |
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()
|