|
@@ -8,13 +8,15 @@ from controllers.inner_api.plugin.wraps import get_tenant, plugin_data
|
|
|
from controllers.inner_api.wraps import plugin_inner_api_only
|
|
|
from core.plugin.backwards_invocation.app import PluginAppBackwardsInvocation
|
|
|
from core.plugin.backwards_invocation.model import PluginModelBackwardsInvocation
|
|
|
+from core.plugin.backwards_invocation.node import PluginNodeBackwardsInvocation
|
|
|
from core.plugin.encrypt import PluginEncrypter
|
|
|
from core.plugin.entities.request import (
|
|
|
RequestInvokeApp,
|
|
|
RequestInvokeEncrypt,
|
|
|
RequestInvokeLLM,
|
|
|
RequestInvokeModeration,
|
|
|
- RequestInvokeNode,
|
|
|
+ RequestInvokeParameterExtractorNode,
|
|
|
+ RequestInvokeQuestionClassifierNode,
|
|
|
RequestInvokeRerank,
|
|
|
RequestInvokeSpeech2Text,
|
|
|
RequestInvokeTextEmbedding,
|
|
@@ -96,23 +98,46 @@ class PluginInvokeToolApi(Resource):
|
|
|
yield (
|
|
|
ToolInvokeMessage(
|
|
|
type=ToolInvokeMessage.MessageType.TEXT,
|
|
|
- message=ToolInvokeMessage.TextMessage(text='helloworld'),
|
|
|
+ message=ToolInvokeMessage.TextMessage(text="helloworld"),
|
|
|
)
|
|
|
.model_dump_json()
|
|
|
.encode()
|
|
|
- + b'\n\n'
|
|
|
+ + b"\n\n"
|
|
|
)
|
|
|
|
|
|
return compact_generate_response(generator())
|
|
|
|
|
|
|
|
|
-class PluginInvokeNodeApi(Resource):
|
|
|
+class PluginInvokeParameterExtractorNodeApi(Resource):
|
|
|
@setup_required
|
|
|
@plugin_inner_api_only
|
|
|
@get_tenant
|
|
|
- @plugin_data(payload_type=RequestInvokeNode)
|
|
|
- def post(self, user_id: str, tenant_model: Tenant, payload: RequestInvokeNode):
|
|
|
- pass
|
|
|
+ @plugin_data(payload_type=RequestInvokeParameterExtractorNode)
|
|
|
+ def post(self, user_id: str, tenant_model: Tenant, payload: RequestInvokeParameterExtractorNode):
|
|
|
+ return PluginNodeBackwardsInvocation.invoke_parameter_extractor(
|
|
|
+ tenant_id=tenant_model.id,
|
|
|
+ user_id=user_id,
|
|
|
+ parameters=payload.parameters,
|
|
|
+ model_config=payload.model,
|
|
|
+ instruction=payload.instruction,
|
|
|
+ query=payload.query,
|
|
|
+ )
|
|
|
+
|
|
|
+
|
|
|
+class PluginInvokeQuestionClassifierNodeApi(Resource):
|
|
|
+ @setup_required
|
|
|
+ @plugin_inner_api_only
|
|
|
+ @get_tenant
|
|
|
+ @plugin_data(payload_type=RequestInvokeQuestionClassifierNode)
|
|
|
+ def post(self, user_id: str, tenant_model: Tenant, payload: RequestInvokeQuestionClassifierNode):
|
|
|
+ return PluginNodeBackwardsInvocation.invoke_question_classifier(
|
|
|
+ tenant_id=tenant_model.id,
|
|
|
+ user_id=user_id,
|
|
|
+ query=payload.query,
|
|
|
+ model_config=payload.model,
|
|
|
+ classes=payload.classes,
|
|
|
+ instruction=payload.instruction,
|
|
|
+ )
|
|
|
|
|
|
|
|
|
class PluginInvokeAppApi(Resource):
|
|
@@ -127,15 +152,13 @@ class PluginInvokeAppApi(Resource):
|
|
|
tenant_id=tenant_model.id,
|
|
|
conversation_id=payload.conversation_id,
|
|
|
query=payload.query,
|
|
|
- stream=payload.response_mode == 'streaming',
|
|
|
+ stream=payload.response_mode == "streaming",
|
|
|
inputs=payload.inputs,
|
|
|
- files=payload.files
|
|
|
- )
|
|
|
-
|
|
|
- return compact_generate_response(
|
|
|
- PluginAppBackwardsInvocation.convert_to_event_stream(response)
|
|
|
+ files=payload.files,
|
|
|
)
|
|
|
|
|
|
+ return compact_generate_response(PluginAppBackwardsInvocation.convert_to_event_stream(response))
|
|
|
+
|
|
|
|
|
|
class PluginInvokeEncryptApi(Resource):
|
|
|
@setup_required
|
|
@@ -149,13 +172,14 @@ class PluginInvokeEncryptApi(Resource):
|
|
|
return PluginEncrypter.invoke_encrypt(tenant_model, payload)
|
|
|
|
|
|
|
|
|
-api.add_resource(PluginInvokeLLMApi, '/invoke/llm')
|
|
|
-api.add_resource(PluginInvokeTextEmbeddingApi, '/invoke/text-embedding')
|
|
|
-api.add_resource(PluginInvokeRerankApi, '/invoke/rerank')
|
|
|
-api.add_resource(PluginInvokeTTSApi, '/invoke/tts')
|
|
|
-api.add_resource(PluginInvokeSpeech2TextApi, '/invoke/speech2text')
|
|
|
-api.add_resource(PluginInvokeModerationApi, '/invoke/moderation')
|
|
|
-api.add_resource(PluginInvokeToolApi, '/invoke/tool')
|
|
|
-api.add_resource(PluginInvokeNodeApi, '/invoke/node')
|
|
|
-api.add_resource(PluginInvokeAppApi, '/invoke/app')
|
|
|
-api.add_resource(PluginInvokeEncryptApi, '/invoke/encrypt')
|
|
|
+api.add_resource(PluginInvokeLLMApi, "/invoke/llm")
|
|
|
+api.add_resource(PluginInvokeTextEmbeddingApi, "/invoke/text-embedding")
|
|
|
+api.add_resource(PluginInvokeRerankApi, "/invoke/rerank")
|
|
|
+api.add_resource(PluginInvokeTTSApi, "/invoke/tts")
|
|
|
+api.add_resource(PluginInvokeSpeech2TextApi, "/invoke/speech2text")
|
|
|
+api.add_resource(PluginInvokeModerationApi, "/invoke/moderation")
|
|
|
+api.add_resource(PluginInvokeToolApi, "/invoke/tool")
|
|
|
+api.add_resource(PluginInvokeParameterExtractorNodeApi, "/invoke/parameter-extractor")
|
|
|
+api.add_resource(PluginInvokeQuestionClassifierNodeApi, "/invoke/question-classifier")
|
|
|
+api.add_resource(PluginInvokeAppApi, "/invoke/app")
|
|
|
+api.add_resource(PluginInvokeEncryptApi, "/invoke/encrypt")
|