@langchain/openai 0.0.11 → 0.0.12

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.
@@ -6,6 +6,7 @@ const messages_1 = require("@langchain/core/messages");
6
6
  const outputs_1 = require("@langchain/core/outputs");
7
7
  const env_1 = require("@langchain/core/utils/env");
8
8
  const chat_models_1 = require("@langchain/core/language_models/chat_models");
9
+ const function_calling_1 = require("@langchain/core/utils/function_calling");
9
10
  const azure_js_1 = require("./utils/azure.cjs");
10
11
  const openai_js_1 = require("./utils/openai.cjs");
11
12
  const openai_format_fndef_js_1 = require("./utils/openai-format-fndef.cjs");
@@ -420,7 +421,7 @@ class ChatOpenAI extends chat_models_1.BaseChatModel {
420
421
  functions: options?.functions,
421
422
  function_call: options?.function_call,
422
423
  tools: isStructuredToolArray(options?.tools)
423
- ? options?.tools.map(openai_js_1.formatToOpenAITool)
424
+ ? options?.tools.map(function_calling_1.convertToOpenAITool)
424
425
  : options?.tools,
425
426
  tool_choice: options?.tool_choice,
426
427
  response_format: options?.response_format,
@@ -3,8 +3,9 @@ import { AIMessage, AIMessageChunk, ChatMessage, ChatMessageChunk, FunctionMessa
3
3
  import { ChatGenerationChunk, } from "@langchain/core/outputs";
4
4
  import { getEnvironmentVariable } from "@langchain/core/utils/env";
5
5
  import { BaseChatModel, } from "@langchain/core/language_models/chat_models";
6
+ import { convertToOpenAITool } from "@langchain/core/utils/function_calling";
6
7
  import { getEndpoint } from "./utils/azure.js";
7
- import { wrapOpenAIClientError, formatToOpenAITool } from "./utils/openai.js";
8
+ import { wrapOpenAIClientError } from "./utils/openai.js";
8
9
  import { formatFunctionDefinitions, } from "./utils/openai-format-fndef.js";
9
10
  function extractGenericMessageCustomRole(message) {
10
11
  if (message.role !== "system" &&
@@ -416,7 +417,7 @@ export class ChatOpenAI extends BaseChatModel {
416
417
  functions: options?.functions,
417
418
  function_call: options?.function_call,
418
419
  tools: isStructuredToolArray(options?.tools)
419
- ? options?.tools.map(formatToOpenAITool)
420
+ ? options?.tools.map(convertToOpenAITool)
420
421
  : options?.tools,
421
422
  tool_choice: options?.tool_choice,
422
423
  response_format: options?.response_format,
@@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.formatToOpenAIAssistantTool = exports.formatToOpenAITool = exports.formatToOpenAIFunction = exports.wrapOpenAIClientError = void 0;
4
4
  const openai_1 = require("openai");
5
5
  const zod_to_json_schema_1 = require("zod-to-json-schema");
6
+ const function_calling_1 = require("@langchain/core/utils/function_calling");
7
+ Object.defineProperty(exports, "formatToOpenAIFunction", { enumerable: true, get: function () { return function_calling_1.convertToOpenAIFunction; } });
8
+ Object.defineProperty(exports, "formatToOpenAITool", { enumerable: true, get: function () { return function_calling_1.convertToOpenAITool; } });
6
9
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
10
  function wrapOpenAIClientError(e) {
8
11
  let error;
@@ -20,32 +23,6 @@ function wrapOpenAIClientError(e) {
20
23
  return error;
21
24
  }
22
25
  exports.wrapOpenAIClientError = wrapOpenAIClientError;
23
- /**
24
- * Formats a `StructuredTool` instance into a format that is compatible
25
- * with OpenAI's ChatCompletionFunctions. It uses the `zodToJsonSchema`
26
- * function to convert the schema of the `StructuredTool` into a JSON
27
- * schema, which is then used as the parameters for the OpenAI function.
28
- */
29
- function formatToOpenAIFunction(tool) {
30
- return {
31
- name: tool.name,
32
- description: tool.description,
33
- parameters: (0, zod_to_json_schema_1.zodToJsonSchema)(tool.schema),
34
- };
35
- }
36
- exports.formatToOpenAIFunction = formatToOpenAIFunction;
37
- function formatToOpenAITool(tool) {
38
- const schema = (0, zod_to_json_schema_1.zodToJsonSchema)(tool.schema);
39
- return {
40
- type: "function",
41
- function: {
42
- name: tool.name,
43
- description: tool.description,
44
- parameters: schema,
45
- },
46
- };
47
- }
48
- exports.formatToOpenAITool = formatToOpenAITool;
49
26
  function formatToOpenAIAssistantTool(tool) {
50
27
  return {
51
28
  type: "function",
@@ -1,13 +1,6 @@
1
1
  import { type OpenAI as OpenAIClient } from "openai";
2
2
  import type { StructuredToolInterface } from "@langchain/core/tools";
3
- import type { FunctionDefinition } from "@langchain/core/language_models/base";
3
+ import { convertToOpenAIFunction, convertToOpenAITool } from "@langchain/core/utils/function_calling";
4
4
  export declare function wrapOpenAIClientError(e: any): any;
5
- /**
6
- * Formats a `StructuredTool` instance into a format that is compatible
7
- * with OpenAI's ChatCompletionFunctions. It uses the `zodToJsonSchema`
8
- * function to convert the schema of the `StructuredTool` into a JSON
9
- * schema, which is then used as the parameters for the OpenAI function.
10
- */
11
- export declare function formatToOpenAIFunction(tool: StructuredToolInterface): FunctionDefinition;
12
- export declare function formatToOpenAITool(tool: StructuredToolInterface): OpenAIClient.Chat.ChatCompletionTool;
5
+ export { convertToOpenAIFunction as formatToOpenAIFunction, convertToOpenAITool as formatToOpenAITool, };
13
6
  export declare function formatToOpenAIAssistantTool(tool: StructuredToolInterface): OpenAIClient.Beta.AssistantCreateParams.AssistantToolsFunction;
@@ -1,5 +1,6 @@
1
1
  import { APIConnectionTimeoutError, APIUserAbortError, } from "openai";
2
2
  import { zodToJsonSchema } from "zod-to-json-schema";
3
+ import { convertToOpenAIFunction, convertToOpenAITool, } from "@langchain/core/utils/function_calling";
3
4
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
5
  export function wrapOpenAIClientError(e) {
5
6
  let error;
@@ -16,30 +17,7 @@ export function wrapOpenAIClientError(e) {
16
17
  }
17
18
  return error;
18
19
  }
19
- /**
20
- * Formats a `StructuredTool` instance into a format that is compatible
21
- * with OpenAI's ChatCompletionFunctions. It uses the `zodToJsonSchema`
22
- * function to convert the schema of the `StructuredTool` into a JSON
23
- * schema, which is then used as the parameters for the OpenAI function.
24
- */
25
- export function formatToOpenAIFunction(tool) {
26
- return {
27
- name: tool.name,
28
- description: tool.description,
29
- parameters: zodToJsonSchema(tool.schema),
30
- };
31
- }
32
- export function formatToOpenAITool(tool) {
33
- const schema = zodToJsonSchema(tool.schema);
34
- return {
35
- type: "function",
36
- function: {
37
- name: tool.name,
38
- description: tool.description,
39
- parameters: schema,
40
- },
41
- };
42
- }
20
+ export { convertToOpenAIFunction as formatToOpenAIFunction, convertToOpenAITool as formatToOpenAITool, };
43
21
  export function formatToOpenAIAssistantTool(tool) {
44
22
  return {
45
23
  type: "function",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/openai",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
4
4
  "description": "OpenAI integrations for LangChain.js",
5
5
  "type": "module",
6
6
  "engines": {
@@ -35,7 +35,7 @@
35
35
  "author": "LangChain",
36
36
  "license": "MIT",
37
37
  "dependencies": {
38
- "@langchain/core": "~0.1.9",
38
+ "@langchain/core": "~0.1.13",
39
39
  "js-tiktoken": "^1.0.7",
40
40
  "openai": "^4.24.2",
41
41
  "zod": "^3.22.3",