Skip to content

Commit 59bb1ab

Browse files
feat(api): update via SDK Studio (#63)
1 parent 40d345d commit 59bb1ab

22 files changed

+470
-61
lines changed

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
configured_endpoints: 46
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/contextual-ai%2Fsunrise-f43814080090927ee22816c5c7f517d8a7eb7f346329ada67915608e32124321.yml
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/contextual-ai%2Fsunrise-194878b194cd507d7c5418ff38cc0fc53441ef618f991990d334b4b75775cd8f.yml

api.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# ContextualAI
2+
3+
Types:
4+
5+
```python
6+
from contextual.types import CompositeMetadataFilter
7+
```
8+
19
# Datastores
210

311
Types:

src/contextual/resources/agents/agents.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ def create(
104104
agent_configs: agent_create_params.AgentConfigs | NotGiven = NOT_GIVEN,
105105
datastore_ids: List[str] | NotGiven = NOT_GIVEN,
106106
description: str | NotGiven = NOT_GIVEN,
107+
filter_prompt: str | NotGiven = NOT_GIVEN,
107108
suggested_queries: List[str] | NotGiven = NOT_GIVEN,
108109
system_prompt: str | NotGiven = NOT_GIVEN,
109110
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -126,6 +127,11 @@ def create(
126127
creates an empty `Datastore` and configures the `Agent` to use the newly created
127128
`Datastore`.
128129
130+
> Note that self-serve users are currently required to create agents through our
131+
> UI. Otherwise, they will receive the following message: "This endpoint is
132+
> disabled as you need to go through checkout. Please use the UI to make this
133+
> request."
134+
129135
Args:
130136
name: Name of the agent
131137
@@ -135,6 +141,9 @@ def create(
135141
136142
description: Description of the agent
137143
144+
filter_prompt: The prompt to an LLM which determines whether retrieved chunks are relevant to a
145+
given query and filters out irrelevant chunks.
146+
138147
suggested_queries: These queries will show up as suggestions in the Contextual UI when users load
139148
the agent. We recommend including common queries that users will ask, as well as
140149
complex queries so users understand the types of complex queries the system can
@@ -159,6 +168,7 @@ def create(
159168
"agent_configs": agent_configs,
160169
"datastore_ids": datastore_ids,
161170
"description": description,
171+
"filter_prompt": filter_prompt,
162172
"suggested_queries": suggested_queries,
163173
"system_prompt": system_prompt,
164174
},
@@ -176,6 +186,7 @@ def update(
176186
*,
177187
agent_configs: agent_update_params.AgentConfigs | NotGiven = NOT_GIVEN,
178188
datastore_ids: List[str] | NotGiven = NOT_GIVEN,
189+
filter_prompt: str | NotGiven = NOT_GIVEN,
179190
llm_model_id: str | NotGiven = NOT_GIVEN,
180191
suggested_queries: List[str] | NotGiven = NOT_GIVEN,
181192
system_prompt: str | NotGiven = NOT_GIVEN,
@@ -198,6 +209,9 @@ def update(
198209
199210
datastore_ids: IDs of the datastore to associate with the agent.
200211
212+
filter_prompt: The prompt to an LLM which determines whether retrieved chunks are relevant to a
213+
given query and filters out irrelevant chunks.
214+
201215
llm_model_id: The model ID to use for generation. Tuned models can only be used for the agents
202216
on which they were tuned. If no model is specified, the default model is used.
203217
Set to `default` to switch from a tuned model to the default model.
@@ -226,6 +240,7 @@ def update(
226240
{
227241
"agent_configs": agent_configs,
228242
"datastore_ids": datastore_ids,
243+
"filter_prompt": filter_prompt,
229244
"llm_model_id": llm_model_id,
230245
"suggested_queries": suggested_queries,
231246
"system_prompt": system_prompt,
@@ -405,6 +420,7 @@ async def create(
405420
agent_configs: agent_create_params.AgentConfigs | NotGiven = NOT_GIVEN,
406421
datastore_ids: List[str] | NotGiven = NOT_GIVEN,
407422
description: str | NotGiven = NOT_GIVEN,
423+
filter_prompt: str | NotGiven = NOT_GIVEN,
408424
suggested_queries: List[str] | NotGiven = NOT_GIVEN,
409425
system_prompt: str | NotGiven = NOT_GIVEN,
410426
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -427,6 +443,11 @@ async def create(
427443
creates an empty `Datastore` and configures the `Agent` to use the newly created
428444
`Datastore`.
429445
446+
> Note that self-serve users are currently required to create agents through our
447+
> UI. Otherwise, they will receive the following message: "This endpoint is
448+
> disabled as you need to go through checkout. Please use the UI to make this
449+
> request."
450+
430451
Args:
431452
name: Name of the agent
432453
@@ -436,6 +457,9 @@ async def create(
436457
437458
description: Description of the agent
438459
460+
filter_prompt: The prompt to an LLM which determines whether retrieved chunks are relevant to a
461+
given query and filters out irrelevant chunks.
462+
439463
suggested_queries: These queries will show up as suggestions in the Contextual UI when users load
440464
the agent. We recommend including common queries that users will ask, as well as
441465
complex queries so users understand the types of complex queries the system can
@@ -460,6 +484,7 @@ async def create(
460484
"agent_configs": agent_configs,
461485
"datastore_ids": datastore_ids,
462486
"description": description,
487+
"filter_prompt": filter_prompt,
463488
"suggested_queries": suggested_queries,
464489
"system_prompt": system_prompt,
465490
},
@@ -477,6 +502,7 @@ async def update(
477502
*,
478503
agent_configs: agent_update_params.AgentConfigs | NotGiven = NOT_GIVEN,
479504
datastore_ids: List[str] | NotGiven = NOT_GIVEN,
505+
filter_prompt: str | NotGiven = NOT_GIVEN,
480506
llm_model_id: str | NotGiven = NOT_GIVEN,
481507
suggested_queries: List[str] | NotGiven = NOT_GIVEN,
482508
system_prompt: str | NotGiven = NOT_GIVEN,
@@ -499,6 +525,9 @@ async def update(
499525
500526
datastore_ids: IDs of the datastore to associate with the agent.
501527
528+
filter_prompt: The prompt to an LLM which determines whether retrieved chunks are relevant to a
529+
given query and filters out irrelevant chunks.
530+
502531
llm_model_id: The model ID to use for generation. Tuned models can only be used for the agents
503532
on which they were tuned. If no model is specified, the default model is used.
504533
Set to `default` to switch from a tuned model to the default model.
@@ -527,6 +556,7 @@ async def update(
527556
{
528557
"agent_configs": agent_configs,
529558
"datastore_ids": datastore_ids,
559+
"filter_prompt": filter_prompt,
530560
"llm_model_id": llm_model_id,
531561
"suggested_queries": suggested_queries,
532562
"system_prompt": system_prompt,

src/contextual/resources/agents/query.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def create(
6363
include_retrieval_content_text: bool | NotGiven = NOT_GIVEN,
6464
retrievals_only: bool | NotGiven = NOT_GIVEN,
6565
conversation_id: str | NotGiven = NOT_GIVEN,
66+
documents_filters: query_create_params.DocumentsFilters | NotGiven = NOT_GIVEN,
6667
llm_model_id: str | NotGiven = NOT_GIVEN,
6768
stream: bool | NotGiven = NOT_GIVEN,
6869
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -97,6 +98,41 @@ def create(
9798
provided, all messages in the `messages` list prior to the latest user-sent
9899
query will be ignored.
99100
101+
documents_filters: Defines an Optional custom metadata filter, which can be a list of filters or
102+
nested filters. The expected input is a nested JSON object that can represent a
103+
single filter or a composite (logical) combination of filters.
104+
105+
Unnested Example:
106+
107+
```json
108+
{
109+
"operator": "AND",
110+
"filters": [{ "field": "status", "operator": "equals", "value": "active" }]
111+
}
112+
```
113+
114+
Nested example:
115+
116+
```json
117+
{
118+
"operator": "AND",
119+
"filters": [
120+
{ "field": "status", "operator": "equals", "value": "active" },
121+
{
122+
"operator": "OR",
123+
"filters": [
124+
{
125+
"field": "category",
126+
"operator": "containsany",
127+
"value": ["policy", "HR"]
128+
},
129+
{ "field": "tags", "operator": "exists" }
130+
]
131+
}
132+
]
133+
}
134+
```
135+
100136
llm_model_id: Model ID of the specific fine-tuned or aligned LLM model to use. Defaults to
101137
base model if not specified.
102138
@@ -118,6 +154,7 @@ def create(
118154
{
119155
"messages": messages,
120156
"conversation_id": conversation_id,
157+
"documents_filters": documents_filters,
121158
"llm_model_id": llm_model_id,
122159
"stream": stream,
123160
},
@@ -210,10 +247,12 @@ def metrics(
210247
self,
211248
agent_id: str,
212249
*,
250+
conversation_ids: List[str] | NotGiven = NOT_GIVEN,
213251
created_after: Union[str, datetime] | NotGiven = NOT_GIVEN,
214252
created_before: Union[str, datetime] | NotGiven = NOT_GIVEN,
215253
limit: int | NotGiven = NOT_GIVEN,
216254
offset: int | NotGiven = NOT_GIVEN,
255+
user_emails: List[str] | NotGiven = NOT_GIVEN,
217256
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
218257
# The extra values given here take precedence over values defined on the client or passed to this method.
219258
extra_headers: Headers | None = None,
@@ -229,6 +268,8 @@ def metrics(
229268
Args:
230269
agent_id: Agent ID of the agent to get metrics for
231270
271+
conversation_ids: Filter messages by conversation ids.
272+
232273
created_after: Filters messages that are created after the specified timestamp.
233274
234275
created_before: Filters messages that are created before specified timestamp.
@@ -237,6 +278,8 @@ def metrics(
237278
238279
offset: Offset for pagination.
239280
281+
user_emails: Filter messages by users.
282+
240283
extra_headers: Send extra headers
241284
242285
extra_query: Add additional query parameters to the request
@@ -256,10 +299,12 @@ def metrics(
256299
timeout=timeout,
257300
query=maybe_transform(
258301
{
302+
"conversation_ids": conversation_ids,
259303
"created_after": created_after,
260304
"created_before": created_before,
261305
"limit": limit,
262306
"offset": offset,
307+
"user_emails": user_emails,
263308
},
264309
query_metrics_params.QueryMetricsParams,
265310
),
@@ -346,6 +391,7 @@ async def create(
346391
include_retrieval_content_text: bool | NotGiven = NOT_GIVEN,
347392
retrievals_only: bool | NotGiven = NOT_GIVEN,
348393
conversation_id: str | NotGiven = NOT_GIVEN,
394+
documents_filters: query_create_params.DocumentsFilters | NotGiven = NOT_GIVEN,
349395
llm_model_id: str | NotGiven = NOT_GIVEN,
350396
stream: bool | NotGiven = NOT_GIVEN,
351397
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -380,6 +426,41 @@ async def create(
380426
provided, all messages in the `messages` list prior to the latest user-sent
381427
query will be ignored.
382428
429+
documents_filters: Defines an Optional custom metadata filter, which can be a list of filters or
430+
nested filters. The expected input is a nested JSON object that can represent a
431+
single filter or a composite (logical) combination of filters.
432+
433+
Unnested Example:
434+
435+
```json
436+
{
437+
"operator": "AND",
438+
"filters": [{ "field": "status", "operator": "equals", "value": "active" }]
439+
}
440+
```
441+
442+
Nested example:
443+
444+
```json
445+
{
446+
"operator": "AND",
447+
"filters": [
448+
{ "field": "status", "operator": "equals", "value": "active" },
449+
{
450+
"operator": "OR",
451+
"filters": [
452+
{
453+
"field": "category",
454+
"operator": "containsany",
455+
"value": ["policy", "HR"]
456+
},
457+
{ "field": "tags", "operator": "exists" }
458+
]
459+
}
460+
]
461+
}
462+
```
463+
383464
llm_model_id: Model ID of the specific fine-tuned or aligned LLM model to use. Defaults to
384465
base model if not specified.
385466
@@ -401,6 +482,7 @@ async def create(
401482
{
402483
"messages": messages,
403484
"conversation_id": conversation_id,
485+
"documents_filters": documents_filters,
404486
"llm_model_id": llm_model_id,
405487
"stream": stream,
406488
},
@@ -493,10 +575,12 @@ async def metrics(
493575
self,
494576
agent_id: str,
495577
*,
578+
conversation_ids: List[str] | NotGiven = NOT_GIVEN,
496579
created_after: Union[str, datetime] | NotGiven = NOT_GIVEN,
497580
created_before: Union[str, datetime] | NotGiven = NOT_GIVEN,
498581
limit: int | NotGiven = NOT_GIVEN,
499582
offset: int | NotGiven = NOT_GIVEN,
583+
user_emails: List[str] | NotGiven = NOT_GIVEN,
500584
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
501585
# The extra values given here take precedence over values defined on the client or passed to this method.
502586
extra_headers: Headers | None = None,
@@ -512,6 +596,8 @@ async def metrics(
512596
Args:
513597
agent_id: Agent ID of the agent to get metrics for
514598
599+
conversation_ids: Filter messages by conversation ids.
600+
515601
created_after: Filters messages that are created after the specified timestamp.
516602
517603
created_before: Filters messages that are created before specified timestamp.
@@ -520,6 +606,8 @@ async def metrics(
520606
521607
offset: Offset for pagination.
522608
609+
user_emails: Filter messages by users.
610+
523611
extra_headers: Send extra headers
524612
525613
extra_query: Add additional query parameters to the request
@@ -539,10 +627,12 @@ async def metrics(
539627
timeout=timeout,
540628
query=await async_maybe_transform(
541629
{
630+
"conversation_ids": conversation_ids,
542631
"created_after": created_after,
543632
"created_before": created_before,
544633
"limit": limit,
545634
"offset": offset,
635+
"user_emails": user_emails,
546636
},
547637
query_metrics_params.QueryMetricsParams,
548638
),

src/contextual/resources/datastores/datastores.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ def create(
8383
from multiple sources of information. This linkage of `Datastore` to `Agent` is
8484
done through the `Create Agent` or `Edit Agent` APIs.
8585
86+
> Note that self-serve users are currently required to create datastores through
87+
> our UI. Otherwise, they will receive the following message: "This endpoint is
88+
> disabled as you need to go through checkout. Please use the UI to make this
89+
> request."
90+
8691
Args:
8792
name: Name of the datastore
8893
@@ -285,6 +290,11 @@ async def create(
285290
from multiple sources of information. This linkage of `Datastore` to `Agent` is
286291
done through the `Create Agent` or `Edit Agent` APIs.
287292
293+
> Note that self-serve users are currently required to create datastores through
294+
> our UI. Otherwise, they will receive the following message: "This endpoint is
295+
> disabled as you need to go through checkout. Please use the UI to make this
296+
> request."
297+
288298
Args:
289299
name: Name of the datastore
290300

0 commit comments

Comments
 (0)