Added get_completion
Browse files
main.py
CHANGED
|
@@ -17,6 +17,15 @@ client = OpenAI(
|
|
| 17 |
|
| 18 |
sp = "You are a helpful and concise assistant."
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
def get_completion_from_messages(messages, model="solar-1-mini-chat", temperature=0):
|
| 21 |
response = client.chat.completions.create(
|
| 22 |
model=model,
|
|
@@ -57,7 +66,7 @@ def send(msg:str, messages:list[str]=None):
|
|
| 57 |
if not messages: messages = []
|
| 58 |
messages.append(msg.rstrip())
|
| 59 |
print(messages)
|
| 60 |
-
r =
|
| 61 |
return (ChatMessage(msg, True), # The user's message
|
| 62 |
ChatMessage(r.rstrip(), False), # The chatbot's response
|
| 63 |
ChatInput()) # And clear the input field via an OOB swap
|
|
|
|
| 17 |
|
| 18 |
sp = "You are a helpful and concise assistant."
|
| 19 |
|
| 20 |
+
def get_completion(prompt, model="solar-1-mini-chat"):
|
| 21 |
+
messages = [{"role": "user", "content": prompt}]
|
| 22 |
+
response = client.chat.completions.create(
|
| 23 |
+
model=model,
|
| 24 |
+
messages=messages,
|
| 25 |
+
temperature=0, # this is the degree of randomness of the model's output
|
| 26 |
+
)
|
| 27 |
+
return response.choices[0].message["content"]
|
| 28 |
+
|
| 29 |
def get_completion_from_messages(messages, model="solar-1-mini-chat", temperature=0):
|
| 30 |
response = client.chat.completions.create(
|
| 31 |
model=model,
|
|
|
|
| 66 |
if not messages: messages = []
|
| 67 |
messages.append(msg.rstrip())
|
| 68 |
print(messages)
|
| 69 |
+
r = get_completion(messages) # get response from chat model
|
| 70 |
return (ChatMessage(msg, True), # The user's message
|
| 71 |
ChatMessage(r.rstrip(), False), # The chatbot's response
|
| 72 |
ChatInput()) # And clear the input field via an OOB swap
|