@langchain/openai 0.0.5 → 0.0.6-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1 +1,100 @@
1
- # langchain-openai
1
+ # @langchain/openai
2
+
3
+ This package contains the LangChainJS integrations for OpenAI through their SDK.
4
+
5
+ ## Installation
6
+
7
+ ```bash npm2yarn
8
+ npm install @langchain/openai
9
+ ```
10
+
11
+ ## Chat Models
12
+
13
+ This package contains the `ChatOpenAI` class, which is the recommended way to interface with the OpenAI series of models.
14
+
15
+ To use, install the requirements, and configure your environment.
16
+
17
+ ```bash
18
+ export OPENAI_API_KEY=your-api-key
19
+ ```
20
+
21
+ Then initialize
22
+
23
+ ```typescript
24
+ import { ChatOpenAI } from "@langchain/openai";
25
+
26
+ const model = new ChatOpenAI({
27
+ apiKey: process.env.OPENAI_API_KEY,
28
+ modelName: "gpt-4-1106-preview",
29
+ });
30
+ const response = await model.invoke(new HumanMessage("Hello world!"));
31
+ ```
32
+
33
+ ### Streaming
34
+
35
+ ```typescript
36
+ import { ChatOpenAI } from "@langchain/openai";
37
+
38
+ const model = new ChatOpenAI({
39
+ apiKey: process.env.OPENAI_API_KEY,
40
+ modelName: "gpt-4-1106-preview",
41
+ });
42
+ const response = await model.stream(new HumanMessage("Hello world!"));
43
+ ```
44
+
45
+ ## Embeddings
46
+
47
+ This package also adds support for OpenAI's embeddings model.
48
+
49
+ ```typescript
50
+ import { OpenAIEmbeddings } from "@langchain/openai";
51
+
52
+ const embeddings = new OpenAIEmbeddings({
53
+ apiKey: process.env.OPENAI_API_KEY,
54
+ });
55
+ const res = await embeddings.embedQuery("Hello world");
56
+ ```
57
+
58
+ ## Development
59
+
60
+ To develop the OpenAI package, you'll need to follow these instructions:
61
+
62
+ ### Install dependencies
63
+
64
+ ```bash
65
+ yarn install
66
+ ```
67
+
68
+ ### Build the package
69
+
70
+ ```bash
71
+ yarn build
72
+ ```
73
+
74
+ Or from the repo root:
75
+
76
+ ```bash
77
+ yarn build --filter=@langchain/openai
78
+ ```
79
+
80
+ ### Run tests
81
+
82
+ Test files should live within a `tests/` file in the `src/` folder. Unit tests should end in `.test.ts` and integration tests should
83
+ end in `.int.test.ts`:
84
+
85
+ ```bash
86
+ $ yarn test
87
+ $ yarn test:int
88
+ ```
89
+
90
+ ### Lint & Format
91
+
92
+ Run the linter & formatter to ensure your code is up to standard:
93
+
94
+ ```bash
95
+ yarn lint && yarn format
96
+ ```
97
+
98
+ ### Adding new entrypoints
99
+
100
+ If you add a new file to be exported, either import & re-export from `src/index.ts`, or add it to `scripts/create-entrypoints.js` and run `yarn build` to generate the new entrypoint.
@@ -38,6 +38,7 @@ class OpenAIEmbeddings extends embeddings_1.Embeddings {
38
38
  writable: true,
39
39
  value: 512
40
40
  });
41
+ // TODO: Update to `false` on next minor release (see: https://github.com/langchain-ai/langchainjs/pull/3612)
41
42
  Object.defineProperty(this, "stripNewLines", {
42
43
  enumerable: true,
43
44
  configurable: true,
@@ -19,7 +19,8 @@ export interface OpenAIEmbeddingsParams extends EmbeddingsParams {
19
19
  batchSize?: number;
20
20
  /**
21
21
  * Whether to strip new lines from the input text. This is recommended by
22
- * OpenAI, but may not be suitable for all use cases.
22
+ * OpenAI for older models, but may not be suitable for all use cases.
23
+ * See: https://github.com/openai/openai-python/issues/418#issuecomment-1525939500
23
24
  */
24
25
  stripNewLines?: boolean;
25
26
  }
@@ -35,6 +35,7 @@ export class OpenAIEmbeddings extends Embeddings {
35
35
  writable: true,
36
36
  value: 512
37
37
  });
38
+ // TODO: Update to `false` on next minor release (see: https://github.com/langchain-ai/langchainjs/pull/3612)
38
39
  Object.defineProperty(this, "stripNewLines", {
39
40
  enumerable: true,
40
41
  configurable: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/openai",
3
- "version": "0.0.5",
3
+ "version": "0.0.6-rc.0",
4
4
  "description": "OpenAI integrations for LangChain.js",
5
5
  "type": "module",
6
6
  "engines": {
@@ -13,7 +13,8 @@
13
13
  "url": "git@github.com:langchain-ai/langchainjs.git"
14
14
  },
15
15
  "scripts": {
16
- "build": "yarn clean && yarn build:esm && yarn build:cjs && yarn build:scripts",
16
+ "build": "yarn run build:deps && yarn clean && yarn build:esm && yarn build:cjs && yarn build:scripts",
17
+ "build:deps": "yarn run turbo:command build --filter=@langchain/core",
17
18
  "build:esm": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist/",
18
19
  "build:cjs": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist-cjs/ -p tsconfig.cjs.json && node scripts/move-cjs-to-dist.js && rimraf dist-cjs",
19
20
  "build:watch": "node scripts/create-entrypoints.js && tsc --outDir dist/ --watch",
@@ -25,16 +26,16 @@
25
26
  "clean": "rimraf .turbo/ dist/ && NODE_OPTIONS=--max-old-space-size=4096 node scripts/create-entrypoints.js pre",
26
27
  "prepack": "yarn build",
27
28
  "release": "release-it --only-version --config .release-it.json",
28
- "test": "NODE_OPTIONS=--experimental-vm-modules jest --testPathIgnorePatterns=\\.int\\.test.ts --testTimeout 30000 --maxWorkers=50%",
29
- "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch --testPathIgnorePatterns=\\.int\\.test.ts",
30
- "test:single": "NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000",
29
+ "test": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules jest --testPathIgnorePatterns=\\.int\\.test.ts --testTimeout 30000 --maxWorkers=50%",
30
+ "test:watch": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules jest --watch --testPathIgnorePatterns=\\.int\\.test.ts",
31
+ "test:single": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000",
31
32
  "format": "prettier --write \"src\"",
32
33
  "format:check": "prettier --check \"src\""
33
34
  },
34
35
  "author": "LangChain",
35
36
  "license": "MIT",
36
37
  "dependencies": {
37
- "@langchain/core": "~0.1.0",
38
+ "@langchain/core": "~0.1.2-rc.0",
38
39
  "js-tiktoken": "^1.0.7",
39
40
  "openai": "^4.19.0",
40
41
  "zod": "^3.22.3",