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
27
apps/common/sql/list_embedding_text.sql
Normal file
27
apps/common/sql/list_embedding_text.sql
Normal file
@ -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':
|
if os.environ.get('SERVER_NAME', 'web') == 'local_model':
|
||||||
urlpatterns += [
|
urlpatterns += [
|
||||||
path('workspace/<str:workspace_id>/model/<str:model_id>/embed_documents', views.ModelApply.EmbedDocuments.as_view()),
|
path('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('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>/compress_documents', views.ModelApply.CompressDocuments.as_view()),
|
||||||
]
|
]
|
||||||
|
|||||||
@ -28,8 +28,7 @@ class ModelApply(APIView):
|
|||||||
responses=DefaultModelResponse.get_response(),
|
responses=DefaultModelResponse.get_response(),
|
||||||
tags=[_('Model')] # type: ignore
|
tags=[_('Model')] # type: ignore
|
||||||
)
|
)
|
||||||
@has_permissions(PermissionConstants.MODEL_READ.get_workspace_permission())
|
def post(self, request: Request, model_id):
|
||||||
def post(self, request: Request, workspace_id, model_id):
|
|
||||||
return result.success(
|
return result.success(
|
||||||
ModelApplySerializers(data={'model_id': model_id}).embed_documents(request.data))
|
ModelApplySerializers(data={'model_id': model_id}).embed_documents(request.data))
|
||||||
|
|
||||||
@ -41,8 +40,7 @@ class ModelApply(APIView):
|
|||||||
responses=DefaultModelResponse.get_response(),
|
responses=DefaultModelResponse.get_response(),
|
||||||
tags=[_('Model')] # type: ignore
|
tags=[_('Model')] # type: ignore
|
||||||
)
|
)
|
||||||
@has_permissions(PermissionConstants.MODEL_READ.get_workspace_permission())
|
def post(self, request: Request, model_id):
|
||||||
def post(self, request: Request, workspace_id, model_id):
|
|
||||||
return result.success(
|
return result.success(
|
||||||
ModelApplySerializers(data={'model_id': model_id}).embed_query(request.data))
|
ModelApplySerializers(data={'model_id': model_id}).embed_query(request.data))
|
||||||
|
|
||||||
@ -54,7 +52,6 @@ class ModelApply(APIView):
|
|||||||
responses=DefaultModelResponse.get_response(),
|
responses=DefaultModelResponse.get_response(),
|
||||||
tags=[_('Model')] # type: ignore
|
tags=[_('Model')] # type: ignore
|
||||||
)
|
)
|
||||||
@has_permissions(PermissionConstants.MODEL_READ.get_workspace_permission())
|
def post(self, request: Request, model_id):
|
||||||
def post(self, request: Request, workspace_id, model_id):
|
|
||||||
return result.success(
|
return result.success(
|
||||||
ModelApplySerializers(data={'model_id': model_id}).compress_documents(request.data))
|
ModelApplySerializers(data={'model_id': model_id}).compress_documents(request.data))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user