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(input, model="gpt-3.5-turbo", temperature=0.8): messages = [ {'role': 'system', 'content': '너는 자기소개서에 기반하여 질문을 하는 면접관이야.\ 만약 전문용어가 있다면 꼬리질문해줘'}, { "role": "user", "content": input } ] 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"] #### #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(user_input, 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"], # Take user input and system prompt separately outputs="text", theme="ParityError/Anime" ) iface.launch()