Skip to content

Commit

Permalink
Properly count used tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
mruwnik committed Dec 2, 2023
1 parent 51d82c8 commit 9831aea
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion api/src/stampy_chat/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,10 @@ def history_tokens(self):

@property
def max_response_tokens(self):
return min(self.maxNumTokens - self.context_tokens - self.history_tokens, self.maxCompletionTokens)
available_tokens = (
self.maxNumTokens -
self.context_tokens - len(self.encoder.encode(self.context_prompt)) -
self.history_tokens - len(self.encoder.encode(self.history_prompt)) -
len(self.encoder.encode(self.question_prompt))
)
return min(available_tokens, self.maxCompletionTokens)

0 comments on commit 9831aea

Please sign in to comment.