From 47d4b7901e2e8f8bb9c197cb0bb6f4138a67cfde Mon Sep 17 00:00:00 2001 From: ideoutrea Date: Wed, 20 Mar 2024 15:31:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9detail=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/console/agent_builder/README.md | 34 +++++++++++-------- .../console/agent_builder/agent_builder.py | 1 - .../core/console/agent_builder/model.py | 28 +++++++++++++-- 3 files changed, 46 insertions(+), 17 deletions(-) diff --git a/appbuilder/core/console/agent_builder/README.md b/appbuilder/core/console/agent_builder/README.md index 58585f680..c2d7298d2 100644 --- a/appbuilder/core/console/agent_builder/README.md +++ b/appbuilder/core/console/agent_builder/README.md @@ -66,20 +66,20 @@ os.environ["APPBUILDER_TOKEN"] = "bce-YOURTOKEN" ### 非流式返回 -| 参数名称 | 参数类型 | 描述 | 示例值 | -|----------------|--------------------|------------------|------------------------------------------------------------------| -| content | AgentBuilderAnswer | 对话返回结果 | | -| +code | Int | 错误码,0代码成功,非0表示失败 | 0 | -| +message | String | 错误具体消息 | | -| +answer | String | 智能体返回的回答 | | -| +events | List[Event] | 事件列表 | | -| +events[0] | Event | 具体事件内容 | | -| ++code | String | 错误码 | | -| ++message | String | 错误具体消息 | | -| ++status | String | 事件状态 | 状态描述,preparing(准备运行)running(运行中)error(执行错误) done(执行完成) | -| ++event_type | String | 事件类型 | | -| ++content_type | String | 内容类型 | 可选值包括:code text, image, status,image, function_call, rag, audio等 | -| ++detail | Dict | 事件输出详情 | 代码解释器、文生图、工具组件等的详细输出内容 | +| 参数名称 | 参数类型 | 描述 | 示例值 | +|----------------|--------------------|------------------|------------------------------------------------------------------------| +| content | AgentBuilderAnswer | 对话返回结果 | | +| +code | Int | 错误码,0代码成功,非0表示失败 | 0 | +| +message | String | 错误具体消息 | | +| +answer | String | 智能体返回的回答 | | +| +events | List[Event] | 事件列表 | | +| +events[0] | Event | 具体事件内容 | | +| ++code | String | 错误码 | | +| ++message | String | 错误具体消息 | | +| ++status | String | 事件状态 | 状态描述,preparing(准备运行)running(运行中)error(执行错误) done(执行完成) | +| ++event_type | String | 事件类型 | | +| ++content_type | String | 内容类型 | 可选值包括:code text, image, status,image, function_call, rag, audio、video等 | +| ++detail | Dict | 事件输出详情 | 代码解释器、文生图、工具组件等的详细输出内容 | ### 流式返回 @@ -141,6 +141,12 @@ for content in message.content: elif content_type == "function_call": function_call_detail = FunctionCallDetail(**detail) print(function_call_detail.video) + elif content_type == "audio": + audio_detail = AudioDetail(**detail) + print(audio_detail) + elif content_type == "video": + video_detail = VideoDetail(**detail) + print(video_detail) elif content_type == "status": StatusDetail(**detail) else: diff --git a/appbuilder/core/console/agent_builder/agent_builder.py b/appbuilder/core/console/agent_builder/agent_builder.py index 17328ad91..0179ccaa2 100644 --- a/appbuilder/core/console/agent_builder/agent_builder.py +++ b/appbuilder/core/console/agent_builder/agent_builder.py @@ -125,7 +125,6 @@ def run(self, conversation_id: str, request_id = self.http_client.response_request_id(response) if stream: client = SSEClient(response) - return Message(content=self._iterate_events(request_id, client.events())) else: data = response.json() diff --git a/appbuilder/core/console/agent_builder/model.py b/appbuilder/core/console/agent_builder/model.py index 81e746113..7b7e6df32 100644 --- a/appbuilder/core/console/agent_builder/model.py +++ b/appbuilder/core/console/agent_builder/model.py @@ -56,6 +56,7 @@ class Result(BaseModel): is_completion: Union[bool, None] = "" content: list[OriginalEvent] = [] + class HTTPResponse(BaseModel): """会话请求参数 属性: @@ -118,7 +119,6 @@ class FunctionCallDetail(BaseModel): """content_type=function_call,详情内容 属性: text(str): 文本详情 - references(list[dict]): 引用详情 """ text: Union[str, dict] = "" image: str = "" @@ -126,6 +126,30 @@ class FunctionCallDetail(BaseModel): video: str = "" +class ImageDetail(BaseModel): + """content_type=function_call,详情内容 + 属性: + image(str): 图片下载地址 + """ + image: str = "" + + +class AudioDetail(BaseModel): + """content_type=audio,详情内容 + 属性: + image(str): 音频下载地址 + """ + audio: str = "" + + +class VideoDetail(BaseModel): + """content_type=video,详情内容 + 属性: + vidoe(str): 视频下载地址 + """ + video: str = "" + + class StatusDetail(BaseModel): pass @@ -203,4 +227,4 @@ class CreateConversationResponse(BaseModel): """ code: int = 0 message: str = "" - result: CreateConversationResult = CreateConversationResult() \ No newline at end of file + result: CreateConversationResult = CreateConversationResult()