Spaces:
Sleeping
Sleeping
File size: 1,495 Bytes
97dfb52 c3a3ddc 97dfb52 c3a3ddc 97dfb52 |
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 |
import openai
import backoff
default_system_message = "You are a instruction-following bot and you give the user exactly what they want, in the format they want, and nothing else. You have set verbose=0."
@backoff.on_exception(backoff.expo, (openai.error.RateLimitError, openai.error.APIConnectionError))
def get_chatgpt_answer(user_msg: str, system_msg: str=default_system_message, temp: float=0.2) -> str:
completion = openai.ChatCompletion.create(
model='gpt-3.5-turbo-0613',
# model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": system_msg},
{"role": "user", "content": user_msg},
],
temperature=temp,
)
result = completion['choices'][0]['message']['content']
return result
@backoff.on_exception(backoff.expo, (openai.error.RateLimitError, openai.error.APIConnectionError))
def get_chatgpt_serious_answer(user_msg: str) -> str:
completion = openai.ChatCompletion.create(
# model='gpt-3.5-turbo-0613',
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a instruction-following bot and you give the user exactly what they want, in the format they want, and nothing else. You have set verbose=0."},
{"role": "user", "content": user_msg},
],
temperature=0.0,
frequency_penalty=0.2,
#n=3,
#top_p=0.7,
)
result = completion['choices'][0]['message']['content']
return result |