Skip to content

Commit da3481b

Browse files
Merge branch 'main' of github.com:invariantlabs-ai/docs
2 parents f3c3b79 + 224da08 commit da3481b

File tree

6 files changed

+201
-14
lines changed

6 files changed

+201
-14
lines changed

docs/explorer/Explorer_API/1_client_setup.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,40 @@ export INVARIANT_API_KEY=YourAPIKey
2121

2222
## Creating a Client
2323

24-
In your Python code, you can create a `Client` object. This object will use the environment variables you set up earlier to authenticate your uploads.
24+
In your Python code, you can create an `AsyncClient` or a `Client` object. This object will use the environment variables you set up earlier to authenticate your uploads.
25+
26+
```python
27+
from invariant_sdk.async_client import AsyncClient
28+
29+
client = AsyncClient()
30+
```
31+
32+
Without parameters, the `AsyncClient` object will automatically use the environment variables you set up earlier and the default Explorer instance at `https://explorer.invariantlabs.ai`.
33+
34+
To create a sync client:
2535

2636
```python
2737
from invariant_sdk.client import Client
2838

2939
client = Client()
3040
```
3141

32-
Without parameters, the `Client` object will automatically use the environment variables you set up earlier and the default Explorer instance at `https://explorer.invariantlabs.ai`.
3342

3443
## Overriding Environment Configuration
3544

36-
If you want to override the environment configuration or use a different API key, you can also pass the API endpoint URL and API key as arguments to the `Client` constructor directly.
45+
If you want to override the environment configuration or use a different API key, you can also pass the API endpoint URL and API key as arguments to the `AsyncClient` constructor directly.
46+
47+
```python
48+
from invariant_sdk.async_client import AsyncClient
49+
50+
client = AsyncClient(
51+
api_url="https://explorer.invariantlabs.ai",
52+
# Add the API key here.
53+
api_key="YourAPIKey",
54+
)
55+
```
56+
57+
For the sync `Client` type:
3758

3859
```python
3960
from invariant_sdk.client import Client
@@ -43,4 +64,4 @@ client = Client(
4364
# Add the API key here.
4465
api_key="YourAPIKey",
4566
)
46-
```
67+
```

docs/explorer/Explorer_API/Dataset_Metadata/get_dataset_metadata_api.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,17 @@ Additional keyword arguments to pass to the requests method. Default is `None`.
3232

3333
The response object from the Invariant API.
3434

35+
> AsyncClient Example
36+
```python
37+
from invariant_sdk.async_client import AsyncClient
38+
from invariant_sdk.types.push_traces import PushTracesRequest
39+
40+
client = AsyncClient()
41+
42+
dataset_metadata = await client.get_dataset_metadata(dataset_name="some_dataset_name")
43+
```
3544

36-
> Example
45+
> Client Example
3746
```python
3847
from invariant_sdk.client import Client
3948
from invariant_sdk.types.push_traces import PushTracesRequest

docs/explorer/Explorer_API/Dataset_Metadata/update_dataset_metadata_api.md

Lines changed: 101 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,75 @@ Additional keyword arguments to pass to the requests method. Default is `None`.
8080

8181
The response object from the Invariant API.
8282

83+
> AsyncClient Example
84+
```python
85+
from invariant_sdk.async_client import AsyncClient
86+
from invariant_sdk.types.update_dataset_metadata import UpdateDatasetMetadataRequest, MetadataUpdate
87+
88+
client = AsyncClient()
89+
90+
# Metadata state: {}
91+
92+
request_1 = UpdateDatasetMetadataRequest(
93+
dataset_name="some_name",
94+
metadata=MetadataUpdate(benchmark="some_benchmark")
95+
)
96+
response_1 = await client.update_dataset_metadata(request_1)
97+
98+
# Metadata state: {"benchmark": "some_benchmark"}
99+
100+
request_2 = UpdateDatasetMetadataRequest(
101+
dataset_name="some_name",
102+
metadata=MetadataUpdate(accuracy=5, name="xyz")
103+
)
104+
105+
response_2 = await client.update_dataset_metadata(request_2)
106+
107+
# Metadata state: {"benchmark": "some_benchmark", "accuracy": 5, "name": "xyz"}
83108

84-
> Example
109+
request_3 = UpdateDatasetMetadataRequest(
110+
dataset_name="some_name",
111+
replace_all=True
112+
metadata=MetadataUpdate(benchmark="new_benchmark")
113+
)
114+
115+
response_3 = await client.update_dataset_metadata(request_3)
116+
117+
# Metadata state: {"benchmark": "new_benchmark"}
118+
119+
```
120+
121+
> AsyncClient Example to clear all previously set metadata
122+
```python
123+
from invariant_sdk.async_client import AsyncClient
124+
from invariant_sdk.types.update_dataset_metadata import UpdateDatasetMetadataRequest, MetadataUpdate
125+
126+
client = AsyncClient()
127+
128+
request = UpdateDatasetMetadataRequest(
129+
dataset_name="some_name",
130+
replace_all=True,
131+
metadata=MetadataUpdate()
132+
)
133+
134+
response = await client.update_dataset_metadata(request)
135+
```
136+
137+
> Client Example
85138
```python
86139
from invariant_sdk.client import Client
87140
from invariant_sdk.types.update_dataset_metadata import UpdateDatasetMetadataRequest, MetadataUpdate
88141

89142
client = Client()
90143

91144
# Metadata state: {}
92-
145+
93146
request_1 = UpdateDatasetMetadataRequest(
94147
dataset_name="some_name",
95148
metadata=MetadataUpdate(benchmark="some_benchmark")
96149
)
97150
response_1 = client.update_dataset_metadata(request_1)
98-
151+
99152
# Metadata state: {"benchmark": "some_benchmark"}
100153

101154
request_2 = UpdateDatasetMetadataRequest(
@@ -119,7 +172,7 @@ The response object from the Invariant API.
119172

120173
```
121174

