Skip to content

Commit 858384b

Browse files
committed
feat: i18n
1 parent ff3f511 commit 858384b

File tree

18 files changed

+1532
-1547
lines changed

18 files changed

+1532
-1547
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Generated by Django 4.2.15 on 2025-01-20 03:20
2+
3+
from django.db import migrations, models
4+
import smartdoc.conf
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('application', '0023_application_stt_autosend'),
11+
]
12+
13+
operations = [
14+
migrations.AddField(
15+
model_name='applicationaccesstoken',
16+
name='language',
17+
field=models.CharField(default=smartdoc.conf.Config.get_language_code, max_length=10, verbose_name='语言'),
18+
),
19+
]

apps/application/models/api_key_model.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
from application.models import Application
1515
from common.mixins.app_model_mixin import AppModelMixin
16+
from smartdoc.const import CONFIG
1617
from users.models import User
1718

1819

@@ -45,6 +46,8 @@ class ApplicationAccessToken(AppModelMixin):
4546
, default=list)
4647
show_source = models.BooleanField(default=False, verbose_name="是否显示知识来源")
4748

49+
language = models.CharField(max_length=10, verbose_name="语言", default=CONFIG.get_language_code)
50+
4851
class Meta:
4952
db_table = "application_access_token"
5053

apps/application/serializers/application_serializers.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,8 @@ class AccessTokenEditSerializer(serializers.Serializer):
336336
show_source = serializers.BooleanField(required=False,
337337
error_messages=ErrMessage.boolean(
338338
_("Whether to display knowledge sources")))
339+
language = serializers.CharField(required=False, allow_blank=True, allow_null=True,
340+
error_messages=ErrMessage.char(_("language")))
339341

340342
def edit(self, instance: Dict, with_valid=True):
341343
if with_valid:
@@ -358,6 +360,8 @@ def edit(self, instance: Dict, with_valid=True):
358360
application_access_token.white_list = instance.get('white_list')
359361
if 'show_source' in instance and instance.get('show_source') is not None:
360362
application_access_token.show_source = instance.get('show_source')
363+
if 'language' in instance and instance.get('language') is not None:
364+
application_access_token.language = instance.get('language')
361365
application_access_token.save()
362366
application_setting_model = DBModelManage.get_model('application_setting')
363367
xpack_cache = DBModelManage.get_model('xpack_cache')
@@ -980,6 +984,7 @@ def profile(self, with_valid=True):
980984
'file_upload_setting': application.file_upload_setting,
981985
'work_flow': application.work_flow,
982986
'show_source': application_access_token.show_source,
987+
'language': application_access_token.language,
983988
**application_setting_dict})
984989

985990
@transaction.atomic

apps/application/swagger_api/application_api.py

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ def get_request_body_api():
165165
'show_source': openapi.Schema(type=openapi.TYPE_BOOLEAN,
166166
title=_("Whether to display knowledge sources"),
167167
description=_("Whether to display knowledge sources")),
168+
'language': openapi.Schema(type=openapi.TYPE_STRING,
169+
title=_("language"),
170+
description=_("language"))
168171
}
169172
)
170173

@@ -282,24 +285,24 @@ def get_request_body_api():
282285
properties={
283286
'prompt': openapi.Schema(type=openapi.TYPE_STRING, title=_("Prompt word"),
284287
description=_("Prompt word"),
285-
default=_("""
286-
Known information:
287-
{data}
288-
Answer requirements:
289-
- If you don't know the answer or don't get the answer, please answer "No relevant information found in the knowledge base, it is recommended to consult relevant technical support or refer to official documents for operation".
290-
- Avoid mentioning that you got the knowledge from <data></data>.
291-
- Please keep the answer consistent with the description in <data></data>.
292-
- Please use markdown syntax to optimize the format of the answer.
293-
- Please return the image link, link address and script language in <data></data> completely.
294-
- Please answer in the same language as the question.
295-
Question:
296-
{question}
297-
""")),
288+
default=_(("Known information:\n"
289+
"{data}\n"
290+
"Answer requirements:\n"
291+
"- If you don't know the answer or don't get the answer, please answer \"No relevant information found in the knowledge base, it is recommended to consult relevant technical support or refer to official documents for operation\".\n"
292+
"- Avoid mentioning that you got the knowledge from <data></data>.\n"
293+
"- Please keep the answer consistent with the description in <data></data>.\n"
294+
"- Please use markdown syntax to optimize the format of the answer.\n"
295+
"- Please return the image link, link address and script language in <data></data> completely.\n"
296+
"- Please answer in the same language as the question.\n"
297+
"Question:\n"
298+
"{question}"))),
298299

