Skip to content

Commit daf31d5

Browse files
docs(api): updates to API spec
1 parent 1a8c6dc commit daf31d5

11 files changed

Lines changed: 374 additions & 14 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-321826aa393f6f2c2e2ccc8b20795157f8b55908a96b4c28d90272f306ee3ff4.yml
3-
openapi_spec_hash: ccf23a9557962bab6ed52a94a25ecf1c
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/writerai%2Fwriter-3f87c8deb39e443022f2e04252994a6c9d25473872503edf9eec00d874576b2d.yml
3+
openapi_spec_hash: 5de52bf1d78e00b13a04f6e9ce2f2fb5
44
config_hash: 7a38bab086b53b43d2a719cb4d883264

src/writerai/resources/graphs.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ def question(
360360
*,
361361
graph_ids: SequenceNotStr[str],
362362
question: str,
363+
query_config: graph_question_params.QueryConfig | NotGiven = NOT_GIVEN,
363364
stream: Literal[False] | NotGiven = NOT_GIVEN,
364365
subqueries: bool | NotGiven = NOT_GIVEN,
365366
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -377,6 +378,9 @@ def question(
377378
378379
question: The question to answer using the Knowledge Graph.
379380
381+
query_config: Configuration options for Knowledge Graph queries, including search parameters
382+
and citation settings.
383+
380384
stream: Determines whether the model's output should be streamed. If true, the output is
381385
generated and sent incrementally, which can be useful for real-time
382386
applications.
@@ -400,6 +404,7 @@ def question(
400404
graph_ids: SequenceNotStr[str],
401405
question: str,
402406
stream: Literal[True],
407+
query_config: graph_question_params.QueryConfig | NotGiven = NOT_GIVEN,
403408
subqueries: bool | NotGiven = NOT_GIVEN,
404409
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
405410
# The extra values given here take precedence over values defined on the client or passed to this method.
@@ -420,6 +425,9 @@ def question(
420425
generated and sent incrementally, which can be useful for real-time
421426
applications.
422427
428+
query_config: Configuration options for Knowledge Graph queries, including search parameters
429+
and citation settings.
430+
423431
subqueries: Specify whether to include subqueries.
424432
425433
extra_headers: Send extra headers
@@ -439,6 +447,7 @@ def question(
439447
graph_ids: SequenceNotStr[str],
440448
question: str,
441449
stream: bool,
450+
query_config: graph_question_params.QueryConfig | NotGiven = NOT_GIVEN,
442451
subqueries: bool | NotGiven = NOT_GIVEN,
443452
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
444453
# The extra values given here take precedence over values defined on the client or passed to this method.
@@ -459,6 +468,9 @@ def question(
459468
generated and sent incrementally, which can be useful for real-time
460469
applications.
461470
471+
query_config: Configuration options for Knowledge Graph queries, including search parameters
472+
and citation settings.
473+
462474
subqueries: Specify whether to include subqueries.
463475
464476
extra_headers: Send extra headers
@@ -477,6 +489,7 @@ def question(
477489
*,
478490
graph_ids: SequenceNotStr[str],
479491
question: str,
492+
query_config: graph_question_params.QueryConfig | NotGiven = NOT_GIVEN,
480493
stream: Literal[False] | Literal[True] | NotGiven = NOT_GIVEN,
481494
subqueries: bool | NotGiven = NOT_GIVEN,
482495
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -492,6 +505,7 @@ def question(
492505
{
493506
"graph_ids": graph_ids,
494507
"question": question,
508+
"query_config": query_config,
495509
"stream": stream,
496510
"subqueries": subqueries,
497511
},
@@ -867,6 +881,7 @@ async def question(
867881
*,
868882
graph_ids: SequenceNotStr[str],
869883
question: str,
884+
query_config: graph_question_params.QueryConfig | NotGiven = NOT_GIVEN,
870885
stream: Literal[False] | NotGiven = NOT_GIVEN,
871886
subqueries: bool | NotGiven = NOT_GIVEN,
872887
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -884,6 +899,9 @@ async def question(
884899
885900
question: The question to answer using the Knowledge Graph.
886901
902+
query_config: Configuration options for Knowledge Graph queries, including search parameters
903+
and citation settings.
904+
887905
stream: Determines whether the model's output should be streamed. If true, the output is
888906
generated and sent incrementally, which can be useful for real-time
889907
applications.
@@ -907,6 +925,7 @@ async def question(
907925
graph_ids: SequenceNotStr[str],
908926
question: str,
909927
stream: Literal[True],
928+
query_config: graph_question_params.QueryConfig | NotGiven = NOT_GIVEN,
910929
subqueries: bool | NotGiven = NOT_GIVEN,
911930
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
912931
# The extra values given here take precedence over values defined on the client or passed to this method.
@@ -927,6 +946,9 @@ async def question(
927946
generated and sent incrementally, which can be useful for real-time
928947
applications.
929948
949+
query_config: Configuration options for Knowledge Graph queries, including search parameters
950+
and citation settings.
951+
930952
subqueries: Specify whether to include subqueries.
931953
932954
extra_headers: Send extra headers
@@ -946,6 +968,7 @@ async def question(
946968
graph_ids: SequenceNotStr[str],
947969
question: str,
948970
stream: bool,
971+
query_config: graph_question_params.QueryConfig | NotGiven = NOT_GIVEN,
949972
subqueries: bool | NotGiven = NOT_GIVEN,
950973
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
951974
# The extra values given here take precedence over values defined on the client or passed to this method.
@@ -966,6 +989,9 @@ async def question(
966989
generated and sent incrementally, which can be useful for real-time
967990
applications.
968991
992+
query_config: Configuration options for Knowledge Graph queries, including search parameters
993+
and citation settings.
994+
969995
subqueries: Specify whether to include subqueries.
970996
971997
extra_headers: Send extra headers
@@ -984,6 +1010,7 @@ async def question(
9841010
*,
9851011
graph_ids: SequenceNotStr[str],
9861012
question: str,
1013+
query_config: graph_question_params.QueryConfig | NotGiven = NOT_GIVEN,
9871014
stream: Literal[False] | Literal[True] | NotGiven = NOT_GIVEN,
9881015
subqueries: bool | NotGiven = NOT_GIVEN,
9891016
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -999,6 +1026,7 @@ async def question(
9991026
{
10001027
"graph_ids": graph_ids,
10011028
"question": question,
1029+
"query_config": query_config,
10021030
"stream": stream,
10031031
"subqueries": subqueries,
10041032
},

src/writerai/types/graph_question_params.py

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from .._types import SequenceNotStr
99

10-
__all__ = ["GraphQuestionParamsBase", "GraphQuestionParamsNonStreaming", "GraphQuestionParamsStreaming"]
10+
__all__ = ["GraphQuestionParamsBase", "QueryConfig", "GraphQuestionParamsNonStreaming", "GraphQuestionParamsStreaming"]
1111

1212

1313
class GraphQuestionParamsBase(TypedDict, total=False):
@@ -17,10 +17,83 @@ class GraphQuestionParamsBase(TypedDict, total=False):
1717
question: Required[str]
1818
"""The question to answer using the Knowledge Graph."""
1919

20+
query_config: QueryConfig
21+
"""
22+
Configuration options for Knowledge Graph queries, including search parameters
23+
and citation settings.
24+
"""
25+
2026
subqueries: bool
2127
"""Specify whether to include subqueries."""
2228

2329

30+
class QueryConfig(TypedDict, total=False):
31+
grounding_level: float
32+
"""
33+
Level of grounding required for responses, controlling how closely answers must
34+
be tied to source material. Set lower for grounded outputs, higher for
35+
creativity. Higher values (closer to 1.0) allow more creative interpretation,
36+
while lower values (closer to 0.0) stick more closely to source material. Range:
37+
0.0-1.0, Default: 0.0.
38+
"""
39+
40+
inline_citations: bool
41+
"""
42+
Whether to include inline citations in the response, showing which Knowledge
43+
Graph sources were used. Default: false.
44+
"""
45+
46+
keyword_threshold: float
47+
"""Threshold for keyword-based matching when searching Knowledge Graph content.
48+
49+
Set higher for stricter relevance, lower for broader range. Higher values
50+
(closer to 1.0) require stronger keyword matches, while lower values (closer to
51+
0.0) allow more lenient matching. Range: 0.0-1.0, Default: 0.7.
52+
"""
53+
54+
max_snippets: int
55+
"""Maximum number of text snippets to retrieve from the Knowledge Graph for
56+
context.
57+
58+
Works in concert with `search_weight` to control best matches vs broader
59+
coverage. While technically supports 1-60, values below 5 may return no results
60+
due to RAG implementation. Recommended range: 5-25. Due to RAG system behavior,
61+
you may see more snippets than requested. Range: 1-60, Default: 30.
62+
"""
63+
64+
max_subquestions: int
65+
"""Maximum number of subquestions to generate when processing complex queries.
66+
67+
Set higher to improve detail, set lower to reduce response time. Range: 1-10,
68+
Default: 6.
69+
"""
70+
71+
max_tokens: int
72+
"""Maximum number of tokens the model can generate in the response.
73+
74+
This controls the length of the AI's answer. Set higher for longer answers, set
75+
lower for shorter, faster answers. Range: 100-8000, Default: 4000.
76+
"""
77+
78+
search_weight: int
79+
"""Weight given to search results when ranking and selecting relevant information.
80+
81+
Higher values (closer to 100) prioritize keyword-based matching, while lower
82+
values (closer to 0) prioritize semantic similarity matching. Use higher values
83+
for exact keyword searches, lower values for conceptual similarity searches.
84+
Range: 0-100, Default: 50.
85+
"""
86+
87+
semantic_threshold: float
88+
"""
89+
Threshold for semantic similarity matching when searching Knowledge Graph
90+
content. Set higher for stricter relevance, lower for broader range. Higher
91+
values (closer to 1.0) require stronger semantic similarity, while lower values
92+
(closer to 0.0) allow more lenient semantic matching. Range: 0.0-1.0, Default:
93+
0.7.
94+
"""
95+
96+
2497
class GraphQuestionParamsNonStreaming(GraphQuestionParamsBase, total=False):
2598
stream: Literal[False]
2699
"""Determines whether the model's output should be streamed.

src/writerai/types/question.py

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,77 @@
22

33
from typing import List, Optional
44

5+
from pydantic import Field as FieldInfo
6+
57
from .._models import BaseModel
68
from .shared.source import Source
79

8-
__all__ = ["Question", "Subquery"]
10+
__all__ = ["Question", "References", "ReferencesFile", "ReferencesWeb", "Subquery"]
11+
12+
13+
class ReferencesFile(BaseModel):
14+
file_id: str = FieldInfo(alias="fileId")
15+
"""The unique identifier of the file in your Writer account."""
16+
17+
score: float
18+
"""
19+
Internal score used during the retrieval process for ranking and selecting
20+
relevant snippets.
21+
"""
22+
23+
text: str
24+
"""
25+
The exact text snippet from the source document that was used to support the
26+
response.
27+
"""
28+
29+
cite: Optional[str] = None
30+
"""
31+
Unique citation ID that appears in inline citations within the response text
32+
(null if not cited).
33+
"""
34+
35+
page: Optional[int] = None
36+
"""Page number where this snippet was found in the source document."""
37+
38+
39+
class ReferencesWeb(BaseModel):
40+
score: float
41+
"""
42+
Internal score used during the retrieval process for ranking and selecting
43+
relevant snippets.
44+
"""
45+
46+
text: str
47+
"""
48+
The exact text snippet from the web source that was used to support the
49+
response.
50+
"""
51+
52+
title: str
53+
"""The title of the web page where this content was found."""
54+
55+
url: str
56+
"""The URL of the web page where this content was found."""
57+
58+
59+
class References(BaseModel):
60+
files: Optional[List[ReferencesFile]] = None
61+
"""Array of file-based references from uploaded documents in the Knowledge Graph."""
62+
63+
web: Optional[List[ReferencesWeb]] = None
64+
"""Array of web-based references from online sources accessed during the query."""
965

1066

1167
class Subquery(BaseModel):
1268
answer: str
13-
"""The answer to the subquery."""
69+
"""The answer to the subquery based on Knowledge Graph content."""
1470

1571
query: str
16-
"""The subquery that was asked."""
72+
"""The subquery that was generated to help answer the main question."""
1773

1874
sources: List[Optional[Source]]
75+
"""Array of source snippets that were used to answer this subquery."""
1976

2077

2178
class Question(BaseModel):
@@ -27,4 +84,10 @@ class Question(BaseModel):
2784

2885
sources: List[Optional[Source]]
2986

87+
references: Optional[References] = None
88+
"""
89+
Detailed source information organized by reference type, providing comprehensive
90+
metadata about the sources used to generate the response.
91+
"""
92+
3093
subqueries: Optional[List[Optional[Subquery]]] = None

src/writerai/types/shared/graph_data.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111

1212
class Subquery(BaseModel):
1313
answer: str
14-
"""The answer to the subquery."""
14+
"""The answer to the subquery based on Knowledge Graph content."""
1515

1616
query: str
17-
"""The subquery that was asked."""
17+
"""The subquery that was generated to help answer the main question."""
1818

1919
sources: List[Optional[Source]]
20+
"""Array of source snippets that were used to answer this subquery."""
2021

2122

2223
class GraphData(BaseModel):

src/writerai/types/shared/source.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77

88
class Source(BaseModel):
99
file_id: str
10-
"""The unique identifier of the file."""
10+
"""The unique identifier of the file in your Writer account."""
1111

1212
snippet: str
13-
"""A snippet of text from the source file."""
13+
"""
14+
The exact text snippet from the source document that was used to support the
15+
response.
16+
"""

0 commit comments

Comments
 (0)