# https://algowriting.medium.com/gpt-3-temperature-setting-101-41200ff0d0be
rendered = prompt.render()
response = openai.Completion.create(
engine="text-davinci-003",
prompt=rendered,
temperature=0.5,
top_p=0.9,
max_tokens=512,
stop=["<|endoftext|>"],
)
reply = response.choices[0].text.strip()
if reply:
flagged_str, blocked_str = moderate_message(
message=(rendered + reply)[-500:], user=user
)
if len(blocked_str) > 0:
return CompletionData(
status=CompletionResult.MODERATION_BLOCKED,
reply_text=reply,
status_text=f"from_response:{blocked_str}",
)
if len(flagged_str) > 0:
return CompletionData(
status=CompletionResult.MODERATION_FLAGGED,
reply_text=reply,
status_text=f"from_response:{flagged_str}",
)
return CompletionData(
status=CompletionResult.OK, reply_text=reply, status_text=None
)