This commit is contained in:
2023-10-20 21:04:03 +02:00
parent f35fff4f6a
commit 6b9f42aa4a
+10 -9
View File
@@ -602,17 +602,17 @@ async def handle_response(prompt, vykidailo, bartender, history, username, music
json.dump(file_data, file_memory, indent=4)
history = []
history.append(GPT_SETTINGS[0])
tokens = num_tokens_from_string(GPT_SETTINGS[0], "gpt-4")
chat_GPT_tokens = num_tokens_from_string(GPT_SETTINGS[0], "gpt-4")
for (slowo, reakcja) in word_reactions.items():
if not reakcja[3]:
content = "Kiedy słyszysz " + slowo + " to reagujesz lub dzieje się to " + reakcja[0]
temp = {"role": "system", "content": content}
tokens += num_tokens_from_string(temp, "gpt-4")
chat_GPT_tokens += num_tokens_from_string(temp, "gpt-4")
history.append(temp)
final_prompt = username + ":" + prompt
logger.error("Liczba tokenów przed dodaniem historii %s", tokens)
logger.error("Liczba tokenów przed dodaniem historii %s", chat_GPT_tokens)
if music:
algorithm = "gpt-3.5-turbo-16k"
table = message_table_muzyka
@@ -623,16 +623,17 @@ async def handle_response(prompt, vykidailo, bartender, history, username, music
token_amount = 8192
prompt_tokens = num_tokens_from_string({"role": "user", "content": final_prompt}, "gpt-4")
temptable = []
for i in reversed(table):
temp_token = num_tokens_from_string(i, "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
logger.error("Liczba tokenow %s prompt token %s temp token %s", chat_GPT_tokens, prompt_tokens, temp_token)
if chat_GPT_tokens < token_amount + prompt_tokens + temp_token:
temptable.insert(1, i)
chat_GPT_tokens += temp_token
history.extend(temptable)
temp = {"role": "user", "content": final_prompt}
history.append(temp)
logger.error("Liczba tokenów wyslana %s", tokens)
logger.error("Liczba tokenów wyslana %s", chat_GPT_tokens)
response = await openai.ChatCompletion.acreate(
model=algorithm, messages=history