Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 18 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,7 @@ const client = new Zeroentropy({
});

async function main() {
const params: Zeroentropy.DocumentAddParams = {
collection_name: 'example_collection',
content: { type: 'text', text: 'Example Content' },
path: 'my_document.txt',
};
const response: Zeroentropy.DocumentAddResponse = await client.documents.add(params);
const response: Zeroentropy.StatusGetStatusResponse = await client.status.getStatus();
}

main();
Expand All @@ -74,21 +69,15 @@ a subclass of `APIError` will be thrown:
<!-- prettier-ignore -->
```ts
async function main() {
const response = await client.documents
.add({
collection_name: 'example_collection',
content: { type: 'text', text: 'Example Content' },
path: 'my_document.txt',
})
.catch(async (err) => {
if (err instanceof Zeroentropy.APIError) {
console.log(err.status); // 400
console.log(err.name); // BadRequestError
console.log(err.headers); // {server: 'nginx', ...}
} else {
throw err;
}
});
const response = await client.status.getStatus().catch(async (err) => {
if (err instanceof Zeroentropy.APIError) {
console.log(err.status); // 400
console.log(err.name); // BadRequestError
console.log(err.headers); // {server: 'nginx', ...}
} else {
throw err;
}
});
}

main();
Expand Down Expand Up @@ -123,7 +112,7 @@ const client = new Zeroentropy({
});

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

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

const response = await client.documents
.add({
collection_name: 'example_collection',
content: { type: 'text', text: 'Example Content' },
path: 'my_document.txt',
})
.asResponse();
const response = await client.status.getStatus().asResponse();
console.log(response.headers.get('X-My-Header'));
console.log(response.statusText); // access the underlying Response object

const { data: response, response: raw } = await client.documents
.add({
collection_name: 'example_collection',
content: { type: 'text', text: 'Example Content' },
path: 'my_document.txt',
})
.withResponse();
const { data: response, response: raw } = await client.status.getStatus().withResponse();
console.log(raw.headers.get('X-My-Header'));
console.log(response.message);
console.log(response.num_documents);
```

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

// Override per-request:
await client.documents.add(
{
collection_name: 'example_collection',
content: { type: 'text', text: 'Example Content' },
path: 'my_document.txt',
},
{
httpAgent: new http.Agent({ keepAlive: false }),
},
);
await client.status.getStatus({
httpAgent: new http.Agent({ keepAlive: false }),
});
```

## Semantic versioning
Expand Down