@langchain/openai 0.4.0 → 0.4.1
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.
|
@@ -616,5 +616,15 @@ class AzureChatOpenAI extends chat_models_js_1.ChatOpenAI {
|
|
|
616
616
|
}
|
|
617
617
|
return json;
|
|
618
618
|
}
|
|
619
|
+
withStructuredOutput(outputSchema, config) {
|
|
620
|
+
const ensuredConfig = { ...config };
|
|
621
|
+
// Not all Azure gpt-4o deployments models support jsonSchema yet
|
|
622
|
+
if (this.model.startsWith("gpt-4o")) {
|
|
623
|
+
if (ensuredConfig?.method === undefined) {
|
|
624
|
+
ensuredConfig.method = "functionCalling";
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
return super.withStructuredOutput(outputSchema, ensuredConfig);
|
|
628
|
+
}
|
|
619
629
|
}
|
|
620
630
|
exports.AzureChatOpenAI = AzureChatOpenAI;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { type ClientOptions } from "openai";
|
|
2
2
|
import { LangSmithParams, type BaseChatModelParams } from "@langchain/core/language_models/chat_models";
|
|
3
|
-
import {
|
|
3
|
+
import { BaseLanguageModelInput } from "@langchain/core/language_models/base";
|
|
4
|
+
import { BaseMessage } from "@langchain/core/messages";
|
|
5
|
+
import { Runnable } from "@langchain/core/runnables";
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import { ChatOpenAI, ChatOpenAIStructuredOutputMethodOptions } from "../chat_models.js";
|
|
4
8
|
import { AzureOpenAIInput, OpenAIChatInput, OpenAICoreRequestOptions } from "../types.js";
|
|
5
9
|
export type { AzureOpenAIInput };
|
|
6
10
|
/**
|
|
@@ -439,4 +443,13 @@ export declare class AzureChatOpenAI extends ChatOpenAI {
|
|
|
439
443
|
getLsParams(options: this["ParsedCallOptions"]): LangSmithParams;
|
|
440
444
|
protected _getClientOptions(options: OpenAICoreRequestOptions | undefined): OpenAICoreRequestOptions;
|
|
441
445
|
toJSON(): any;
|
|
446
|
+
withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: z.ZodType<RunOutput> | Record<string, any>, config?: ChatOpenAIStructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;
|
|
447
|
+
withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: z.ZodType<RunOutput> | Record<string, any>, config?: ChatOpenAIStructuredOutputMethodOptions<true>): Runnable<BaseLanguageModelInput, {
|
|
448
|
+
raw: BaseMessage;
|
|
449
|
+
parsed: RunOutput;
|
|
450
|
+
}>;
|
|
451
|
+
withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: z.ZodType<RunOutput> | Record<string, any>, config?: ChatOpenAIStructuredOutputMethodOptions<boolean>): Runnable<BaseLanguageModelInput, RunOutput> | Runnable<BaseLanguageModelInput, {
|
|
452
|
+
raw: BaseMessage;
|
|
453
|
+
parsed: RunOutput;
|
|
454
|
+
}>;
|
|
442
455
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AzureOpenAI as AzureOpenAIClient } from "openai";
|
|
2
2
|
import { getEnvironmentVariable } from "@langchain/core/utils/env";
|
|
3
|
-
import { ChatOpenAI } from "../chat_models.js";
|
|
3
|
+
import { ChatOpenAI, } from "../chat_models.js";
|
|
4
4
|
import { getEndpoint } from "../utils/azure.js";
|
|
5
5
|
/**
|
|
6
6
|
* Azure OpenAI chat model integration.
|
|
@@ -613,4 +613,14 @@ export class AzureChatOpenAI extends ChatOpenAI {
|
|
|
613
613
|
}
|
|
614
614
|
return json;
|
|
615
615
|
}
|
|
616
|
+
withStructuredOutput(outputSchema, config) {
|
|
617
|
+
const ensuredConfig = { ...config };
|
|
618
|
+
// Not all Azure gpt-4o deployments models support jsonSchema yet
|
|
619
|
+
if (this.model.startsWith("gpt-4o")) {
|
|
620
|
+
if (ensuredConfig?.method === undefined) {
|
|
621
|
+
ensuredConfig.method = "functionCalling";
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
return super.withStructuredOutput(outputSchema, ensuredConfig);
|
|
625
|
+
}
|
|
616
626
|
}
|
package/dist/chat_models.d.ts
CHANGED
|
@@ -749,4 +749,8 @@ export declare class ChatOpenAI<CallOptions extends ChatOpenAICallOptions = Chat
|
|
|
749
749
|
raw: BaseMessage;
|
|
750
750
|
parsed: RunOutput;
|
|
751
751
|
}>;
|
|
752
|
+
withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: z.ZodType<RunOutput> | Record<string, any>, config?: ChatOpenAIStructuredOutputMethodOptions<boolean>): Runnable<BaseLanguageModelInput, RunOutput> | Runnable<BaseLanguageModelInput, {
|
|
753
|
+
raw: BaseMessage;
|
|
754
|
+
parsed: RunOutput;
|
|
755
|
+
}>;
|
|
752
756
|
}
|