FIX: improve token counting (#234)

We were running out of tokens under certain conditions (really long
chains)

Add more buffer.
This commit is contained in:
Sam 2023-09-28 15:32:22 +10:00 committed by GitHub
parent 237e9478df
commit ed7d1f06d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 3 deletions

View File

@ -243,6 +243,7 @@ discourse_ai:
- sql_helper
- settings_explorer
- researcher
- creative
ai_bot_add_to_header:
default: true
client: true

View File

@ -16,9 +16,9 @@ module DiscourseAi
# note this is about 100 tokens over, OpenAI have a more optimal representation
@function_size ||= tokenize(available_functions.to_json).length
# provide a buffer of 80 tokens - our function counting is not
# 100% accurate so this is a trial and error number
buffer = @function_size + reply_params[:max_tokens] + 80
# provide a buffer of 120 tokens - our function counting is not
# 100% accurate and getting numbers to align exactly is very hard
buffer = @function_size + reply_params[:max_tokens] + 120
if bot_user.id == DiscourseAi::AiBot::EntryPoint::GPT4_ID
8192 - buffer