fix: 修复应用修改模型后,历史对话未使用最新模型 (#487)
Some checks are pending
sync2gitee / repo-sync (push) Waiting to run
Typos Check / Spell Check with Typos (push) Waiting to run

This commit is contained in:
shaohuzhang1 2024-05-20 20:21:45 +08:00 committed by GitHub
parent 03b662beec
commit 84c7728d00
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 1 deletions

View File

@ -41,7 +41,7 @@ from setting.serializers.provider_serializers import ModelSerializer
from smartdoc.conf import PROJECT_DIR from smartdoc.conf import PROJECT_DIR
token_cache = cache.caches['token_cache'] token_cache = cache.caches['token_cache']
chat_cache = cache.caches['chat_cache'] chat_cache = cache.caches['model_cache']
class ModelDatasetAssociation(serializers.Serializer): class ModelDatasetAssociation(serializers.Serializer):
@ -532,6 +532,7 @@ class ApplicationSerializer(serializers.Serializer):
QuerySet(ApplicationDatasetMapping).bulk_create( QuerySet(ApplicationDatasetMapping).bulk_create(
[ApplicationDatasetMapping(application_id=application_id, dataset_id=dataset_id) for dataset_id in [ApplicationDatasetMapping(application_id=application_id, dataset_id=dataset_id) for dataset_id in
dataset_id_list]) if len(dataset_id_list) > 0 else None dataset_id_list]) if len(dataset_id_list) > 0 else None
chat_cache.clear_by_application_id(application_id)
return self.one(with_valid=False) return self.one(with_valid=False)
def list_dataset(self, with_valid=True): def list_dataset(self, with_valid=True):

View File

@ -29,3 +29,15 @@ class MemCache(LocMemCache):
pickled = self._cache[key] pickled = self._cache[key]
self._cache.move_to_end(key, last=False) self._cache.move_to_end(key, last=False)
return pickled return pickled
def clear_by_application_id(self, application_id):
delete_keys = []
for key in self._cache.keys():
value = self._cache.get(key)
if (hasattr(value,
'application') and value.application is not None and value.application.id is not None and
str(
value.application.id) == application_id):
delete_keys.append(key)
for key in delete_keys:
self._delete(key)