File size: 2,611 Bytes
93c3753
6071116
93c3753
 
 
 
 
 
 
 
 
 
6071116
93c3753
7dec94f
93c3753
 
 
 
 
 
 
 
4600530
93c3753
 
 
7dec94f
6071116
 
 
93c3753
 
 
 
 
6071116
 
 
 
 
93c3753
7dec94f
93c3753
7dec94f
6071116
7dec94f
 
6071116
7dec94f
6071116
 
 
 
7dec94f
6071116
 
 
 
 
 
 
7dec94f
6071116
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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()