Skip to content

Commit fb7062d

Browse files
Merge branch 'v2' into pr@v2@feat_permission_manage
2 parents b048d2d + 0d36704 commit fb7062d

File tree

73 files changed

+1320
-684
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+1320
-684
lines changed

apps/application/serializers/application_chat_record.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
from django.db import transaction
1414
from django.db.models import QuerySet
15+
from django.db.models.aggregates import Max
16+
from django.utils.translation import gettext_lazy as _, gettext
1517
from rest_framework import serializers
1618
from rest_framework.utils.formatting import lazy_format
1719

@@ -21,9 +23,6 @@
2123
from common.exception.app_exception import AppApiException
2224
from common.utils.common import post
2325
from knowledge.models import Paragraph, Document, Problem, ProblemParagraphMapping
24-
25-
from django.utils.translation import gettext_lazy as _, gettext
26-
2726
from knowledge.serializers.common import get_embedding_model_id_by_knowledge_id, update_document_char_length
2827
from knowledge.serializers.paragraph import ParagraphSerializers
2928
from knowledge.task.embedding import embedding_by_paragraph, embedding_by_paragraph_list
@@ -229,6 +228,11 @@ def post_improve(self, instance: Dict):
229228
chat_record.improve_paragraph_id_list.append(paragraph.id)
230229

231230
# 批量保存段落和问题映射
231+
max_position = Paragraph.objects.filter(document_id=document_id).aggregate(
232+
max_position=Max('position')
233+
)['max_position']
234+
for i, paragraph in enumerate(paragraphs):
235+
paragraph.position = max_position + i + 1
232236
Paragraph.objects.bulk_create(paragraphs)
233237
ProblemParagraphMapping.objects.bulk_create(problem_paragraph_mappings)
234238

@@ -276,11 +280,17 @@ def improve(self, instance: Dict, with_valid=True):
276280

277281
document_id = self.data.get("document_id")
278282
knowledge_id = self.data.get("knowledge_id")
279-
paragraph = Paragraph(id=uuid.uuid1(),
280-
document_id=document_id,
281-
content=instance.get("content"),
282-
knowledge_id=knowledge_id,
283-
title=instance.get("title") if 'title' in instance else '')
283+
max_position = Paragraph.objects.filter(document_id=document_id).aggregate(
284+
max_position=Max('position')
285+
)['max_position'] or 0
286+
paragraph = Paragraph(
287+
id=uuid.uuid1(),
288+
document_id=document_id,
289+
content=instance.get("content"),
290+
knowledge_id=knowledge_id,
291+
title=instance.get("title") if 'title' in instance else '',
292+
position=max_position + 1
293+
)
284294
problem_text = instance.get('problem_text') if instance.get(
285295
'problem_text') is not None else chat_record.problem_text
286296
problem, _ = QuerySet(Problem).get_or_create(content=problem_text, knowledge_id=knowledge_id)

apps/chat/urls.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
path('profile', views.AuthProfile.as_view()),
1111
path('application/profile', views.ApplicationProfile.as_view()),
1212
path('chat_message/<str:chat_id>', views.ChatView.as_view()),
13-
path('open', views.OpenView.as_view())
13+
path('open', views.OpenView.as_view()),
14+
path('captcha', views.CaptchaView.as_view(), name='captcha'),
1415
]

apps/chat/views/chat.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
from common.constants.permission_constants import ChatAuth
2222
from common.exception.app_exception import AppAuthenticationFailed
2323
from common.result import result
24+
from users.api import CaptchaAPI
25+
from users.serializers.login import CaptchaSerializer
2426

2527

2628
class AnonymousAuthentication(APIView):
@@ -122,3 +124,14 @@ def get(self, request: Request):
122124
data={'application_id': request.auth.application_id,
123125
'chat_user_id': request.auth.chat_user_id, 'chat_user_type': request.auth.chat_user_type,
124126
'debug': False}).open())
127+
128+
129+
class CaptchaView(APIView):
130+
@extend_schema(methods=['GET'],
131+
summary=_("Get captcha"),
132+
description=_("Get captcha"),
133+
operation_id=_("Get captcha"), # type: ignore
134+
tags=[_("User Management")], # type: ignore
135+
responses=CaptchaAPI.get_response())
136+
def get(self, request: Request):
137+
return result.success(CaptchaSerializer().generate())

apps/common/auth/handle/impl/user_token.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,9 @@ def get_role_list(user,
224224
workspace_user_role_mapping in
225225
workspace_user_role_mapping_list] + [user.role], version=version)
226226
else:
227-
role_list = [user.role, get_role_permission(RoleConstants.WORKSPACE_MANAGE, 'default')]
227+
role_list = [user.role]
228+
if user.role == RoleConstants.ADMIN.value.__str__():
229+
role_list = [user.role, get_role_permission(RoleConstants.WORKSPACE_MANAGE, 'default')]
228230
cache.set(key, role_list, version=version)
229231
return role_list
230232
return workspace_list

