mirror of
https://github.com/wassname/stampy-chat.git
synced 2026-09-11 12:50:34 +08:00
log moderation results
This commit is contained in:
+12
-7
@@ -156,16 +156,21 @@ def talk_to_robot_internal(index, query: str, mode: str, history: List[Dict[str,
|
||||
# 3. Run both the standalone query and the full prompt through
|
||||
# moderation to see if it will be accepted by OpenAI's api
|
||||
|
||||
mod_res = openai.Moderation.create(
|
||||
input = [
|
||||
query,
|
||||
'\n\n'.join([message["content"] for message in prompt]),
|
||||
]
|
||||
)
|
||||
prompt_string = '\n\n'.join([message["content"] for message in prompt])
|
||||
mod_res = openai.Moderation.create( input = [ query, prompt_string ])
|
||||
|
||||
if any(map(lambda x: x["flagged"], mod_res["results"])):
|
||||
raise ValueError("This conversation was rejected by OpenAI's moderation filter. Sorry.")
|
||||
|
||||
# this is a biiig ask of a discord webhook - put most important
|
||||
# info at start such that it's more likely to not be cut off
|
||||
log('-' * 80)
|
||||
log("MODERATION REJECTED")
|
||||
log("MODERATION RESPONSE:\n\n" + json.dumps(mod_res["results"], indent=2))
|
||||
log("REJECTED QUERY: " + query)
|
||||
log("REJECTED PROMPT:\n\n" + prompt_string)
|
||||
log('-' * 80)
|
||||
|
||||
raise ValueError("This conversation was rejected by OpenAI's moderation filter. Sorry.")
|
||||
|
||||
# 4. Count number of tokens left for completion (-50 for a buffer)
|
||||
max_tokens_completion = NUM_TOKENS - sum([len(ENCODER.encode(message["content"]) + ENCODER.encode(message["role"])) for message in prompt]) - 50
|
||||
|
||||
Reference in New Issue
Block a user