|
22 | 22 | make_request_options |
23 | 23 | ) |
24 | 24 |
|
25 | | -from zai.types.file_parser.file_parser_create_params import FileParserCreateParams |
26 | | -from zai.types.file_parser.file_parser_resp import FileParserTaskCreateResp |
| 25 | +from zai.types.file_parser.file_parser_create_params import FileParserCreateParams,FileParserSyncParams |
| 26 | +from zai.types.file_parser.file_parser_resp import FileParserTaskCreateResp,FileParsingDownloadResp |
27 | 27 |
|
28 | 28 | if TYPE_CHECKING: |
29 | 29 | from zai._client import ZaiClient |
@@ -103,3 +103,41 @@ def content( |
103 | 103 | cast_type=_legacy_binary_response.HttpxBinaryResponseContent, |
104 | 104 | ) |
105 | 105 | return httpxBinaryResponseContent.response |
| 106 | + |
| 107 | + |
| 108 | + def create_sync( |
| 109 | + self, |
| 110 | + *, |
| 111 | + file: FileTypes = None, |
| 112 | + file_type: str = None, |
| 113 | + tool_type: Literal["prime-sync"], |
| 114 | + extra_headers: Headers | None = None, |
| 115 | + extra_body: Body | None = None, |
| 116 | + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, |
| 117 | + ) -> FileParsingDownloadResp: |
| 118 | + |
| 119 | + if not file: |
| 120 | + raise ValueError("At least one `file` must be provided.") |
| 121 | + body = deepcopy_minimal( |
| 122 | + { |
| 123 | + "file": file, |
| 124 | + "file_type": file_type, |
| 125 | + "tool_type": tool_type, |
| 126 | + } |
| 127 | + ) |
| 128 | + |
| 129 | + files = extract_files(cast(Mapping[str, object], body), paths=[["file"]]) |
| 130 | + if files: |
| 131 | + # It should be noted that the actual Content-Type header that will be |
| 132 | + # sent to the server will contain a `boundary` parameter, e.g. |
| 133 | + # multipart/form-data; boundary=---abc-- |
| 134 | + extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})} |
| 135 | + return self._post( |
| 136 | + "/files/parser/sync", |
| 137 | + body=maybe_transform(body, FileParserSyncParams), |
| 138 | + files=files, |
| 139 | + options=make_request_options( |
| 140 | + extra_headers=extra_headers, extra_body=extra_body, timeout=timeout |
| 141 | + ), |
| 142 | + cast_type=FileParsingDownloadResp, |
| 143 | + ) |
0 commit comments