@langchain/openai 0.0.5 → 0.0.6

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,128 @@
1
- # langchain-openai
1
+ # @langchain/openai
2
+
3
+ This package contains the LangChain.js integrations for OpenAI through their SDK.
4
+
5
+ ## Installation
6
+
7
+ ```bash npm2yarn
8
+ npm install @langchain/openai
9
+ ```
10
+
11
+ This package, along with the main LangChain package, depends on [`@langchain/core`](https://npmjs.com/package/@langchain/core/).
12
+ If you are using this package with other LangChain packages, you should make sure that all of the packages depend on the same instance of @langchain/core.
13
+ You can do so by adding appropriate fields to your project's `package.json` like this:
14
+
15
+ ```json
16
+ {
17
+ "name": "your-project",
18
+ "version": "0.0.0",
19
+ "dependencies": {
20
+ "@langchain/openai": "^0.0.0",
21
+ "langchain": "0.0.207"
22
+ },
23
+ "resolutions": {
24
+ "@langchain/core": "0.1.1"
25
+ },
26
+ "overrides": {
27
+ "@langchain/core": "0.1.1"
28
+ },
29
+ "pnpm": {
30
+ "overrides": {
31
+ "@langchain/core": "0.1.1"
32
+ }
33
+ }
34
+ }
35
+ ```
36
+
37
+ The field you need depends on the package manager you're using, but we recommend adding a field for the common `yarn`, `npm`, and `pnpm` to maximize compatibility.
38
+
39
+ ## Chat Models
40
+
41
+ This package contains the `ChatOpenAI` class, which is the recommended way to interface with the OpenAI series of models.
42
+
43
+ To use, install the requirements, and configure your environment.
44
+
45
+ ```bash
46
+ export OPENAI_API_KEY=your-api-key
47
+ ```
48
+
49
+ Then initialize
50
+
51
+ ```typescript
52
+ import { ChatOpenAI } from "@langchain/openai";
53
+
54
+ const model = new ChatOpenAI({
55
+ apiKey: process.env.OPENAI_API_KEY,
56
+ modelName: "gpt-4-1106-preview",
57
+ });
58
+ const response = await model.invoke(new HumanMessage("Hello world!"));
59
+ ```
60
+
61
+ ### Streaming
62
+
63
+ ```typescript
64
+ import { ChatOpenAI } from "@langchain/openai";
65
+
66
+ const model = new ChatOpenAI({
67
+ apiKey: process.env.OPENAI_API_KEY,
68
+ modelName: "gpt-4-1106-preview",
69
+ });
70
+ const response = await model.stream(new HumanMessage("Hello world!"));
71
+ ```
72
+
73
+ ## Embeddings
74
+
75
+ This package also adds support for OpenAI's embeddings model.
76
+
77
+ ```typescript
78
+ import { OpenAIEmbeddings } from "@langchain/openai";
79
+
80
+ const embeddings = new OpenAIEmbeddings({
81
+ apiKey: process.env.OPENAI_API_KEY,
82
+ });
83
+ const res = await embeddings.embedQuery("Hello world");
84
+ ```
85
+
86
+ ## Development
87
+
88
+ To develop the OpenAI package, you'll need to follow these instructions:
89
+
90
+ ### Install dependencies
91
+
92
+ ```bash
93
+ yarn install
94
+ ```
95
+
96
+ ### Build the package
97
+
98
+ ```bash
99
+ yarn build
100
+ ```
101
+
102
+ Or from the repo root:
103
+
104
+ ```bash
105
+ yarn build --filter=@langchain/openai
106
+ ```
107
+
108
+ ### Run tests
109
+
110
+ Test files should live within a `tests/` file in the `src/` folder. Unit tests should end in `.test.ts` and integration tests should
111
+ end in `.int.test.ts`:
112
+
113
+ ```bash
114
+ $ yarn test
115
+ $ yarn test:int
116
+ ```
117
+
118
+ ### Lint & Format
119
+
120
+ Run the linter & formatter to ensure your code is up to standard:
121
+
122
+ ```bash
123
+ yarn lint && yarn format
124
+ ```
125
+
126
+ ### Adding new entrypoints
127
+
128
+ 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",
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",
38
39
  "js-tiktoken": "^1.0.7",
39
40
  "openai": "^4.19.0",
40
41
  "zod": "^3.22.3",