File size: 961 Bytes
1dd5dc6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import openai
from utils import get_doc_tools
from llama_index.llms.openai import OpenAI
from llama_index.agent.openai import OpenAIAgent
import gradio as gr

openai.api_key = "sk-proj-OPe6yvFXnluDbsk4inaoT3BlbkFJ7mf26VTWhErEiXXF0Dt2"

vector_tool, summary_tool = get_doc_tools("metagpt.pdf", "metagpt")

llm = OpenAI(model="gpt-3.5-turbo", temperature=0)

agent = OpenAIAgent.from_tools(
    [vector_tool, summary_tool], 
    llm=llm, 
    verbose=False
)

def get_agent_response(message, history=[]): # We need to have the history parameter here because ChatInterface requires it
    response = agent.chat(
        message
    )
    return (str(response))

# Create the Gradio interface
chatbot_interface = gr.ChatInterface(
    fn=get_agent_response, 
    title="MetaGPT Agent Chatbot",
    description="Ask questions about the MetaGPT agent roles and their communication."
)

# Launch the interface
chatbot_interface.launch()