Skip to content

Commit 37f6974

Browse files
committed
Fix framework quickstart env loading and LangChain schema
1 parent bc68e7e commit 37f6974

3 files changed

Lines changed: 28 additions & 4 deletions

File tree

examples/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ To run framework integration sketches:
9999
Install optional framework dependencies first:
100100

101101
```bash
102-
npm install @openai/agents @langchain/openai @langchain/core
102+
npm install @openai/agents @langchain/openai @langchain/core zod
103103
```
104104

105105
```bash

examples/src/framework_langchain.mjs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1+
import "dotenv/config";
12
import { NutrientClient } from "@nutrient-sdk/dws-client-typescript";
23
import { ChatOpenAI } from "@langchain/openai";
34
import { tool } from "@langchain/core/tools";
5+
import { z } from "zod";
6+
7+
const nutrientApiKey = process.env.NUTRIENT_API_KEY;
8+
if (!nutrientApiKey) {
9+
throw new Error("Missing NUTRIENT_API_KEY. Add it to examples/.env before running.");
10+
}
11+
12+
if (!process.env.OPENAI_API_KEY) {
13+
throw new Error("Missing OPENAI_API_KEY. Add it to examples/.env before running.");
14+
}
415

516
const client = new NutrientClient({
6-
apiKey: process.env.NUTRIENT_API_KEY ?? "nutr_sk_placeholder",
17+
apiKey: nutrientApiKey,
718
});
819

920
const redactEmails = tool(
@@ -14,13 +25,16 @@ const redactEmails = tool(
1425
{
1526
name: "redact_emails",
1627
description: "Redact email addresses from a document via Nutrient DWS.",
28+
schema: z.object({
29+
path: z.string().describe("Local path to the input PDF file."),
30+
}),
1731
}
1832
);
1933

2034
async function main() {
2135
const model = new ChatOpenAI({
2236
model: "gpt-4.1-mini",
23-
apiKey: process.env.OPENAI_API_KEY ?? "sk-placeholder",
37+
apiKey: process.env.OPENAI_API_KEY,
2438
});
2539

2640
const response = await model.bindTools([redactEmails]).invoke(

examples/src/framework_openai_agents.mjs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1+
import "dotenv/config";
12
import { NutrientClient } from "@nutrient-sdk/dws-client-typescript";
23
import { Agent, Runner, tool } from "@openai/agents";
34

5+
const nutrientApiKey = process.env.NUTRIENT_API_KEY;
6+
if (!nutrientApiKey) {
7+
throw new Error("Missing NUTRIENT_API_KEY. Add it to examples/.env before running.");
8+
}
9+
10+
if (!process.env.OPENAI_API_KEY) {
11+
throw new Error("Missing OPENAI_API_KEY. Add it to examples/.env before running.");
12+
}
13+
414
const client = new NutrientClient({
5-
apiKey: process.env.NUTRIENT_API_KEY ?? "nutr_sk_placeholder",
15+
apiKey: nutrientApiKey,
616
});
717

818
const extractText = tool({

0 commit comments

Comments
 (0)