Skip to content

Commit 1d3a576

Browse files
committed
Update the typescript samples
1 parent c6c9529 commit 1d3a576

File tree

1 file changed

+61
-30
lines changed

1 file changed

+61
-30
lines changed

api-reference/api-services/sdk.mdx

Lines changed: 61 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,23 @@ deployment of Unstructured API, you can access the API using the Python or TypeS
2929

3030
## Basics
3131

32-
<Note>
32+
<Warning>
33+
The TypeScript SDK has the following breaking changes in v0.11.0:
34+
* Imports under the `dist` path have moved up a level
35+
* Enums are now used for parameters with a set of options
36+
* This includes `chunkingStrategy`, `outputFormat`, and `strategy`
37+
* All parameters to `partition` have moved to a `partitionParameters` object
38+
</Warning>
39+
40+
<Warning>
3341
Python SDK Deprecation Warning (>v0.22.0): The legacy method of passing `shared.PartitionParameters`
3442
directly to `client.general.partition()` is currently supported but may be deprecated and
3543
could break in future releases. Users should migrate to the new `shared.PartitionRequest` object
3644
to ensure compatibility with future updates.
37-
</Note>
45+
</Warning>
3846

3947
<Note>
40-
Currently, the clients only support sending one file at a time.
48+
Currently, the SDKs only support sending one file at a time.
4149
</Note>
4250

4351
Let's start with a simple example in which you send a pdf document to be partitioned via the free Unstructured API:
@@ -77,30 +85,43 @@ deployment of Unstructured API, you can access the API using the Python or TypeS
7785
pass
7886
```
7987
```javascript TypeScript
80-
import { openAsBlob } from "node:fs";
8188
import { UnstructuredClient } from "unstructured-client";
82-
import { Strategy, ChunkingStrategy } from "unstructured-client/sdk/models/shared";
89+
import { PartitionResponse } from "unstructured-client/sdk/models/operations";
90+
import { Strategy } from "unstructured-client/sdk/models/shared";
91+
import * as fs from "fs";
92+
93+
const key = "${apiKey}";
8394

8495
const client = new UnstructuredClient({
85-
security: { apiKeyAuth: "YOUR_API_KEY" },
86-
// You only need to provide your unique API URL if using the SaaS Unstructured API
87-
// serverURL: "YOUR_API_URL",
96+
serverURL: "${apiUrl}",
97+
security: {
98+
apiKeyAuth: key,
99+
},
88100
});
89101

90-
async function run() {
91-
const res = await client.general.partition({
92-
partitionParameters: {
93-
files: await openAsBlob("sample-docs/layout-parser-paper.pdf"),
94-
strategy: Strategy.Auto,
95-
languages: ['eng'],
96-
},
97-
});
98-
99-
// Handle the response
100-
console.log(res)
101-
}
102+
const filename = "PATH_TO_FILE";
103+
const data = fs.readFileSync(filename);
102104

103-
run();
105+
client.general.partition({
106+
partitionParameters: {
107+
files: {
108+
content: data,
109+
fileName: filename,
110+
},
111+
strategy: Strategy.Fast,
112+
}
113+
}).then((res: PartitionResponse) => {
114+
if (res.statusCode == 200) {
115+
console.log(res.elements);
116+
}
117+
}).catch((e) => {
118+
if (e.statusCode) {
119+
console.log(e.statusCode);
120+
console.log(e.body);
121+
} else {
122+
console.log(e);
123+
}
124+
});
104125
```
105126
```python Python (SDK <=v0.22.0)
106127
import unstructured_client
@@ -137,26 +158,36 @@ deployment of Unstructured API, you can access the API using the Python or TypeS
137158
import { PartitionResponse } from "unstructured-client/dist/sdk/models/operations";
138159
import * as fs from "fs";
139160

140-
const key = "YOUR_API_KEY";
161+
const key = "${apiKey}";
141162

142163
const client = new UnstructuredClient({
143-
security: { apiKeyAuth: "YOUR_API_KEY" },
144-
// You only need to provide your unique API URL if using the SaaS Unstructured API
145-
// serverURL: "YOUR_API_URL",
164+
serverURL: "${apiUrl}",
165+
security: {
166+
apiKeyAuth: key,
167+
},
146168
});
147169

148-
const filename = "sample-docs/layout-parser-paper.pdf";
170+
const filename = "PATH_TO_FILE";
149171
const data = fs.readFileSync(filename);
150172

151173
client.general.partition({
152174
files: {
153175
content: data,
154176
fileName: filename,
155177
},
156-
// Other partition params
157-
strategy: "auto",
158-
languages: ['eng'],
159-
})
178+
strategy: 'fast'
179+
}).then((res: PartitionResponse) => {
180+
if (res.statusCode == 200) {
181+
console.log(res.elements);
182+
}
183+
}).catch((e) => {
184+
if (e.statusCode) {
185+
console.log(e.statusCode);
186+
console.log(e.body);
187+
} else {
188+
console.log(e);
189+
}
190+
});
160191
```
161192
</CodeGroup>
162193

0 commit comments

Comments
 (0)