File size: 1,298 Bytes
c169262
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
42
import gradio as gr
import requests


def fastlane_agent(message, history):

    history_openai_format = [
        {"role": "system", "content": "You are an assistant for an eCommerce store."}]
    for human, assistant in history:
        history_openai_format.append({"role": "user", "content": human})
        history_openai_format.append(
            {"role": "assistant", "content": assistant})
    history_openai_format.append({"role": "user", "content": message})

    response = requests.post(
        "http://localhost:8000/query-handler/", json={"text": message, "history": history_openai_format})
    if response.status_code == 200:
        return  response.json().get("generative response")
    else:
        return "Error: Could not fetch response."


iface = gr.ChatInterface(
    fn=fastlane_agent,
    chatbot=gr.Chatbot(height=400),
    textbox=gr.Textbox(
        placeholder="How can I help you?", container=False, scale=7
    ),
    title="Fastlane Chat GPT",
    description="AI sales assistance for e-commmerce",
    theme="soft",
    examples=["Hello", "What is the status of my order?",
              "Recommend me products"],
    cache_examples=True,
    retry_btn=None,
    undo_btn="Delete Previous",
    clear_btn="Clear"
)

if __name__ == "__main__":
    iface.launch()