299300
'system': openapi.Schema(type=openapi.TYPE_STRING, title=_("System prompt words (role)"),
300301
description=_("System prompt words (role)")),
301-
'no_references_prompt': openapi.Schema(type=openapi.TYPE_STRING, title=_("No citation segmentation prompt"),
302-
default="{question}", description=_("No citation segmentation prompt"))
302+
'no_references_prompt': openapi.Schema(type=openapi.TYPE_STRING,
303+
title=_("No citation segmentation prompt"),
304+
default="{question}",
305+
description=_("No citation segmentation prompt"))
303306

304307
}
305308
)
@@ -323,22 +326,29 @@ def get_request_body_api():
323326
required=['name', 'desc', 'model_id', 'dialogue_number', 'dataset_setting', 'model_setting',
324327
'problem_optimization', 'stt_model_enable', 'stt_model_enable', 'tts_type'],
325328
properties={
326-
'name': openapi.Schema(type=openapi.TYPE_STRING, title=_("Application Name"), description=_("Application Name")),
327-
'desc': openapi.Schema(type=openapi.TYPE_STRING, title=_("Application Description"), description=_("Application Description")),
328-
'model_id': openapi.Schema(type=openapi.TYPE_STRING, title=_("Model id"), description=_("Model id")),
329-
"dialogue_number": openapi.Schema(type=openapi.TYPE_NUMBER, title=_("Number of multi-round conversations"),
329+
'name': openapi.Schema(type=openapi.TYPE_STRING, title=_("Application Name"),
330+
description=_("Application Name")),
331+
'desc': openapi.Schema(type=openapi.TYPE_STRING, title=_("Application Description"),
332+
description=_("Application Description")),
333+
'model_id': openapi.Schema(type=openapi.TYPE_STRING, title=_("Model id"),
334+
description=_("Model id")),
335+
"dialogue_number": openapi.Schema(type=openapi.TYPE_NUMBER,
336+
title=_("Number of multi-round conversations"),
330337
description=_("Number of multi-round conversations")),
331-
'prologue': openapi.Schema(type=openapi.TYPE_STRING, title=_("Opening remarks"), description=_("Opening remarks")),
338+
'prologue': openapi.Schema(type=openapi.TYPE_STRING, title=_("Opening remarks"),
339+
description=_("Opening remarks")),
332340
'dataset_id_list': openapi.Schema(type=openapi.TYPE_ARRAY,
333341
items=openapi.Schema(type=openapi.TYPE_STRING),
334-
title=_("List of associated knowledge base IDs"), description=_("List of associated knowledge base IDs")),
342+
title=_("List of associated knowledge base IDs"),
343+
description=_("List of associated knowledge base IDs")),
335344
'dataset_setting': ApplicationApi.DatasetSetting.get_request_body_api(),
336345
'model_setting': ApplicationApi.ModelSetting.get_request_body_api(),
337346
'problem_optimization': openapi.Schema(type=openapi.TYPE_BOOLEAN, title=_("Problem Optimization"),
338347
description=_("Problem Optimization"), default=True),
339348
'type': openapi.Schema(type=openapi.TYPE_STRING, title=_("Application Type"),
340349
description=_("Application Type SIMPLE | WORK_FLOW")),
341-
'problem_optimization_prompt': openapi.Schema(type=openapi.TYPE_STRING, title=_('Question optimization tips'),
350+
'problem_optimization_prompt': openapi.Schema(type=openapi.TYPE_STRING,
351+
title=_('Question optimization tips'),
342352
description=_("Question optimization tips"),
343353
default=_(
344354
"() contains the user's question. Answer the guessed user's question based on the context ({question}) Requirement: Output a complete question and put it in the <data></data> tag")),

apps/common/mixins/app_model_mixin.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
@desc:
88
"""
99
from django.db import models
10-
from django.utils.translation import gettext_lazy as _
10+
1111

1212
class AppModelMixin(models.Model):
13-
create_time = models.DateTimeField(verbose_name=_('Create time'), auto_now_add=True)
14-
update_time = models.DateTimeField(verbose_name=_('Update time'), auto_now=True)
13+
create_time = models.DateTimeField(verbose_name="创建时间", auto_now_add=True)
14+
update_time = models.DateTimeField(verbose_name="修改时间", auto_now=True)
1515

1616
class Meta:
1717
abstract = True

0 commit comments

Comments
 (0)