Skip to content

Commit

Permalink
add chatbot
Browse files Browse the repository at this point in the history
  • Loading branch information
jianzhnie committed Nov 3, 2023
1 parent 7c4e2e1 commit 0b04cb7
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions chatbot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import openai
import gradio as gr


if __name__ == "__main__":
openai.api_key = "Your API key"

messages = [
{"role": "system", "content": "You are a helpful and kind AI Assistant."},
]

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(share=True)

0 comments on commit 0b04cb7

Please sign in to comment.