Skip to content

Commit 28fbb65

Browse files
feat(api): update via SDK Studio (#10)
1 parent 9b1b297 commit 28fbb65

File tree

1 file changed

+48
-18
lines changed

1 file changed

+48
-18
lines changed

README.md

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,12 @@ const client = new Zeroentropy({
5252
});
5353

5454
async function main() {
55-
const response: Zeroentropy.StatusGetStatusResponse = await client.status.getStatus();
55+
const params: Zeroentropy.DocumentAddParams = {
56+
collection_name: 'example_collection',
57+
content: { type: 'text', text: 'Example Content' },
58+
path: 'my_document.txt',
59+
};
60+
const response: Zeroentropy.DocumentAddResponse = await client.documents.add(params);
5661
}
5762

5863
main();
@@ -69,15 +74,21 @@ a subclass of `APIError` will be thrown:
6974
<!-- prettier-ignore -->
7075
```ts
7176
async function main() {
72-
const response = await client.status.getStatus().catch(async (err) => {
73-
if (err instanceof Zeroentropy.APIError) {
74-
console.log(err.status); // 400
75-
console.log(err.name); // BadRequestError
76-
console.log(err.headers); // {server: 'nginx', ...}
77-
} else {
78-
throw err;
79-
}
80-
});
77+
const response = await client.documents
78+
.add({
79+
collection_name: 'example_collection',
80+
content: { type: 'text', text: 'Example Content' },
81+
path: 'my_document.txt',
82+
})
83+
.catch(async (err) => {
84+
if (err instanceof Zeroentropy.APIError) {
85+
console.log(err.status); // 400
86+
console.log(err.name); // BadRequestError
87+
console.log(err.headers); // {server: 'nginx', ...}
88+
} else {
89+
throw err;
90+
}
91+
});
8192
}
8293

8394
main();
@@ -112,7 +123,7 @@ const client = new Zeroentropy({
112123
});
113124

114125
// Or, configure per-request:
115-
await client.status.getStatus({
126+
await client.documents.add({ collection_name: 'example_collection', content: { type: 'text', text: 'Example Content' }, path: 'my_document.txt' }, {
116127
maxRetries: 5,
117128
});
118129
```
@@ -129,7 +140,7 @@ const client = new Zeroentropy({
129140
});
130141

131142
// Override per-request:
132-
await client.status.getStatus({
143+
await client.documents.add({ collection_name: 'example_collection', content: { type: 'text', text: 'Example Content' }, path: 'my_document.txt' }, {
133144
timeout: 5 * 1000,
134145
});
135146
```
@@ -183,13 +194,25 @@ You can also use the `.withResponse()` method to get the raw `Response` along wi
183194
```ts
184195
const client = new Zeroentropy();
185196

186-
const response = await client.status.getStatus().asResponse();
197+
const response = await client.documents
198+
.add({
199+
collection_name: 'example_collection',
200+
content: { type: 'text', text: 'Example Content' },
201+
path: 'my_document.txt',
202+
})
203+
.asResponse();
187204
console.log(response.headers.get('X-My-Header'));
188205
console.log(response.statusText); // access the underlying Response object
189206

190-
const { data: response, response: raw } = await client.status.getStatus().withResponse();
207+
const { data: response, response: raw } = await client.documents
208+
.add({
209+
collection_name: 'example_collection',
210+
content: { type: 'text', text: 'Example Content' },
211+
path: 'my_document.txt',
212+
})
213+
.withResponse();
191214
console.log(raw.headers.get('X-My-Header'));
192-
console.log(response.num_documents);
215+
console.log(response.message);
193216
```
194217

195218
### Making custom/undocumented requests
@@ -293,9 +316,16 @@ const client = new Zeroentropy({
293316
});
294317

295318
// Override per-request:
296-
await client.status.getStatus({
297-
httpAgent: new http.Agent({ keepAlive: false }),
298-
});
319+
await client.documents.add(
320+
{
321+
collection_name: 'example_collection',
322+
content: { type: 'text', text: 'Example Content' },
323+
path: 'my_document.txt',
324+
},
325+
{
326+
httpAgent: new http.Agent({ keepAlive: false }),
327+
},
328+
);
299329
```
300330

301331
## Semantic versioning

0 commit comments

Comments
 (0)