Reverse Invocation App¶
Note: ⚠️ 本文档由 AI 自动翻译。如有任何不准确之处,请参考英文原版。
反向调用应用意味着插件可以访问 FlexAI 内应用的数据。此模块支持流式和非流式应用调用。如果你不熟悉反向调用的基本概念,请先阅读反向调用 FlexAI 服务。
接口类型:
- 对于
Chatbot/Agent/Chatflow类型的应用,它们都是基于对话的应用,因此共享相同的输入和输出参数类型。因此,它们可以统一视为 Chat 接口。 - 对于工作流应用,它们占用单独的工作流接口。
- 对于 Completion(文本生成应用)应用,它们占用单独的 Completion 接口。
请注意,插件只允许访问插件所在工作空间内的应用。
调用 Chat 接口¶
入口点¶
接口规范¶
def invoke(
self,
app_id: str,
inputs: dict,
response_mode: Literal["streaming", "blocking"],
conversation_id: str,
files: list,
) -> Generator[dict, None, None] | dict:
pass
当 response_mode 为 streaming 时,此接口将直接返回 Generator[dict]。否则,返回 dict。有关具体接口字段,请参阅 ServiceApi 的返回结果。
使用场景¶
我们可以在 Endpoint 内调用 Chat 类型的应用并直接返回结果。
from typing import Mapping
from werkzeug import Request, Response
from flexai_plugin import Endpoint
class Duck(Endpoint):
def _invoke(self, r: Request, values: Mapping, settings: Mapping) -> Response:
"""
Invokes the endpoint with the given request.
"""
app_id = values["app_id"]
def generator():
# Note: The original example incorrectly called self.session.app.workflow.invoke
# It should call self.session.app.chat.invoke for a chat app.
# Assuming a chat app is intended here based on the section title.
response = self.session.app.chat.invoke(
app_id=app_id,
inputs={}, # Provide actual inputs as needed
response_mode="streaming",
conversation_id="some-conversation-id", # Provide a conversation ID if needed
files=[]
)
for data in response:
yield f"{json.dumps(data)} <br>"
return Response(generator(), status=200, content_type="text/html")
调用工作流接口¶
入口点¶
接口规范¶
def invoke(
self,
app_id: str,
inputs: dict,
response_mode: Literal["streaming", "blocking"],
files: list,
) -> Generator[dict, None, None] | dict:
pass
调用 Completion 接口¶
入口点¶
接口规范
def invoke(
self,
app_id: str,
inputs: dict,
response_mode: Literal["streaming", "blocking"],
files: list,
) -> Generator[dict, None, None] | dict:
pass
相关资源¶
- 反向调用 FlexAI 服务 - 了解反向调用的基本概念
- 反向调用模型 - 学习如何调用平台内的模型能力
- 反向调用工具 - 学习如何调用其他插件
- 开发 Slack Bot 插件 - 使用反向调用的实际应用案例
- 开发扩展插件 - 学习如何开发扩展插件
{/ Contributing Section DO NOT edit this section! It will be automatically generated by the script. /}