File size: 1,243 Bytes
ee2cb0d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
43
44
import os
import openai
import gradio as gr
from dotenv import load_dotenv

load_dotenv()
openai.api_key = os.environ['OPENAI_API_KEY']

messages = [
    {"role": "system", 
     "content": "你是算塔罗牌的专家,帮助人们算塔罗牌."}, 
]

def chat(message, history):
    if message:
        messages.append({"role": "user", "content": message})
        response = openai.ChatCompletion.create(
            model="gpt-3.5-turbo", messages=messages
        )
        reply = response.choices[0].message.content
        # messages.append({"role": "assistant", "content": reply})
        return reply
    
# def chat(user_input):
#     if user_input:
#         messages.append({"role": "user", "content": user_input})
#         response = openai.ChatCompletion.create(
#             model="gpt-3.5-turbo", messages=messages
#         )
#         reply = response.choices[0].message.content
#         messages.append({"role": "assistant", "content": reply})
#         return reply

inputs = gr.inputs.Textbox(label="User input")
outputs = gr.outputs.Textbox(label="Response")

chatInterface = gr.ChatInterface(
    fn=chat, 
    # inputs=inputs, 
    # outputs=outputs, 
    title="AI 塔罗",
    )

chatInterface.launch(share=True)