Skip to content

Commit 84f10b0

Browse files
liyuxuan-bdyiguang
authored andcommitted
feat: add response api
1 parent 66e243f commit 84f10b0

32 files changed

+842
-57
lines changed

volcenginesdkarkruntime/resources/example.py

Lines changed: 0 additions & 45 deletions
This file was deleted.

volcenginesdkarkruntime/resources/images/images.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ def generate(
5959
- disabled: Disables multi-image; the model generates only a single image
6060
"""
6161

62-
6362
@overload
6463
def generate(
6564
self,
@@ -140,7 +139,10 @@ def generate(
140139
"watermark": watermark,
141140
"optimize_prompt": optimize_prompt,
142141
"sequential_image_generation": sequential_image_generation,
143-
"sequential_image_generation_options": sequential_image_generation_options.model_dump(mode='json'),
142+
"sequential_image_generation_options": (
143+
sequential_image_generation_options.model_dump(mode="json")
144+
if sequential_image_generation_options is not None else None
145+
),
144146
"stream": stream,
145147
},
146148
options=make_request_options(
@@ -261,7 +263,11 @@ async def generate(
261263
"watermark": watermark,
262264
"optimize_prompt": optimize_prompt,
263265
"sequential_image_generation": sequential_image_generation,
264-
"sequential_image_generation_options": sequential_image_generation_options,
266+
"sequential_image_generation_options": (
267+
sequential_image_generation_options.model_dump(mode="json")
268+
if sequential_image_generation_options is not None else None
269+
),
270+
"stream": stream,
265271
},
266272
options=make_request_options(
267273
extra_headers=extra_headers,

volcenginesdkarkruntime/types/images/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
from .images import SequentialImageGenerationOptions, ImagesResponse
1414

1515

16-
__all__ = ["SequentialImageGenerationOptions","ImagesResponse"]
16+
__all__ = ["SequentialImageGenerationOptions", "ImagesResponse"]

volcenginesdkarkruntime/types/images/image_gen_completed_event.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class Usage(BaseModel):
2525
total_tokens: int
2626
"""The total number of tokens."""
2727

28+
2829
class Error(BaseModel):
2930
message: str
3031
"""The reason for failed image generation"""

volcenginesdkarkruntime/types/images/image_gen_generating_event.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
__all__ = ["ImageGenGeneratingEvent"]
2020

21+
2122
class Error(BaseModel):
2223
message: str
2324
"""The reason for failed image generation"""

volcenginesdkarkruntime/types/images/image_gen_stream_event.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from volcenginesdkarkruntime._utils import PropertyInfo
1717
from .image_gen_completed_event import ImageGenCompletedEvent
18-
from .image_gen_generating_event import ImageGenGeneratingEvent
18+
from .image_gen_generating_event import ImageGenGeneratingEvent
1919

2020
__all__ = ["ImageGenStreamEvent"]
2121

volcenginesdkarkruntime/types/images/images.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
__all__ = ["SequentialImageGenerationOptions", "ImagesResponse"]
1818

19+
1920
class SequentialImageGenerationOptions(BaseModel):
2021
max_images: Optional[int] = None
2122
""" Maximum number of images to generate in this request; effective only when the multi-image feature is enabled """
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
2+
# Copyright (c) [2025] [OpenAI]
3+
# Copyright (c) [2025] [ByteDance Ltd. and/or its affiliates.]
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# This file has been modified by [ByteDance Ltd. and/or its affiliates.] on 2025.7
7+
#
8+
# Original file was released under Apache License Version 2.0, with the full license text
9+
# available at https://github.com/openai/openai-python/blob/main/LICENSE.
10+
#
11+
# This modified file is released under the same license.
12+
13+
from typing_extensions import TypedDict, Required, Optional, Iterable, Literal
14+
15+
__all__ = [
16+
"McpListTools",
17+
"McpListToolsTool",
18+
"McpApprovalRequest",
19+
"McpApprovalResponse",
20+
"McpCall",
21+
]
22+
23+
24+
class McpListToolsTool(TypedDict, total=False):
25+
input_schema: Required[object]
26+
"""The JSON schema describing the tool's input."""
27+
28+
name: Required[str]
29+
"""The name of the tool."""
30+
31+
annotations: Optional[object]
32+
"""Additional annotations about the tool."""
33+
34+
description: Optional[str]
35+
"""The description of the tool."""
36+
37+
38+
class McpListTools(TypedDict, total=False):
39+
id: Required[str]
40+
"""The unique ID of the list."""
41+
42+
server_label: Required[str]
43+
"""The label of the MCP server."""
44+
45+
tools: Required[Iterable[McpListToolsTool]]
46+
"""The tools available on the server."""
47+
48+
type: Required[Literal["mcp_list_tools"]]
49+
"""The type of the item. Always `mcp_list_tools`."""
50+
51+
error: Optional[str]
52+
"""Error message if the server could not list tools."""
53+
54+
55+
class McpApprovalRequest(TypedDict, total=False):
56+
id: Required[str]
57+
"""The unique ID of the approval request."""
58+
59+
arguments: Required[str]
60+
"""A JSON string of arguments for the tool."""
61+
62+
name: Required[str]
63+
"""The name of the tool to run."""
64+
65+
server_label: Required[str]
66+
"""The label of the MCP server making the request."""
67+
68+
type: Required[Literal["mcp_approval_request"]]
69+
"""The type of the item. Always `mcp_approval_request`."""
70+
71+
72+
class McpApprovalResponse(TypedDict, total=False):
73+
approval_request_id: Required[str]
74+
"""The ID of the approval request being answered."""
75+
76+
approve: Required[bool]
77+
"""Whether the request was approved."""
78+
79+
type: Required[Literal["mcp_approval_response"]]
80+
"""The type of the item. Always `mcp_approval_response`."""
81+
82+
id: Optional[str]
83+
"""The unique ID of the approval response"""
84+
85+
reason: Optional[str]
86+
"""Optional reason for the decision."""
87+
88+
89+
class McpCall(TypedDict, total=False):
90+
id: Required[str]
91+
"""The unique ID of the tool call."""
92+
93+
arguments: Required[str]
94+
"""A JSON string of the arguments passed to the tool."""
95+
96+
name: Required[str]
97+
"""The name of the tool that was run."""
98+
99+
server_label: Required[str]
100+
"""The label of the MCP server running the tool."""
101+
102+
type: Required[Literal["mcp_call"]]
103+
"""The type of the item. Always `mcp_call`."""
104+
105+
error: Optional[str]
106+
"""The error from the tool call, if any."""
107+
108+
output: Optional[str]
109+
"""The output from the tool call."""
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
2+
# Copyright (c) [2025] [OpenAI]
3+
# Copyright (c) [2025] [ByteDance Ltd. and/or its affiliates.]
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# This file has been modified by [ByteDance Ltd. and/or its affiliates.] on 2025.7
7+
#
8+
# Original file was released under Apache License Version 2.0, with the full license text
9+
# available at https://github.com/openai/openai-python/blob/main/LICENSE.
10+
#
11+
# This modified file is released under the same license.
12+
13+
from typing_extensions import Literal, Optional, Dict, TypeAlias, Union, List
14+
15+
from ..._models import BaseModel
16+
17+
18+
__all__ = [
19+
"Mcp",
20+
"McpAllowedTools",
21+
"McpAllowedToolsMcpAllowedToolsFilter",
22+
"McpRequireApproval",
23+
"McpRequireApprovalMcpToolApprovalFilter",
24+
"McpRequireApprovalMcpToolApprovalFilterAlways",
25+
"McpRequireApprovalMcpToolApprovalFilterNever",
26+
]
27+
28+
29+
class McpAllowedToolsMcpAllowedToolsFilter(BaseModel):
30+
tool_names: Optional[List[str]] = None
31+
"""List of allowed tool names."""
32+
33+
34+
class McpRequireApprovalMcpToolApprovalFilterAlways(BaseModel):
35+
tool_names: Optional[List[str]] = None
36+
"""List of tools that require approval."""
37+
38+
39+
class McpRequireApprovalMcpToolApprovalFilterNever(BaseModel):
40+
tool_names: Optional[List[str]] = None
41+
"""List of tools that do not require approval."""
42+
43+
44+
class McpRequireApprovalMcpToolApprovalFilter(BaseModel):
45+
always: Optional[McpRequireApprovalMcpToolApprovalFilterAlways] = None
46+
"""A list of tools that always require approval."""
47+
48+
never: Optional[McpRequireApprovalMcpToolApprovalFilterNever] = None
49+
"""A list of tools that never require approval."""
50+
51+
52+
McpAllowedTools: TypeAlias = Union[List[str], McpAllowedToolsMcpAllowedToolsFilter, None]
53+
54+
McpRequireApproval: TypeAlias = Union[McpRequireApprovalMcpToolApprovalFilter, Literal["always", "never"], None]
55+
56+
57+
class Mcp(BaseModel):
58+
server_label: str
59+
"""A label for this MCP server, used to identify it in tool calls."""
60+
61+
server_url: str
62+
"""The URL for the MCP server."""
63+
64+
type: Literal["mcp"]
65+
"""The type of the MCP tool. Always `mcp`."""
66+
67+
allowed_tools: Optional[McpAllowedTools] = None
68+
"""List of allowed tool names or a filter object."""
69+
70+
headers: Optional[Dict[str, str]] = None
71+
"""Optional HTTP headers to send to the MCP server.
72+
73+
Use for authentication or other purposes.
74+
"""
75+
76+
require_approval: Optional[McpRequireApproval] = None
77+
"""Specify which of the MCP server's tools require approval."""
78+
79+
server_description: Optional[str] = None
80+
"""Optional description of the MCP server, used to provide more context."""
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
2+
# Copyright (c) [2025] [OpenAI]
3+
# Copyright (c) [2025] [ByteDance Ltd. and/or its affiliates.]
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# This file has been modified by [ByteDance Ltd. and/or its affiliates.] on 2025.7
7+
#
8+
# Original file was released under Apache License Version 2.0, with the full license text
9+
# available at https://github.com/openai/openai-python/blob/main/LICENSE.
10+
#
11+
# This modified file is released under the same license.
12+
13+
from typing_extensions import Literal, TypedDict, Required, Optional, Dict, TypeAlias, Union, List
14+
15+
__all__ = [
16+
"Mcp",
17+
"McpAllowedTools",
18+
"McpAllowedToolsMcpAllowedToolsFilter",
19+
"McpRequireApproval",
20+
"McpRequireApprovalMcpToolApprovalFilter",
21+
"McpRequireApprovalMcpToolApprovalFilterAlways",
22+
"McpRequireApprovalMcpToolApprovalFilterNever",
23+
]
24+
25+
26+
class McpAllowedToolsMcpAllowedToolsFilter(TypedDict, total=False):
27+
tool_names: List[str]
28+
"""List of allowed tool names."""
29+
30+
31+
class McpRequireApprovalMcpToolApprovalFilterAlways(TypedDict, total=False):
32+
tool_names: List[str]
33+
"""List of tools that require approval."""
34+
35+
36+
class McpRequireApprovalMcpToolApprovalFilterNever(TypedDict, total=False):
37+
tool_names: List[str]
38+
"""List of tools that do not require approval."""
39+
40+
41+
class McpRequireApprovalMcpToolApprovalFilter(TypedDict, total=False):
42+
always: McpRequireApprovalMcpToolApprovalFilterAlways
43+
"""A list of tools that always require approval."""
44+
45+
never: McpRequireApprovalMcpToolApprovalFilterNever
46+
"""A list of tools that never require approval."""
47+
48+
49+
McpAllowedTools: TypeAlias = Union[List[str], McpAllowedToolsMcpAllowedToolsFilter]
50+
51+
52+
McpRequireApproval: TypeAlias = Union[McpRequireApprovalMcpToolApprovalFilter, Literal["always", "never"]]
53+
54+
55+
class Mcp(TypedDict, total=False):
56+
server_label: Required[str]
57+
"""A label for this MCP server, used to identify it in tool calls."""
58+
59+
server_url: Required[str]
60+
"""The URL for the MCP server."""
61+
62+
type: Required[Literal["mcp"]]
63+
"""The type of the MCP tool. Always `mcp`."""
64+
65+
allowed_tools: Optional[McpAllowedTools]
66+
"""List of allowed tool names or a filter object."""
67+
68+
headers: Optional[Dict[str, str]]
69+
"""Optional HTTP headers to send to the MCP server.
70+
71+
Use for authentication or other purposes.
72+
"""
73+
74+
require_approval: Optional[McpRequireApproval]
75+
"""Specify which of the MCP server's tools require approval."""
76+
77+
server_description: str
78+
"""Optional description of the MCP server, used to provide more context."""

0 commit comments

Comments
 (0)