Enhance Memory class: Remove 'model_use' and 'time' in messages payload when user select free model from oepn router which result 500 error

This commit is contained in:
Mike Lin
2025-06-22 17:39:38 +08:00
parent 12a6705724
commit 860e52c3fa
+7
View File
@@ -7,10 +7,14 @@ import json
from typing import List, Tuple, Type, Dict from typing import List, Tuple, Type, Dict
import torch import torch
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
import configparser
from sources.utility import timer_decorator, pretty_print, animate_thinking from sources.utility import timer_decorator, pretty_print, animate_thinking
from sources.logger import Logger from sources.logger import Logger
config = configparser.ConfigParser()
config.read('config.ini')
class Memory(): class Memory():
""" """
Memory is a class for managing the conversation memory Memory is a class for managing the conversation memory
@@ -162,6 +166,9 @@ class Memory():
if self.memory[curr_idx-1]['content'] == content: if self.memory[curr_idx-1]['content'] == content:
pretty_print("Warning: same message have been pushed twice to memory", color="error") pretty_print("Warning: same message have been pushed twice to memory", color="error")
time_str = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") time_str = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
if config["MAIN"]["provider_name"] == "openrouter":
self.memory.append({'role': role, 'content': content})
else:
self.memory.append({'role': role, 'content': content, 'time': time_str, 'model_used': self.model_provider}) self.memory.append({'role': role, 'content': content, 'time': time_str, 'model_used': self.model_provider})
return curr_idx-1 return curr_idx-1