Skip to content

Commit

Permalink
Reduced token limit before resummarising (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
art-from-the-machine committed Apr 14, 2024
1 parent 9002678 commit f7fbb8e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/conversation/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ def generate_system_message(self, prompt: str, include_player: bool = False, inc
conversation_summaries=content[1]
)
if self.__client.calculate_tokens_from_text(result) < self.__client.token_limit * self.__token_limit_percent:
logging.log(23, f'Prompt sent to LLM: {result.strip()}')
logging.log(23, f'Prompt sent to LLM ({self.__client.calculate_tokens_from_text(result)} tokens): {result.strip()}')
return result


logging.log(23, f'Prompt sent to LLM: {prompt.strip()}')
logging.log(23, f'Prompt sent to LLM ({self.__client.calculate_tokens_from_text(result)} tokens): {prompt.strip()}')
return prompt #This should only trigger, if the default prompt even without bios and conversation_summaries is too long
6 changes: 4 additions & 2 deletions src/conversation/conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(self, context_for_conversation: context, stt :Transcriber, tts: Syn
self.__output_manager: ChatManager = output_manager
self.__rememberer: remembering = rememberer
self.__context_length: int = context_length
self.__token_limit_percent: float = 0.45
self.__token_limit_percent: float = token_limit_percent
self.__has_already_ended: bool = False

def add_character(self, new_character: Character):
Expand Down Expand Up @@ -90,7 +90,9 @@ def proceed(self) -> bool:
else:
self.__add_assistant_message()
# After an assistant_message is generated, check if the current message exchange is about to break the context size of the LLM and if yes, reload the conversation
if self.__output_manager.num_tokens(self.__messages) > (round(self.__context_length*self.__token_limit_percent,0)):
conversation_token_count = self.__output_manager.num_tokens(self.__messages)
conversation_token_limit = round(self.__context_length*self.__token_limit_percent,0)
if conversation_token_count > conversation_token_limit:
self.__reload_conversation()

# After a message has been added, check if the conversation_type decides to end the conversation
Expand Down
2 changes: 1 addition & 1 deletion src/remember/summaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class summaries(remembering):
""" Stores a conversation as a summary in a text file.
Loads the latest summary from disk for a prompt text.
"""
def __init__(self, memory_prompt: str, resummarize_prompt: str, client: openai_client, language_name: str, game: str, summary_limit_pct: float = 0.35) -> None:
def __init__(self, memory_prompt: str, resummarize_prompt: str, client: openai_client, language_name: str, game: str, summary_limit_pct: float = 0.3) -> None:
super().__init__()
self.loglevel = 28
self.__summary_limit_pct: float = summary_limit_pct
Expand Down

0 comments on commit f7fbb8e

Please sign in to comment.