mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-30 01:32:49 +00:00
feat: add SQL query for embedding text and update model API routes to remove workspace_id
This commit is contained in:
parent
269960649d
commit
fee5993c22
|
|
@ -0,0 +1,27 @@
|
|||
SELECT
|
||||
problem_paragraph_mapping."id" AS "source_id",
|
||||
paragraph.document_id AS document_id,
|
||||
paragraph."id" AS paragraph_id,
|
||||
problem.knowledge_id AS knowledge_id,
|
||||
0 AS source_type,
|
||||
problem."content" AS "text",
|
||||
paragraph.is_active AS is_active
|
||||
FROM
|
||||
problem problem
|
||||
LEFT JOIN problem_paragraph_mapping problem_paragraph_mapping ON problem_paragraph_mapping.problem_id=problem."id"
|
||||
LEFT JOIN paragraph paragraph ON paragraph."id" = problem_paragraph_mapping.paragraph_id
|
||||
${problem}
|
||||
|
||||
UNION
|
||||
SELECT
|
||||
paragraph."id" AS "source_id",
|
||||
paragraph.document_id AS document_id,
|
||||
paragraph."id" AS paragraph_id,
|
||||
paragraph.knowledge_id AS knowledge_id,
|
||||
1 AS source_type,
|
||||
concat_ws(E'\n',paragraph.title,paragraph."content") AS "text",
|
||||
paragraph.is_active AS is_active
|
||||
FROM
|
||||
paragraph paragraph
|
||||
|
||||
${paragraph}
|
||||
|
|
@ -20,7 +20,7 @@ urlpatterns = [
|
|||
|
||||
if os.environ.get('SERVER_NAME', 'web') == 'local_model':
|
||||
urlpatterns += [
|
||||
path('workspace/<str:workspace_id>/model/<str:model_id>/embed_documents', views.ModelApply.EmbedDocuments.as_view()),
|
||||
path('workspace/<str:workspace_id>model/<str:model_id>/embed_query', views.ModelApply.EmbedQuery.as_view()),
|
||||
path('workspace/<str:workspace_id>model/<str:model_id>/compress_documents', views.ModelApply.CompressDocuments.as_view()),
|
||||
path('model/<str:model_id>/embed_documents', views.ModelApply.EmbedDocuments.as_view()),
|
||||
path('model/<str:model_id>/embed_query', views.ModelApply.EmbedQuery.as_view()),
|
||||
path('model/<str:model_id>/compress_documents', views.ModelApply.CompressDocuments.as_view()),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@ class ModelApply(APIView):
|
|||
responses=DefaultModelResponse.get_response(),
|
||||
tags=[_('Model')] # type: ignore
|
||||
)
|
||||
@has_permissions(PermissionConstants.MODEL_READ.get_workspace_permission())
|
||||
def post(self, request: Request, workspace_id, model_id):
|
||||
def post(self, request: Request, model_id):
|
||||
return result.success(
|
||||
ModelApplySerializers(data={'model_id': model_id}).embed_documents(request.data))
|
||||
|
||||
|
|
@ -41,8 +40,7 @@ class ModelApply(APIView):
|
|||
responses=DefaultModelResponse.get_response(),
|
||||
tags=[_('Model')] # type: ignore
|
||||
)
|
||||
@has_permissions(PermissionConstants.MODEL_READ.get_workspace_permission())
|
||||
def post(self, request: Request, workspace_id, model_id):
|
||||
def post(self, request: Request, model_id):
|
||||
return result.success(
|
||||
ModelApplySerializers(data={'model_id': model_id}).embed_query(request.data))
|
||||
|
||||
|
|
@ -54,7 +52,6 @@ class ModelApply(APIView):
|
|||
responses=DefaultModelResponse.get_response(),
|
||||
tags=[_('Model')] # type: ignore
|
||||
)
|
||||
@has_permissions(PermissionConstants.MODEL_READ.get_workspace_permission())
|
||||
def post(self, request: Request, workspace_id, model_id):
|
||||
def post(self, request: Request, model_id):
|
||||
return result.success(
|
||||
ModelApplySerializers(data={'model_id': model_id}).compress_documents(request.data))
|
||||
|
|
|
|||
Loading…
Reference in New Issue