apps/knowledge/migrations/0001_initial.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class Migration(migrations.Migration):
5656
('scope', models.CharField(choices=[('SHARED', '共享'), ('WORKSPACE', '工作空间可用')], default='WORKSPACE', max_length=20, verbose_name='可用范围')),
5757
('file_size_limit', models.IntegerField(default=100, verbose_name='文件大小限制')),
5858
('meta', models.JSONField(default=dict, verbose_name='元数据')),
59-
('embedding_model', models.ForeignKey(default=knowledge.models.knowledge.default_model, on_delete=django.db.models.deletion.DO_NOTHING, to='models_provider.model', verbose_name='向量模型')),
59+
('embedding_model', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='models_provider.model', verbose_name='向量模型')),
6060
('user', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='users.user', verbose_name='所属用户')),
6161
],
6262
options={

apps/knowledge/models/knowledge.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,6 @@ def default_status_meta():
9595
return {"state_time": {}}
9696

9797

98-
def default_model():
99-
# todo : 这里需要从数据库中获取默认的模型
100-
return uuid.UUID('42f63a3d-427e-11ef-b3ec-a8a1595801ab')
10198

10299

103100
class KnowledgeFolder(MPTTModel, AppModelMixin):
@@ -128,8 +125,7 @@ class Knowledge(AppModelMixin):
128125
scope = models.CharField(max_length=20, verbose_name='可用范围', choices=KnowledgeScope.choices,
129126
default=KnowledgeScope.WORKSPACE)
130127
folder = models.ForeignKey(KnowledgeFolder, on_delete=models.DO_NOTHING, verbose_name="文件夹id", default='default')
131-
embedding_model = models.ForeignKey(Model, on_delete=models.DO_NOTHING, verbose_name="向量模型",
132-
default=default_model)
128+
embedding_model = models.ForeignKey(Model, on_delete=models.DO_NOTHING, verbose_name="向量模型")
133129
file_size_limit = models.IntegerField(verbose_name="文件大小限制", default=100)
134130
file_count_limit = models.IntegerField(verbose_name="文件数量限制", default=50)
135131
meta = models.JSONField(verbose_name="元数据", default=dict)

apps/knowledge/serializers/paragraph.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def save(self, instance: Dict, with_valid=True, with_embedding=True):
270270
'knowledge_id': knowledge_id,
271271
'document_id': document_id,
272272
'workspace_id': self.data.get('workspace_id')
273-
}).adjust_position(position=instance.get('position', max_position + 1))
273+
}).adjust_position(instance.get('position', max_position + 1))
274274
# 插入問題
275275
QuerySet(Problem).bulk_create(problem_model_list) if len(problem_model_list) > 0 else None
276276
# 插入问题关联关系
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Section title (optional), Section content (required,question answer), Question (optional,one per line in the cell)
2+
MaxKB product introduction,"MaxKB is a knowledge base question-answering system based on the LLM large language model. MaxKB = Max Knowledge Base,aims to become the most powerful brain of the enterprise。Out-of-the-box: supports direct document upload、automatic crawling of online documents、automatic text splitting and vectorization、and good intelligent question-answering interactive experience;Seamless embedding: supports zero-coding and rapid embedding into third-party business systems;Multi-model support: supports docking with mainstream large models,including Ollama local private large models (such as Llama 2、Llama 3、qwen)、Tongyi Qianwen、OpenAI、Azure OpenAI、Kimi、Zhipu AI、iFlytek Spark and Baidu Qianfan large models、etc.","What is MaxKB?
3+
MaxKB product introduction
4+
Large language model supported by MaxKB
5+
MaxKB advantages"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
分段标题(选填),分段内容(必填,问题答案)),问题(选填,单元格内一行一个)
2+
MaxKB产品介绍,"MaxKB 是一款基于 LLM 大语言模型的知识库问答系统。MaxKB = Max Knowledge Base,旨在成为企业的最强大脑。
3+
开箱即用:支持直接上传文档、自动爬取在线文档,支持文本自动拆分、向量化,智能问答交互体验好;
4+
无缝嵌入:支持零编码快速嵌入到第三方业务系统;
5+
多模型支持:支持对接主流的大模型,包括 Ollama 本地私有大模型(如 Llama 2、Llama 3、qwen)、通义千问、OpenAI、Azure OpenAI、Kimi、智谱 AI、讯飞星火和百度千帆大模型等。","MaxKB是什么?
6+
MaxKB产品介绍
7+
MaxKB支持的大语言模型
8+
MaxKB优势"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
分段標題(選填),分段內容(必填,問題答案)),問題(選填,單元格內一行一個)
2+
MaxKB產品介紹,"MaxKB 是一款基於 LLM 大語言模型的知識庫問答系統。MaxKB = Max Knowledge Base,旨在成為企業的最強大大腦。
3+
開箱即用:支援直接上傳文檔、自動爬取線上文檔,支援文字自動分割、向量化,智慧問答互動體驗好;
4+
無縫嵌入:支援零編碼快速嵌入到第三方業務系統;
5+
多模型支援:支持對接主流的大模型,包括Ollama 本地私有大模型(如Llama 2、Llama 3、qwen)、通義千問、OpenAI、Azure OpenAI、Kimi、智譜AI、訊飛星火和百度千帆大模型等。 ","MaxKB是什麼?
6+
MaxKB產品介紹
7+
MaxKB支援的大語言模型
8+
MaxKB優勢"

0 commit comments

Comments
 (0)