Fix tokens

This commit is contained in:
2023-10-20 18:45:03 +02:00
parent daea2e30b7
commit d8e68aab8b
+5 -3
View File
@@ -606,25 +606,27 @@ async def handle_response(prompt, vykidailo, bartender, history, username, music
if music:
algorithm = "gpt-3.5-turbo-16k"
table = message_table_muzyka
token_amount = 16000
token_amount = 16384
else:
table = MESSAGE_TABLE
algorithm = "gpt-4"
token_amount = 80000
token_amount = 8192
prompt_tokens = num_tokens_from_string(final_prompt, "gpt-4")
for i in reversed(table):
temp_token = num_tokens_from_string(i["content"], "gpt-4")
logger.error("Liczba tokenow %s prompt token %s temp token %s", tokens, prompt_tokens, temp_token)
if tokens < token_amount + prompt_tokens + temp_token:
history.append(i)
tokens += temp_token
temp = {"role": "user", "content": final_prompt}
history.append(temp)
logger.error("Liczba tokenów wyslana %s", tokens)
response = await openai.ChatCompletion.acreate(
model=algorithm, messages=history
)
logger.error("Liczba tokenów przed dodaniem historii %s", tokens)
logger.info("Historia wysłana:")
logger.info(history)
await asyncio.sleep(10)