Skip to content

Commit fee5993

Browse files
committed
feat: add SQL query for embedding text and update model API routes to remove workspace_id
1 parent 2699606 commit fee5993

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
SELECT
2+
problem_paragraph_mapping."id" AS "source_id",
3+
paragraph.document_id AS document_id,
4+
paragraph."id" AS paragraph_id,
5+
problem.knowledge_id AS knowledge_id,
6+
0 AS source_type,
7+
problem."content" AS "text",
8+
paragraph.is_active AS is_active
9+
FROM
10+
problem problem
11+
LEFT JOIN problem_paragraph_mapping problem_paragraph_mapping ON problem_paragraph_mapping.problem_id=problem."id"
12+
LEFT JOIN paragraph paragraph ON paragraph."id" = problem_paragraph_mapping.paragraph_id
13+
${problem}
14+
15+
UNION
16+
SELECT
17+
paragraph."id" AS "source_id",
18+
paragraph.document_id AS document_id,
19+
paragraph."id" AS paragraph_id,
20+
paragraph.knowledge_id AS knowledge_id,
21+
1 AS source_type,
22+
concat_ws(E'\n',paragraph.title,paragraph."content") AS "text",
23+
paragraph.is_active AS is_active
24+
FROM
25+
paragraph paragraph
26+
27+
${paragraph}

apps/models_provider/urls.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
if os.environ.get('SERVER_NAME', 'web') == 'local_model':
2222
urlpatterns += [
23-
path('workspace/<str:workspace_id>/model/<str:model_id>/embed_documents', views.ModelApply.EmbedDocuments.as_view()),
24-
path('workspace/<str:workspace_id>model/<str:model_id>/embed_query', views.ModelApply.EmbedQuery.as_view()),
25-
path('workspace/<str:workspace_id>model/<str:model_id>/compress_documents', views.ModelApply.CompressDocuments.as_view()),
23+
path('model/<str:model_id>/embed_documents', views.ModelApply.EmbedDocuments.as_view()),
24+
path('model/<str:model_id>/embed_query', views.ModelApply.EmbedQuery.as_view()),
25+
path('model/<str:model_id>/compress_documents', views.ModelApply.CompressDocuments.as_view()),
2626
]

apps/models_provider/views/model_apply.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ class EmbedDocuments(APIView):
2828
responses=DefaultModelResponse.get_response(),
2929
tags=[_('Model')] # type: ignore
3030
)
31-
@has_permissions(PermissionConstants.MODEL_READ.get_workspace_permission())
32-
def post(self, request: Request, workspace_id, model_id):
31+
def post(self, request: Request, model_id):
3332
return result.success(
3433
ModelApplySerializers(data={'model_id': model_id}).embed_documents(request.data))
3534

@@ -41,8 +40,7 @@ class EmbedQuery(APIView):
4140
responses=DefaultModelResponse.get_response(),
4241
tags=[_('Model')] # type: ignore
4342
)
44-
@has_permissions(PermissionConstants.MODEL_READ.get_workspace_permission())
45-
def post(self, request: Request, workspace_id, model_id):
43+
def post(self, request: Request, model_id):
4644
return result.success(
4745
ModelApplySerializers(data={'model_id': model_id}).embed_query(request.data))
4846

@@ -54,7 +52,6 @@ class CompressDocuments(APIView):
5452
responses=DefaultModelResponse.get_response(),
5553
tags=[_('Model')] # type: ignore
5654
)
57-
@has_permissions(PermissionConstants.MODEL_READ.get_workspace_permission())
58-
def post(self, request: Request, workspace_id, model_id):
55+
def post(self, request: Request, model_id):
5956
return result.success(
6057
ModelApplySerializers(data={'model_id': model_id}).compress_documents(request.data))

0 commit comments

Comments
 (0)