Removed max history length from openai calls
This commit is contained in:
@@ -6,7 +6,6 @@ from base_telegram_inference_bot import BaseTelegramInferenceBot
|
||||
from openai import OpenAI, AzureOpenAI # Import both
|
||||
|
||||
class OpenAICompatibleInferenceBot(BaseTelegramInferenceBot):
|
||||
DEFAULT_MAX_HISTORY_LENGTH = 20
|
||||
DEFAULT_MAX_TOKENS = 1000 # Default for _configure_model_and_tokens
|
||||
|
||||
def __init__(
|
||||
@@ -25,7 +24,6 @@ class OpenAICompatibleInferenceBot(BaseTelegramInferenceBot):
|
||||
):
|
||||
super().__init__(system_prompt_content=system_prompt_content, system_prompt_path=system_prompt_path)
|
||||
|
||||
self.max_history_length = max_history_length if max_history_length is not None else self.DEFAULT_MAX_HISTORY_LENGTH
|
||||
self.client = client
|
||||
|
||||
if not self.client:
|
||||
@@ -194,16 +192,7 @@ class OpenAICompatibleInferenceBot(BaseTelegramInferenceBot):
|
||||
# Ensure final content is returned even if max iterations hit with pending tool calls
|
||||
break
|
||||
|
||||
self.conversation_history[user_id] = messages # Persist the full exchange for this turn
|
||||
# Apply history length limit
|
||||
if len(self.conversation_history[user_id]) > self.max_history_length:
|
||||
# Keep system prompt if present as the first message, then trim the rest
|
||||
if self.conversation_history[user_id][0]["role"] == "system":
|
||||
system_msg = [self.conversation_history[user_id][0]]
|
||||
trimmed_history = self.conversation_history[user_id][-(self.max_history_length-1):]
|
||||
self.conversation_history[user_id] = system_msg + trimmed_history
|
||||
else:
|
||||
self.conversation_history[user_id] = self.conversation_history[user_id][-self.max_history_length:]
|
||||
self.conversation_history[user_id] = messages
|
||||
|
||||
final_assistant_message = messages[-1]
|
||||
return final_assistant_message.content if final_assistant_message.role == "assistant" and final_assistant_message.content is not None else "Assistant did not provide a textual response."
|
||||
|
||||
Reference in New Issue
Block a user