fix: 修复人格一段时间后消失的问题

This commit is contained in:
Soulter
2023-09-25 15:55:51 +08:00
parent 191976e22e
commit 2f4e0bb4f2
2 changed files with 17 additions and 3 deletions
+12 -2
View File
@@ -235,9 +235,14 @@ class CommandOpenAIOfficial(Command):
self.provider.session_dict[session_id] = []
new_record = {
"user": {
"role": "system",
"role": "user",
"content": personalities[ps],
},
"AI": {
"role": "assistant",
"content": "好的,接下来我会扮演这个角色。"
},
'type': "personality",
'usage_tokens': 0,
'single-tokens': 0
}
@@ -251,9 +256,14 @@ class CommandOpenAIOfficial(Command):
}
new_record = {
"user": {
"role": "system",
"role": "user",
"content": ps,
},
"AI": {
"role": "assistant",
"content": "好的,接下来我会扮演这个角色。"
},
'type': "personality",
'usage_tokens': 0,
'single-tokens': 0
}
+5 -1
View File
@@ -113,6 +113,7 @@ class ProviderOpenAIOfficial(Provider):
f.close()
cache_data_list, new_record, req = self.wrap(prompt, session_id)
gu.log(f"CACHE_DATA_: {str(cache_data_list)}", level=gu.LEVEL_DEBUG, max_len=99999)
gu.log(f"OPENAI REQUEST: {str(req)}", level=gu.LEVEL_DEBUG, max_len=9999)
retry = 0
response = None
@@ -156,6 +157,8 @@ class ProviderOpenAIOfficial(Provider):
chatgpt_res = str(response["choices"][0]["message"]["content"]).strip()
current_usage_tokens = response['usage']['total_tokens']
gu.log(f"OPENAI RESPONSE: {response['usage']}", level=gu.LEVEL_DEBUG, max_len=9999)
# 超过指定tokens, 尽可能的保留最多的条目,直到小于max_tokens
if current_usage_tokens > self.max_tokens:
t = current_usage_tokens
@@ -164,7 +167,7 @@ class ProviderOpenAIOfficial(Provider):
if index >= len(cache_data_list):
break
# 保留人格信息
if 'user' in cache_data_list[index] and cache_data_list[index]['user']['role'] != 'system':
if cache_data_list[index]['type'] != 'personality':
t -= int(cache_data_list[index]['single_tokens'])
del cache_data_list[index]
else:
@@ -297,6 +300,7 @@ class ProviderOpenAIOfficial(Provider):
"content": prompt,
},
"AI": {},
'type': "common",
'usage_tokens': 0,
}
req_list = []