Skip to content

Commit 9189e1d

Browse files
committed
Update readme for split page being true by default
Add links back to our docs, and reintroduce some autogenerated readme sections.
1 parent 59d21c4 commit 9189e1d

File tree

1 file changed

+124
-57
lines changed

1 file changed

+124
-57
lines changed

README.md

Lines changed: 124 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@
99
<a href="https://speakeasyapi.dev/"><img src="https://custom-icon-badges.demolab.com/badge/-Built%20By%20Speakeasy-212015?style=for-the-badge&logoColor=FBE331&logo=speakeasy&labelColor=545454" /></a>
1010
</div>
1111

12-
<h2 align="center">
13-
<p>Typescript SDK for the Unstructured API</p>
14-
</h2>
15-
16-
This is a Typescript client for the [Unstructured API](https://unstructured-io.github.io/unstructured/api.html).
17-
1812
<div align="center">
1913

2014
<a
@@ -24,6 +18,13 @@ This is a Typescript client for the [Unstructured API](https://unstructured-io.g
2418

2519
</div>
2620

21+
<h2 align="center">
22+
<p>Typescript SDK for the Unstructured API</p>
23+
</h2>
24+
25+
This is a Typescript client for the [Unstructured API](https://unstructured-io.github.io/unstructured/api.html).
26+
27+
Please refer to the [Unstructured docs](https://docs.unstructured.io/api-reference/api-services/sdk) for a full guide to using the client.
2728

2829
## SDK Installation
2930

@@ -40,45 +41,40 @@ yarn add unstructured-client --dev
4041
```
4142
<!-- No SDK Installation -->
4243

44+
<!-- Start SDK Example Usage [usage] -->
4345
## SDK Example Usage
44-
Only the `files` parameter is required for partition. See the [general partition](docs/sdks/general/README.md) page for all available parameters.
46+
47+
### Example
4548

4649
```typescript
50+
import { openAsBlob } from "node:fs";
4751
import { UnstructuredClient } from "unstructured-client";
48-
import { PartitionResponse } from "unstructured-client/dist/sdk/models/operations";
49-
import * as fs from "fs";
50-
51-
const key = "YOUR-API-KEY";
52+
import { Strategy } from "unstructured-client/sdk/models/shared";
5253

53-
const client = new UnstructuredClient({
54+
const unstructuredClient = new UnstructuredClient({
5455
security: {
55-
apiKeyAuth: key,
56+
apiKeyAuth: "YOUR_API_KEY",
5657
},
57-
// uncomment and change the URL below depending on which services you use or hosting locally; see below for more details
58-
// by default it will make requests againt the url for the freemium (https://unstructured.io/api-key-free) API service
59-
// serverURL: "http://localhost:8000",
6058
});
6159

62-
const filename = "sample-docs/layout-parser-paper.pdf";
63-
const data = fs.readFileSync(filename);
60+
async function run() {
61+
const result = await unstructuredClient.general.partition({
62+
partitionParameters: {
63+
files: await openAsBlob("./sample-file"),
64+
strategy: Strategy.Auto,
65+
},
66+
});
67+
68+
// Handle the result
69+
console.log(result);
70+
}
71+
72+
run();
6473

65-
client.general.partition({
66-
// Note that this currently only supports a single file
67-
files: {
68-
content: data,
69-
fileName: filename,
70-
},
71-
// Other partition params
72-
strategy: "fast",
73-
}).then((res: PartitionResponse) => {
74-
if (res.statusCode == 200) {
75-
console.log(res.elements);
76-
}
77-
}).catch((e) => {
78-
console.log(e.statusCode);
79-
console.log(e.body);
80-
});
8174
```
75+
<!-- End SDK Example Usage [usage] -->
76+
77+
Refer to the [API parameters page](https://docs.unstructured.io/api-reference/api-services/api-parameters) for all available parameters.
8278

8379
## Change the base URL
8480

@@ -103,12 +99,6 @@ const client = new UnstructuredClient({
10399
```
104100

105101

106-
<!-- No SDK Example Usage -->
107-
<!-- No SDK Available Operations -->
108-
<!-- No Pagination -->
109-
<!-- No Error Handling -->
110-
<!-- No Server Selection -->
111-
112102
<!-- Start Custom HTTP Client [http-client] -->
113103
## Custom HTTP Client
114104

@@ -157,24 +147,102 @@ httpClient.addHook("requestError", (error, request) => {
157147
const sdk = new UnstructuredClient({ httpClient });
158148
```
159149
<!-- End Custom HTTP Client [http-client] -->
160-
<!-- No Retries -->
161-
<!-- No Authentication -->
162150

163-
## PartitionParameters
151+
<!-- Start Retries [retries] -->
152+
## Retries
164153

165-
See the [general partition](docs/sdk/models/shared/partitionparameters.md) page for all available parameters.
154+
Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.
166155

167-
### Splitting PDF by pages
156+
To change the default retry strategy for a single API call, simply provide a retryConfig object to the call:
157+
```typescript
158+
import { openAsBlob } from "node:fs";
159+
import { UnstructuredClient } from "unstructured-client";
160+
import { Strategy } from "unstructured-client/sdk/models/shared";
161+
162+
const unstructuredClient = new UnstructuredClient({
163+
security: {
164+
apiKeyAuth: "YOUR_API_KEY",
165+
},
166+
});
168167

169-
In order to speed up processing of long PDF files, set `splitPdfPage` parameter to `true`. It will cause the PDF to be split into smaller batches at client side, before sending to API, and combining individual responses as single result. This will work only for PDF files, so don't set it for other types of files. Size of each batch is determined internally and it can vary between 2 and 20 pages per split.
168+
async function run() {
169+
const result = await unstructuredClient.general.partition(
170+
{
171+
partitionParameters: {
172+
files: await openAsBlob("./sample-file"),
173+
strategy: Strategy.Auto,
174+
},
175+
},
176+
{
177+
retries: {
178+
strategy: "backoff",
179+
backoff: {
180+
initialInterval: 1,
181+
maxInterval: 50,
182+
exponent: 1.1,
183+
maxElapsedTime: 100,
184+
},
185+
retryConnectionErrors: false,
186+
},
187+
}
188+
);
170189

171-
The amount of parallel requests is controlled by `splitPdfConcurrencyLevel` parameter. By default it equals to 5. It can't be more than 15, to avoid too high resource usage and costs.
190+
// Handle the result
191+
console.log(result);
192+
}
193+
194+
run();
172195

196+
```
197+
198+
If you'd like to override the default retry strategy for all operations that support retries, you can provide a retryConfig at SDK initialization:
173199
```typescript
174-
import { SplitPdfHook } from "unstructured-client/hooks/custom/SplitPdfHook";
200+
import { openAsBlob } from "node:fs";
201+
import { UnstructuredClient } from "unstructured-client";
202+
import { Strategy } from "unstructured-client/sdk/models/shared";
175203

176-
...
204+
const unstructuredClient = new UnstructuredClient({
205+
retryConfig: {
206+
strategy: "backoff",
207+
backoff: {
208+
initialInterval: 1,
209+
maxInterval: 50,
210+
exponent: 1.1,
211+
maxElapsedTime: 100,
212+
},
213+
retryConnectionErrors: false,
214+
},
215+
security: {
216+
apiKeyAuth: "YOUR_API_KEY",
217+
},
218+
});
177219

220+
async function run() {
221+
const result = await unstructuredClient.general.partition({
222+
partitionParameters: {
223+
files: await openAsBlob("./sample-file"),
224+
strategy: Strategy.Auto,
225+
},
226+
});
227+
228+
// Handle the result
229+
console.log(result);
230+
}
231+
232+
run();
233+
234+
```
235+
<!-- End Retries [retries] -->
236+
237+
### Splitting PDF by pages
238+
239+
See [page splitting](https://docs.unstructured.io/api-reference/api-services/sdk#page-splitting) for more details.
240+
241+
In order to speed up processing of large PDF files, the client splits up PDFs into smaller files, sends these to the API concurrently, and recombines the results. `splitPdfPage` can be set to `false` to disable this.
242+
243+
The amount of parallel requests is controlled by `splitPdfConcurrencyLevel` parameter. By default it equals to 5. It can't be more than 15, to avoid too high resource usage and costs. The size of each batch is determined internally and it can vary between 2 and 20 pages per split.
244+
245+
```typescript
178246
client.general.partition({
179247
partitionParameters: {
180248
files: {
@@ -186,14 +254,7 @@ client.general.partition({
186254
// Modify splitPdfConcurrencyLevel to change the limit of parallel requests
187255
splitPdfConcurrencyLevel: 10,
188256
},
189-
}).then((res: PartitionResponse) => {
190-
if (res.statusCode == 200) {
191-
console.log(res.elements);
192-
}
193-
}).catch((e) => {
194-
console.log(e.statusCode);
195-
console.log(e.body);
196-
});
257+
}};
197258
```
198259
199260
<!-- Start Requirements [requirements] -->
@@ -244,6 +305,12 @@ run();
244305
```
245306
<!-- End File uploads [file-upload] -->
246307
308+
<!-- No Authentication -->
309+
<!-- No SDK Available Operations -->
310+
<!-- No Pagination -->
311+
<!-- No Error Handling -->
312+
<!-- No Server Selection -->
313+
247314
<!-- Placeholder for Future Speakeasy SDK Sections -->
248315
249316
### Maturity

0 commit comments

Comments
 (0)