Skip to content

Commit bc68e7e

Browse files
committed
Add framework integration quickstarts
1 parent 1517a80 commit bc68e7e

File tree

5 files changed

+149
-0
lines changed

5 files changed

+149
-0
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,21 @@ const client = new NutrientClient({
7171
});
7272
```
7373

74+
## Framework Quickstarts
75+
76+
Framework wiring examples are available in `examples/src/`:
77+
78+
- `framework_openai_agents.mjs`
79+
- `framework_langchain.mjs`
80+
- `framework_crewai_scope.md` (CrewAI scope note for TypeScript users)
81+
82+
Syntax-check commands:
83+
84+
```bash
85+
node --check examples/src/framework_openai_agents.mjs
86+
node --check examples/src/framework_langchain.mjs
87+
```
88+
7489
### Working with URLs
7590

7691
Most methods accept URLs directly. The URL is passed to the server, which fetches the content—this avoids SSRF vulnerabilities since the client never fetches URLs itself.

examples/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ This example project demonstrates how to use the Nutrient DWS TypeScript Client
88
- `src/` - Contains TypeScript source files
99
- `direct_method.ts` - Examples using direct method calls
1010
- `workflow.ts` - Examples using the workflow builder pattern
11+
- `framework_openai_agents.mjs` - OpenAI Agents integration sketch
12+
- `framework_langchain.mjs` - LangChain integration sketch
13+
- `framework_crewai_scope.md` - CrewAI scope note for TypeScript users
1114
- `output/` - Directory where processed files will be saved
1215
- `.env.example` - Example environment variables file
1316

@@ -89,6 +92,31 @@ This will:
8992
3. Extract text with JSON output
9093
4. Execute a complex multi-step workflow
9194

95+
### Framework Examples
96+
97+
To run framework integration sketches:
98+
99+
Install optional framework dependencies first:
100+
101+
```bash
102+
npm install @openai/agents @langchain/openai @langchain/core
103+
```
104+
105+
```bash
106+
node src/framework_openai_agents.mjs
107+
node src/framework_langchain.mjs
108+
```
109+
110+
Syntax-check:
111+
112+
```bash
113+
node --check src/framework_openai_agents.mjs
114+
node --check src/framework_langchain.mjs
115+
```
116+
117+
CrewAI note:
118+
- CrewAI is Python-native. See `src/framework_crewai_scope.md` for a recommended bridge pattern when your app stack is TypeScript-first.
119+
92120
## Output
93121

94122
All processed files will be saved to the `output/` directory. You can examine these files to see the results of the document processing operations.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# CrewAI Scope Note (TypeScript Repository)
2+
3+
CrewAI is currently Python-native. This TypeScript client repo does not provide a first-party CrewAI TypeScript SDK path.
4+
5+
## Recommended Pattern
6+
7+
1. Run CrewAI orchestration in a Python service.
8+
2. Call Nutrient DWS through one of these options:
9+
- Python service uses `nutrient-dws-client-python`, or
10+
- Python service calls your TypeScript app endpoint that wraps `@nutrient-sdk/dws-client-typescript`.
11+
3. Return processed artifact metadata (output path, pages, extraction results) back to the TypeScript app.
12+
13+
## Minimal Bridge Sketch
14+
15+
```python
16+
# Python CrewAI worker (separate service)
17+
from crewai import Agent, Crew, Task
18+
19+
# Inside task execution, call your TypeScript endpoint:
20+
# POST /api/dws/process { "operation": "extract_text", "path": "input.pdf" }
21+
```
22+
23+
This keeps CrewAI orchestration explicit while preserving a TypeScript-first application surface.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { NutrientClient } from "@nutrient-sdk/dws-client-typescript";
2+
import { ChatOpenAI } from "@langchain/openai";
3+
import { tool } from "@langchain/core/tools";
4+
5+
const client = new NutrientClient({
6+
apiKey: process.env.NUTRIENT_API_KEY ?? "nutr_sk_placeholder",
7+
});
8+
9+
const redactEmails = tool(
10+
async ({ path }) => {
11+
const response = await client.createRedactionsPreset(path, "email-address", "apply");
12+
return JSON.stringify(response);
13+
},
14+
{
15+
name: "redact_emails",
16+
description: "Redact email addresses from a document via Nutrient DWS.",
17+
}
18+
);
19+
20+
async function main() {
21+
const model = new ChatOpenAI({
22+
model: "gpt-4.1-mini",
23+
apiKey: process.env.OPENAI_API_KEY ?? "sk-placeholder",
24+
});
25+
26+
const response = await model.bindTools([redactEmails]).invoke(
27+
"Redact email addresses from ./assets/sample.pdf and summarize next steps."
28+
);
29+
30+
if (response.tool_calls?.length) {
31+
for (const call of response.tool_calls) {
32+
if (call.name === "redact_emails") {
33+
const args =
34+
typeof call.args === "object" && call.args !== null ? call.args : {};
35+
const toolResult = await redactEmails.invoke(args);
36+
console.log(toolResult);
37+
return;
38+
}
39+
}
40+
}
41+
42+
console.log(response.content);
43+
}
44+
45+
void main();
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { NutrientClient } from "@nutrient-sdk/dws-client-typescript";
2+
import { Agent, Runner, tool } from "@openai/agents";
3+
4+
const client = new NutrientClient({
5+
apiKey: process.env.NUTRIENT_API_KEY ?? "nutr_sk_placeholder",
6+
});
7+
8+
const extractText = tool({
9+
name: "extract_text",
10+
description: "Extract text from a document using Nutrient DWS.",
11+
parameters: {
12+
type: "object",
13+
properties: {
14+
path: { type: "string" },
15+
},
16+
required: ["path"],
17+
},
18+
async execute(input) {
19+
const result = await client.extractText(input.path);
20+
return JSON.stringify(result);
21+
},
22+
});
23+
24+
const agent = new Agent({
25+
name: "nutrient-openai-agents-typescript",
26+
instructions: "Use tools to process documents and summarize outcomes.",
27+
tools: [extractText],
28+
});
29+
30+
async function main() {
31+
const run = await Runner.run(
32+
agent,
33+
"Extract text from ./assets/sample.pdf and summarize key points."
34+
);
35+
console.log(run.finalOutput);
36+
}
37+
38+
void main();

0 commit comments

Comments
 (0)