Skip to content

Commit 04fe076

Browse files
docs(api): updates to API spec
1 parent 74b4799 commit 04fe076

9 files changed

Lines changed: 92 additions & 18 deletions

File tree

‎.stats.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 33
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/writerai%2Fwriter-4ec783072dd7f57c6e021a746df7650fb8d7a164d8ec25c7d5cab06c33bc114f.yml
3-
openapi_spec_hash: ceab065d515f3681b0c33137da308968
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/writerai%2Fwriter-ea6ec4b34f6b7fdecc564f59b2e31482eee05830bf8dc1f389461b158de1548e.yml
3+
openapi_spec_hash: ea89c1faed473908be2740efe6da255f
44
config_hash: 886645f89dc98f04b8931eaf02854e5f

‎src/writerai/resources/files.py‎

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import httpx
88

9-
from ..types import file_list_params, file_retry_params
9+
from ..types import file_list_params, file_retry_params, file_upload_params
1010
from .._types import Body, Omit, Query, Headers, NotGiven, FileTypes, SequenceNotStr, omit, not_given
1111
from .._utils import maybe_transform, async_maybe_transform
1212
from .._compat import cached_property
@@ -274,6 +274,7 @@ def upload(
274274
content: FileTypes,
275275
content_disposition: str,
276276
content_type: str,
277+
graph_id: str | Omit = omit,
277278
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
278279
# The extra values given here take precedence over values defined on the client or passed to this method.
279280
extra_headers: Headers | None = None,
@@ -287,6 +288,13 @@ def upload(
287288
DOC, DOCX, PPT, PPTX, JPG, PNG, EML, HTML, SRT, CSV, XLS, and XLSX.
288289
289290
Args:
291+
graph_id: The unique identifier of the Knowledge Graph to associate the uploaded file
292+
with.
293+
294+
Note: The response from the upload endpoint does not include the `graphId`
295+
field, but the association will be visible when you retrieve the file using the
296+
file retrieval endpoint.
297+
290298
extra_headers: Send extra headers
291299
292300
extra_query: Add additional query parameters to the request
@@ -303,7 +311,11 @@ def upload(
303311
return self._post(
304312
"/v1/files",
305313
options=make_request_options(
306-
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
314+
extra_headers=extra_headers,
315+
extra_query=extra_query,
316+
extra_body=extra_body,
317+
timeout=timeout,
318+
query=maybe_transform({"graph_id": graph_id}, file_upload_params.FileUploadParams),
307319
),
308320
binary_request=content,
309321
cast_to=File,
@@ -550,6 +562,7 @@ async def upload(
550562
content: FileTypes,
551563
content_disposition: str,
552564
content_type: str,
565+
graph_id: str | Omit = omit,
553566
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
554567
# The extra values given here take precedence over values defined on the client or passed to this method.
555568
extra_headers: Headers | None = None,
@@ -563,6 +576,13 @@ async def upload(
563576
DOC, DOCX, PPT, PPTX, JPG, PNG, EML, HTML, SRT, CSV, XLS, and XLSX.
564577
565578
Args:
579+
graph_id: The unique identifier of the Knowledge Graph to associate the uploaded file
580+
with.
581+
582+
Note: The response from the upload endpoint does not include the `graphId`
583+
field, but the association will be visible when you retrieve the file using the
584+
file retrieval endpoint.
585+
566586
extra_headers: Send extra headers
567587
568588
extra_query: Add additional query parameters to the request
@@ -579,7 +599,11 @@ async def upload(
579599
return await self._post(
580600
"/v1/files",
581601
options=make_request_options(
582-
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
602+
extra_headers=extra_headers,
603+
extra_query=extra_query,
604+
extra_body=extra_body,
605+
timeout=timeout,
606+
query=await async_maybe_transform({"graph_id": graph_id}, file_upload_params.FileUploadParams),
583607
),
584608
binary_request=content,
585609
cast_to=File,

‎src/writerai/resources/vision.py‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@ def analyze(
5757
extra_body: Body | None = None,
5858
timeout: float | httpx.Timeout | None | NotGiven = not_given,
5959
) -> VisionResponse:
60-
"""
61-
Submit images and a prompt to generate an analysis of the images.
60+
"""Submit images and documents with a prompt to generate an analysis.
61+
62+
Supports JPG,
63+
PNG, PDF, and TXT files up to 7MB each.
6264
6365
Args:
6466
model: The model to use for image analysis.
@@ -125,8 +127,10 @@ async def analyze(
125127
extra_body: Body | None = None,
126128
timeout: float | httpx.Timeout | None | NotGiven = not_given,
127129
) -> VisionResponse:
128-
"""
129-
Submit images and a prompt to generate an analysis of the images.
130+
"""Submit images and documents with a prompt to generate an analysis.
131+
132+
Supports JPG,
133+
PNG, PDF, and TXT files up to 7MB each.
130134
131135
Args:
132136
model: The model to use for image analysis.

‎src/writerai/types/file.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ class File(BaseModel):
1616
"""The timestamp when the file was uploaded."""
1717

1818
graph_ids: List[str]
19-
"""A list of Knowledge Graph IDs that the file is associated with."""
19+
"""A list of Knowledge Graph IDs that the file is associated with.
20+
21+
If you provided a `graphId` during upload, the file is associated with that
22+
Knowledge Graph. However, the `graph_ids` field in the upload response is an
23+
empty list. The association will be visible in the `graph_ids` list when you
24+
retrieve the file using the file retrieval endpoint.
25+
"""
2026

2127
name: str
2228
"""The name of the file."""

‎src/writerai/types/file_upload_params.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,13 @@ class FileUploadParams(TypedDict, total=False):
1616
content_disposition: Required[Annotated[str, PropertyInfo(alias="Content-Disposition")]]
1717

1818
content_type: Required[Annotated[str, PropertyInfo(alias="Content-Type")]]
19+
20+
graph_id: Annotated[str, PropertyInfo(alias="graphId")]
21+
"""
22+
The unique identifier of the Knowledge Graph to associate the uploaded file
23+
with.
24+
25+
Note: The response from the upload endpoint does not include the `graphId`
26+
field, but the association will be visible when you retrieve the file using the
27+
file retrieval endpoint.
28+
"""

‎src/writerai/types/shared/tool_param.py‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,11 @@ class TranslationTool(BaseModel):
203203

204204
class VisionToolFunctionVariable(BaseModel):
205205
file_id: str
206-
"""The File ID of the image to analyze.
206+
"""The File ID of the file to analyze.
207207
208208
The file must be uploaded to the Writer platform before you use it with the
209-
Vision tool. The maximum allowed file size is 7MB.
209+
Vision tool. Supported file types: JPG, PNG, PDF, TXT. The maximum allowed file
210+
size is 7MB.
210211
"""
211212

212213
name: str
@@ -228,7 +229,10 @@ class VisionToolFunction(BaseModel):
228229

229230
class VisionTool(BaseModel):
230231
function: VisionToolFunction
231-
"""A tool that uses Palmyra Vision to analyze images."""
232+
"""A tool that uses Palmyra Vision to analyze images and documents.
233+
234+
Supports JPG, PNG, PDF, and TXT files up to 7MB each.
235+
"""
232236

233237
type: Literal["vision"]
234238
"""The type of tool."""

‎src/writerai/types/shared_params/tool_param.py‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,11 @@ class TranslationTool(TypedDict, total=False):
204204

205205
class VisionToolFunctionVariable(TypedDict, total=False):
206206
file_id: Required[str]
207-
"""The File ID of the image to analyze.
207+
"""The File ID of the file to analyze.
208208
209209
The file must be uploaded to the Writer platform before you use it with the
210-
Vision tool. The maximum allowed file size is 7MB.
210+
Vision tool. Supported file types: JPG, PNG, PDF, TXT. The maximum allowed file
211+
size is 7MB.
211212
"""
212213

213214
name: Required[str]
@@ -229,7 +230,10 @@ class VisionToolFunction(TypedDict, total=False):
229230

230231
class VisionTool(TypedDict, total=False):
231232
function: Required[VisionToolFunction]
232-
"""A tool that uses Palmyra Vision to analyze images."""
233+
"""A tool that uses Palmyra Vision to analyze images and documents.
234+
235+
Supports JPG, PNG, PDF, and TXT files up to 7MB each.
236+
"""
233237

234238
type: Required[Literal["vision"]]
235239
"""The type of tool."""

‎src/writerai/types/vision_analyze_params.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ class VisionAnalyzeParams(TypedDict, total=False):
2525

2626
class Variable(TypedDict, total=False):
2727
file_id: Required[str]
28-
"""The File ID of the image to analyze.
28+
"""The File ID of the file to analyze.
2929
3030
The file must be uploaded to the Writer platform before it can be used in a
31-
vision request.
31+
vision request. Supported file types: JPG, PNG, PDF, TXT (max 7MB each).
3232
"""
3333

3434
name: Required[str]

‎tests/api_resources/test_files.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,17 @@ def test_method_upload(self, client: Writer) -> None:
239239
)
240240
assert_matches_type(File, file, path=["response"])
241241

242+
@pytest.mark.skip(reason="requests with binary data not yet supported in test environment")
243+
@parametrize
244+
def test_method_upload_with_all_params(self, client: Writer) -> None:
245+
file = client.files.upload(
246+
content=b"raw file contents",
247+
content_disposition="Content-Disposition",
248+
content_type="Content-Type",
249+
graph_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
250+
)
251+
assert_matches_type(File, file, path=["response"])
252+
242253
@pytest.mark.skip(reason="requests with binary data not yet supported in test environment")
243254
@parametrize
244255
def test_raw_response_upload(self, client: Writer) -> None:
@@ -484,6 +495,17 @@ async def test_method_upload(self, async_client: AsyncWriter) -> None:
484495
)
485496
assert_matches_type(File, file, path=["response"])
486497

498+
@pytest.mark.skip(reason="requests with binary data not yet supported in test environment")
499+
@parametrize
500+
async def test_method_upload_with_all_params(self, async_client: AsyncWriter) -> None:
501+
file = await async_client.files.upload(
502+
content=b"raw file contents",
503+
content_disposition="Content-Disposition",
504+
content_type="Content-Type",
505+
graph_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
506+
)
507+
assert_matches_type(File, file, path=["response"])
508+
487509
@pytest.mark.skip(reason="requests with binary data not yet supported in test environment")
488510
@parametrize
489511
async def test_raw_response_upload(self, async_client: AsyncWriter) -> None:

0 commit comments

Comments
 (0)