Spaces:
Runtime error
Runtime error
File size: 1,320 Bytes
eabc9cd f26cbb9 eabc9cd f26cbb9 eabc9cd 4617b5f eabc9cd f26cbb9 eabc9cd |
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 |
import os
from openai import OpenAI
from .conversation_storage import get_conversation_storage, update_conversation_storage
BASE_ENHANCE_PROMPT = {
"role": "system", "content": "You are a helpful assistant. You are helping a customer to solve a problem."}
client = OpenAI()
def send_message(prompt: str, histories: list = [], api_key: str = None):
if api_key is not None:
client.api_key = api_key
return client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
BASE_ENHANCE_PROMPT,
*histories,
{"role": "user", "content": prompt}
]
).choices[0].message.content
def send_message_conversation(conversation_id: str, prompt: str, api_key: str = None):
if api_key is not None:
client.api_key = api_key
# Update conversation
update_conversation_storage(conversation_id, "user", prompt)
# Generate response
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
BASE_ENHANCE_PROMPT,
*get_conversation_storage(conversation_id),
{"role": "user", "content": prompt}
]
).choices[0].message.content
# Update conversation
update_conversation_storage(conversation_id, "assistant", response)
return response
|