File size: 1,170 Bytes
1564f7d eb00604 | 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 | # Build a chatbot with interface using GPT-3 Key: OpenAI API Key
import openai
import gradio as gr
from dotenv import load_dotenv
import os
load_dotenv()
openai.api_key = os.getenv('OPENAI_KEY')
messages = [
{"role": "system", "content": "You are a helpful and kind AI Assistant created by Livia Ellen, a data scientist with 5 years experience of Python programming. For more information about her you can go to her website liviaellen.com, To contact her, please reach liviaellen@msn.com . She likes paragliding and traveling."},
]
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 Ellen-GPT")
outputs = gr.outputs.Textbox(label="Reply")
gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="Ellen AI Assistant",
description="Ask anything you want",
theme=gr.themes.Soft()).launch()
|