File size: 959 Bytes
593afae
 
18002ed
d4f1e9a
295a79b
593afae
 
4e44db4
593afae
 
 
 
 
 
 
 
 
048201f
593afae
 
 
 
 
31727b8
 
9c94389
 
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
import openai
import gradio as gr
import os

openai.API_KEY = os.getenv("OPENAI_API_KEY") 

messages = [
    {"role": "system", "content": "You are an astrologer. And you are from Kit Astrology. Use an astrologer tone to answer questions with more details and friendly remind them to consult Kit if have any query, answer in traditional chinese "},
]

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

inputs = gr.inputs.Textbox(lines=7, label="Chat with AI")
outputs = gr.outputs.Textbox(label="Reply")

gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="AI Chatbot",
             description="Ask anything you want",
             theme="compact").launch()