@langchain/openai 0.1.0 → 0.1.2

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.
@@ -13,7 +13,7 @@ export declare class AzureChatOpenAI extends ChatOpenAI {
13
13
  } & BaseChatModelParams & {
14
14
  configuration?: ClientOptions & LegacyOpenAIInput;
15
15
  });
16
- protected getLsParams(options: this["ParsedCallOptions"]): LangSmithParams;
16
+ getLsParams(options: this["ParsedCallOptions"]): LangSmithParams;
17
17
  protected _getClientOptions(options: OpenAICoreRequestOptions | undefined): OpenAICoreRequestOptions;
18
18
  toJSON(): any;
19
19
  }
@@ -683,6 +683,13 @@ class ChatOpenAI extends chat_models_1.BaseChatModel {
683
683
  ...(part.finish_reason ? { finish_reason: part.finish_reason } : {}),
684
684
  ...(part.logprobs ? { logprobs: part.logprobs } : {}),
685
685
  };
686
+ if ((0, messages_1.isAIMessage)(generation.message)) {
687
+ generation.message.usage_metadata = {
688
+ input_tokens: tokenUsage.promptTokens ?? 0,
689
+ output_tokens: tokenUsage.completionTokens ?? 0,
690
+ total_tokens: tokenUsage.totalTokens ?? 0,
691
+ };
692
+ }
686
693
  generations.push(generation);
687
694
  }
688
695
  return {
@@ -106,7 +106,7 @@ export declare class ChatOpenAI<CallOptions extends ChatOpenAICallOptions = Chat
106
106
  },
107
107
  /** @deprecated */
108
108
  configuration?: ClientOptions & LegacyOpenAIInput);
109
- protected getLsParams(options: this["ParsedCallOptions"]): LangSmithParams;
109
+ getLsParams(options: this["ParsedCallOptions"]): LangSmithParams;
110
110
  bindTools(tools: (Record<string, unknown> | StructuredToolInterface)[], kwargs?: Partial<CallOptions>): Runnable<BaseLanguageModelInput, AIMessageChunk, CallOptions>;
111
111
  /**
112
112
  * Get the parameters used to invoke the model
@@ -679,6 +679,13 @@ export class ChatOpenAI extends BaseChatModel {
679
679
  ...(part.finish_reason ? { finish_reason: part.finish_reason } : {}),
680
680
  ...(part.logprobs ? { logprobs: part.logprobs } : {}),
681
681
  };
682
+ if (isAIMessage(generation.message)) {
683
+ generation.message.usage_metadata = {
684
+ input_tokens: tokenUsage.promptTokens ?? 0,
685
+ output_tokens: tokenUsage.completionTokens ?? 0,
686
+ total_tokens: tokenUsage.totalTokens ?? 0,
687
+ };
688
+ }
682
689
  generations.push(generation);
683
690
  }
684
691
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/openai",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "OpenAI integrations for LangChain.js",
5
5
  "type": "module",
6
6
  "engines": {
@@ -16,26 +16,21 @@
16
16
  "scripts": {
17
17
  "build": "yarn turbo:command build:internal --filter=@langchain/openai",
18
18
  "build:internal": "yarn lc-build:v2 --create-entrypoints --pre --tree-shaking",
19
- "build:deps": "yarn run turbo:command build --filter=@langchain/core",
20
- "build:esm": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist/",
21
- "build:cjs": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist-cjs/ -p tsconfig.cjs.json && yarn move-cjs-to-dist && rimraf dist-cjs",
22
- "build:watch": "yarn create-entrypoints && tsc --outDir dist/ --watch",
23
- "build:scripts": "yarn create-entrypoints && yarn check-tree-shaking",
24
19
  "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/",
25
20
  "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts",
26
21
  "lint": "yarn lint:eslint && yarn lint:dpdm",
27
22
  "lint:fix": "yarn lint:eslint --fix && yarn lint:dpdm",
28
23
  "clean": "rm -rf .turbo dist/",
29
24
  "prepack": "yarn build",
30
- "test": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules jest --testPathIgnorePatterns=\\.int\\.test.ts --testTimeout 30000 --maxWorkers=50%",
31
- "test:watch": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules jest --watch --testPathIgnorePatterns=\\.int\\.test.ts",
32
- "test:single": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000",
25
+ "test": "NODE_OPTIONS=--experimental-vm-modules jest --testPathIgnorePatterns=\\.int\\.test.ts --testTimeout 30000 --maxWorkers=50%",
26
+ "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch --testPathIgnorePatterns=\\.int\\.test.ts",
27
+ "test:single": "NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000",
33
28
  "test:int": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%",
29
+ "test:standard:unit": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.standard\\.test.ts --testTimeout 100000 --maxWorkers=50%",
30
+ "test:standard:int": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.standard\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%",
31
+ "test:standard": "yarn test:standard:unit && yarn test:standard:int",
34
32
  "format": "prettier --config .prettierrc --write \"src\"",
35
- "format:check": "prettier --config .prettierrc --check \"src\"",
36
- "move-cjs-to-dist": "yarn lc-build --config ./langchain.config.js --move-cjs-dist",
37
- "create-entrypoints": "yarn lc-build --config ./langchain.config.js --create-entrypoints",
38
- "check-tree-shaking": "yarn lc-build --config ./langchain.config.js --tree-shaking"
33
+ "format:check": "prettier --config .prettierrc --check \"src\""
39
34
  },
40
35
  "author": "LangChain",
41
36
  "license": "MIT",
@@ -50,6 +45,7 @@
50
45
  "@azure/identity": "^4.2.0",
51
46
  "@jest/globals": "^29.5.0",
52
47
  "@langchain/scripts": "~0.0.14",
48
+ "@langchain/standard-tests": "workspace:*",
53
49
  "@swc/core": "^1.3.90",
54
50
  "@swc/jest": "^0.2.29",
55
51
  "dpdm": "^3.12.0",