122-
> Example to clear all previously set metadata
175+
> Client Example to clear all previously set metadata
123176
```python
124177
from invariant_sdk.client import Client
125178
from invariant_sdk.types.update_dataset_metadata import UpdateDatasetMetadataRequest, MetadataUpdate
@@ -160,8 +213,50 @@ Additional keyword arguments to pass to the requests method. Default is `None`.
160213
##### <span class='type'>Dict</span>
161214

162215
The response object from the Invariant API.
216+
> AsyncClient Example
217+
```python
218+
from invariant_sdk.async_client import AsyncClient
219+
220+
client = AsyncClient()
221+
222+
# Metadata state: {}
223+
224+
response_1 = await client.create_request_and_update_dataset_metadata(
225+
dataset_name="some_name",
226+
metadata={"benchmark": "some_benchmark"}
227+
)
228+
229+
# Metadata state: {"benchmark": "some_benchmark"}
230+
231+
response_2 = await client.create_request_and_update_dataset_metadata(
232+
dataset_name="some_name",
233+
metadata={"accuracy": 5, "name": "xyz"}
234+
)
235+
236+
# Metadata state: {"benchmark": "some_benchmark", "accuracy": 5, "name": "xyz"}
237+
238+
response_3 = await client.create_request_and_update_dataset_metadata(
239+
dataset_name="some_name",
240+
replace_all=True,
241+
metadata={"benchmark": "new_benchmark"}
242+
)
243+
244+
# Metadata state: {"benchmark": "new_benchmark"}
245+
```
246+
247+
> AsyncClient Example to clear all previously set metadata
248+
```python
249+
from invariant_sdk.async_client import AsyncClient
250+
251+
client = AsyncClient()
252+
253+
response = await client.create_request_and_update_dataset_metadata(
254+
dataset_name="some_name"
255+
replace_all=True,
256+
)
257+
```
163258

164-
> Example
259+
> Client Example
165260
```python
166261
from invariant_sdk.client import Client
167262

@@ -192,7 +287,7 @@ The response object from the Invariant API.
192287
# Metadata state: {"benchmark": "new_benchmark"}
193288
```
194289

195-
> Example to clear all previously set metadata
290+
> Client Example to clear all previously set metadata
196291
```python
197292
from invariant_sdk.client import Client
198293

docs/explorer/Explorer_API/Uploading_Traces/push_api.md

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,37 @@ Additional keyword arguments to pass to the requests method. Default is `None`.
104104

105105
The response object from the Invariant API.
106106

107+
> AsyncClient Example
108+
```python
109+
from invariant_sdk.async_client import AsyncClient
110+
from invariant_sdk.types.push_traces import PushTracesRequest
107111

108-
> Example
112+
client = AsyncClient()
113+
114+
request = PushTracesRequest(
115+
messages=[
116+
[
117+
{"role": "user", "content": "one"},
118+
{"role": "assistant", "content": "two \n three"},
119+
]
120+
],
121+
annotations=[
122+
[
123+
{
124+
"content": "annotating one",
125+
"address": "messages[0].content:L0",
126+
"extra_metadata": {"key1": "value1"},
127+
}
128+
]
129+
],
130+
metadata=[{"meta_key_1": "meta_value_1"}],
131+
dataset="dataset_name"
132+
)
133+
134+
response = await client.push_trace(request)
135+
```
136+
137+
> Client Example
109138
```python
110139
from invariant_sdk.client import Client
111140
from invariant_sdk.types.push_traces import PushTracesRequest
@@ -165,7 +194,40 @@ Additional keyword arguments to pass to the requests method. Default is `None`.
165194

166195
The response object from the Invariant API.
167196

168-
> Example
197+
> AsyncClient Example
198+
```python
199+
from invariant_sdk.async_client import AsyncClient
200+
201+
client = AsyncClient()
202+
203+
messages = [
204+
[
205+
{"role": "user", "content": "one"},
206+
{"role": "assistant", "content": "two \n three"},
207+
]
208+
]
209+
210+
annotations = [
211+
[
212+
{
213+
"content": "annotating one",
214+
"address": "messages[0].content:L0",
215+
"extra_metadata": {"key1": "value1"},
216+
}
217+
]
218+
]
219+
220+
metadata = [{"meta_key_1": "meta_value_1"}]
221+
222+
response = await client.create_request_and_push_trace(
223+
messages=messages,
224+
annotations=annotations,
225+
metadata=metadata,
226+
dataset="dataset_name"
227+
)
228+
```
229+
230+
> Client Example
169231
```python
170232
from invariant_sdk.client import Client
171233

docs/explorer/search_and_filter.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Often, there is a large number of traces in the dataset. In this chapter, we des
66

77
For instance, searching for `maps` would return all traces containing the word `maps` somewhere in the trace.
88

9-
<img src="/assets/images/search.png" class="img-fluid" alt="Search bar in the Invariant Explorer">
9+
<img src="../assets/search.png" class="img-fluid" alt="Search bar in the Invariant Explorer">
1010

1111
## Exact search
1212

0 commit comments

Comments
 (0)