Skip to content

Commit

Permalink
feat: 历史版本
Browse files Browse the repository at this point in the history
  • Loading branch information
shaohuzhang1 committed Oct 23, 2024
1 parent e4d9a49 commit 8a38e42
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 9 deletions.
12 changes: 11 additions & 1 deletion apps/application/migrations/0018_workflowversion_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,15 @@ class Migration(migrations.Migration):
name='name',
field=models.CharField(default='', max_length=128, verbose_name='版本名称'),
),
migrations.RunSQL(sql)
migrations.RunSQL(sql),
migrations.AddField(
model_name='workflowversion',
name='publish_user_id',
field=models.UUIDField(default=None, null=True, verbose_name='发布者id'),
),
migrations.AddField(
model_name='workflowversion',
name='publish_user_name',
field=models.CharField(default='', max_length=128, verbose_name='发布者名称'),
),
]
2 changes: 2 additions & 0 deletions apps/application/models/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ class WorkFlowVersion(AppModelMixin):
id = models.UUIDField(primary_key=True, max_length=128, default=uuid.uuid1, editable=False, verbose_name="主键id")
application = models.ForeignKey(Application, on_delete=models.CASCADE)
name = models.CharField(verbose_name="版本名称", max_length=128, default="")
publish_user_id = models.UUIDField(verbose_name="发布者id", max_length=128, default=None, null=True)
publish_user_name = models.CharField(verbose_name="发布者名称", max_length=128, default="")
work_flow = models.JSONField(verbose_name="工作流数据", default=dict)

class Meta:
Expand Down
14 changes: 11 additions & 3 deletions apps/application/serializers/application_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
@date:2023/11/7 10:02
@desc:
"""
import datetime
import hashlib
import json
import os
Expand Down Expand Up @@ -50,6 +51,7 @@
from setting.models_provider.tools import get_model_instance_by_model_user_id
from setting.serializers.provider_serializers import ModelSerializer
from smartdoc.conf import PROJECT_DIR
from users.models import User

chat_cache = cache.caches['chat_cache']

Expand Down Expand Up @@ -655,6 +657,8 @@ def delete(self, with_valid=True):
def publish(self, instance, with_valid=True):
if with_valid:
self.is_valid()
user_id = self.data.get('user_id')
user = QuerySet(User).filter(id=user_id).first()
application = QuerySet(Application).filter(id=self.data.get("application_id")).first()
work_flow = instance.get('work_flow')
if work_flow is None:
Expand All @@ -674,7 +678,10 @@ def publish(self, instance, with_valid=True):
application.save()
# 插入知识库关联关系
self.save_application_mapping(application_dataset_id_list, dataset_id_list, application.id)
work_flow_version = WorkFlowVersion(work_flow=work_flow, application=application)
work_flow_version = WorkFlowVersion(work_flow=work_flow, application=application,
name=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
publish_user_id=user_id,
publish_user_name=user.username)
chat_cache.clear_by_application_id(str(application.id))
work_flow_version.save()
return True
Expand Down Expand Up @@ -810,7 +817,7 @@ def edit(self, instance: Dict, with_valid=True):
update_keys = ['name', 'desc', 'model_id', 'multiple_rounds_dialogue', 'prologue', 'status',
'dataset_setting', 'model_setting', 'problem_optimization', 'dialogue_number',
'stt_model_id', 'tts_model_id', 'tts_model_enable', 'stt_model_enable', 'tts_type',
'api_key_is_active', 'icon', 'work_flow', 'model_params_setting','tts_model_params_setting',
'api_key_is_active', 'icon', 'work_flow', 'model_params_setting', 'tts_model_params_setting',
'problem_optimization_prompt']
for update_key in update_keys:
if update_key in instance and instance.get(update_key) is not None:
Expand Down Expand Up @@ -952,7 +959,8 @@ def text_to_speech(self, text, with_valid=True):
application_id = self.data.get('application_id')
application = QuerySet(Application).filter(id=application_id).first()
if application.tts_model_enable:
model = get_model_instance_by_model_user_id(application.tts_model_id, application.user_id, **application.tts_model_params_setting)
model = get_model_instance_by_model_user_id(application.tts_model_id, application.user_id,
**application.tts_model_params_setting)
return model.text_to_speech(text)

class ApplicationKeySerializerModel(serializers.ModelSerializer):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
class ApplicationVersionModelSerializer(serializers.ModelSerializer):
class Meta:
model = WorkFlowVersion
fields = ['id', 'name', 'application_id', 'work_flow', 'create_time', 'update_time']
fields = ['id', 'name', 'application_id', 'work_flow', 'publish_user_id', 'publish_user_name', 'create_time',
'update_time']


class ApplicationVersionEditSerializer(serializers.Serializer):
Expand All @@ -38,7 +39,7 @@ def get_query_set(self):
query_set = QuerySet(WorkFlowVersion).filter(application_id=self.data.get('application_id'))
if 'name' in self.data and self.data.get('name') is not None:
query_set = query_set.filter(name__contains=self.data.get('name'))
return query_set
return query_set.order_by("-create_time")

def list(self, with_valid=True):
if with_valid:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setting.models_provider.base_model_provider import MaxKBBaseModel
from typing import Dict
import requests

from setting.models_provider.base_model_provider import MaxKBBaseModel


class TencentEmbeddingModel(MaxKBBaseModel):
Expand All @@ -19,7 +19,6 @@ def new_instance(model_type: str, model_name: str, model_credential: Dict[str, s
model_name=model_name,
)


def _generate_auth_token(self):
# Example method to generate an authentication token for the model API
return f"{self.secret_id}:{self.secret_key}"

0 comments on commit 8a38e42

Please sign in to comment.