File size: 1,194 Bytes
d9dc802
 
 
 
 
 
 
 
 
 
 
 
 
4d41c1d
d9dc802
 
 
4d41c1d
d9dc802
4d41c1d
 
d9dc802
 
4d41c1d
 
 
 
 
d9dc802
 
 
 
 
 
4d41c1d
d9dc802
 
 
 
 
 
207dcbf
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 os
import gradio as gr
import openai

openai.api_base = os.environ.get("OPENAI_API_BASE")
openai.api_key = os.environ.get("OPENAI_API_KEY")
bbusr = os.environ.get("BBUSER")
bbpwd = os.environ.get("BBPWD")

messages = [{"role": "system",
             "content": "You are a friendly AI assistant and an expert in health ."}]


def ChatResponse(user_input, history):
    messages.append({"role": "user", "content": user_input})
    response = openai.ChatCompletion.create(
        model="gpt-3.5-turbo",
        stream=True,
        messages=messages,
        max_tokens=512, 
        temperature=0.5, 
        top_p=0.95
    )
    partial_response = ""
    for stream_response in response:
        token = stream_response["choices"][0]["delta"].get("content", "")
        partial_response += token
        yield partial_response


mychatbot = gr.Chatbot(
    avatar_images=["./user.png", "./aibot.png"], bubble_full_width=False, show_label=False, show_copy_button=True,)


demo = gr.ChatInterface(fn=ChatResponse, 
        chatbot=mychatbot,
        title="🫐BuruBuru Chat🫐",
        retry_btn=None,
        undo_btn=None
    )

demo.queue().launch(auth=(bbusr, bbpwd),show_api=False)