import openai | |
import gradio as gr | |
import time | |
import os | |
openai.api_key = os.getenv("OPENAI_API_KEY") | |
def get_completion(prompt, model="gpt-3.5-turbo"): | |
messages = [{"role": "user", "content": prompt}] | |
response = openai.ChatCompletion.create( | |
model=model, | |
messages=messages, | |
temperature=0, # this is the degree of randomness of the model's output | |
) | |
return response.choices[0].message["content"] | |
def get_completion_from_messages(messages, model="gpt-3.5-turbo", temperature=0.8): | |
response = openai.ChatCompletion.create( | |
model=model, | |
messages=messages, | |
temperature=temperature, # this is the degree of randomness of the model's output | |
) | |
# print(str(response.choices[0].message)) | |
return response.choices[0].message["content"] | |
messages = [ | |
{'role':'interviewer', 'content':'๋๋ ์๊ธฐ์๊ฐ์์ ๊ธฐ๋ฐํ์ฌ ์ง๋ฌธ์ ํ๋ ๋ฉด์ ๊ด์ด์ผ.\ | |
๋ง์ฝ ์ ๋ฌธ์ฉ์ด๊ฐ ์๋ค๋ฉด ๊ผฌ๋ฆฌ์ง๋ฌธํด์ค'}] | |
#### | |
#user input | |
#get completion ํต๊ณผ ์์ผ์ ๋ต๋ณ์ป์ | |
#์ด๋ ์ญํ ๋ถ๋ด ๋ฐ ํ๋กฌํํธ ์์ง๋์ด๋ง ์งํ | |
#### | |
class ChatBot: | |
def __init__(self): | |
# Initialize the ChatBot class with an empty history | |
self.history = [] | |
def predict(self, user_input): | |
response_text =get_completion_from_messages(messages, temperature=0.8) | |
return response_text # Return the generated response | |
bot = ChatBot() | |
title = "์์์๊ธฐ๋ฐ ๋ฉด์ ์๋ฎฌ๋ ์ด์ chat bot (this template based on Tonic's MistralMed Chat)" | |
#description = "์ด ๊ณต๊ฐ์ ์ฌ์ฉํ์ฌ ํ์ฌ ๋ชจ๋ธ์ ํ ์คํธํ ์ ์์ต๋๋ค. [(Tonic/MistralMed)](https://huggingface.co/Tonic/MistralMed) ๋๋ ์ด ๊ณต๊ฐ์ ๋ณต์ ํ๊ณ ๋ก์ปฌ ๋๋ ๐คHuggingFace์์ ์ฌ์ฉํ ์ ์์ต๋๋ค. [Discord์์ ํจ๊ป ๋ง๋ค๊ธฐ ์ํด Discord์ ๊ฐ์ ํ์ญ์์ค](https://discord.gg/VqTxc76K3u). You can use this Space to test out the current model [(Tonic/MistralMed)](https://huggingface.co/Tonic/MistralMed) or duplicate this Space and use it locally or on ๐คHuggingFace. [Join me on Discord to build together](https://discord.gg/VqTxc76K3u)." | |
#examples = [["[Question:] What is the proper treatment for buccal herpes?", | |
# "You are a medicine and public health expert, you will receive a question, answer the question, and provide a complete answer"]] | |
iface = gr.Interface( | |
fn=bot.predict, | |
title=title, | |
inputs=["text", "text"], # Take user input and system prompt separately | |
outputs="text", | |
theme="ParityError/Anime" | |
) | |
iface.launch() |