Spaces:
Sleeping
Sleeping
File size: 1,316 Bytes
6b814d2 667399c 6b814d2 667399c | 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 openai
import os
from dotenv import load_dotenv, find_dotenv
_ = load_dotenv(find_dotenv()) # read local .env file
openai.api_key = os.getenv('OPENAI_API_KEY')
def get_completion_from_messages(messages,
model="gpt-3.5-turbo",
temperature=0,
max_tokens=500):
response = openai.chat.completions.create( # Use openai.chat.completions.create instead of openai.ChatCompletion.create
model=model,
messages=messages,
temperature=temperature,
max_tokens=max_tokens,
)
return response.choices[0].message.content
import gradio as gr
def generate(input, slider):
messages = [
{'role':'user',
'content': f"{input}"},
]
output = get_completion_from_messages(messages)
return output
demo = gr.ChatInterface(
fn=generate,
chatbot=gr.Chatbot(height=300),
textbox=gr.Textbox(placeholder="Ask me a yes or no question", container=False, scale=7),
title="Your Helper CHAT Bot",
description="Ask 'Yes Man' any question",
theme="soft",
examples=["Hello", "Am I cool?", "Are tomatoes vegetables?"],
cache_examples=True,
#retry_btn=None,
#undo_btn="Delete Previous",
#clear_btn="Clear",
).launch() |