Skip to content

Commit

Permalink
core[minor], mistralai[patch], openai[patch]: Warn when using beta me…
Browse files Browse the repository at this point in the history
…thod (#4592)

* core[minor], mistralai[patch], openai[patch]: Warn when using beta methods

* rm build artifacts

* cr

* chore: lint files

* Apply suggestions from code review

* cr

* change warning to info
  • Loading branch information
bracesproul authored Feb 29, 2024
1 parent add4863 commit de00f99
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/core_docs/docs/integrations/chat/mistral.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ import ToolCalling from "@examples/models/chat/chat_mistralai_tools.ts";

### `.withStructuredOutput({ ... })`

:::info
The `.withStructuredOutput` method is in beta. It is actively being worked on, so the API may change.
:::

Using the `.withStructuredOutput` method, you can easily make the LLM return structured output, given only a Zod or JSON schema:

:::note
Expand Down
4 changes: 4 additions & 0 deletions docs/core_docs/docs/integrations/chat/openai.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ import OpenAITools from "@examples/models/chat/integration_openai_tool_calls.ts"

### `.withStructuredOutput({ ... })`

:::info
The `.withStructuredOutput` method is in beta. It is actively being worked on, so the API may change.
:::

You can also use the `.withStructuredOutput({ ... })` method to coerce `ChatOpenAI` into returning a structured output.

The method allows for passing in either a Zod object, or a valid JSON schema (like what is returned from [`zodToJsonSchema`](https://www.npmjs.com/package/zod-to-json-schema)).
Expand Down
4 changes: 4 additions & 0 deletions langchain-core/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ utils/types.cjs
utils/types.js
utils/types.d.ts
utils/types.d.cts
utils/beta_warning.cjs
utils/beta_warning.js
utils/beta_warning.d.ts
utils/beta_warning.d.cts
vectorstores.cjs
vectorstores.js
vectorstores.d.ts
Expand Down
1 change: 1 addition & 0 deletions langchain-core/langchain.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export const config = {
"utils/testing": "utils/testing/index",
"utils/tiktoken": "utils/tiktoken",
"utils/types": "utils/types",
"utils/beta_warning": "utils/beta_warning",
vectorstores: "vectorstores",
},
tsConfigPath: resolve("./tsconfig.json"),
Expand Down
13 changes: 13 additions & 0 deletions langchain-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,15 @@
"import": "./utils/types.js",
"require": "./utils/types.cjs"
},
"./utils/beta_warning": {
"types": {
"import": "./utils/beta_warning.d.ts",
"require": "./utils/beta_warning.d.cts",
"default": "./utils/beta_warning.d.ts"
},
"import": "./utils/beta_warning.js",
"require": "./utils/beta_warning.cjs"
},
"./vectorstores": {
"types": {
"import": "./vectorstores.d.ts",
Expand Down Expand Up @@ -729,6 +738,10 @@
"utils/types.js",
"utils/types.d.ts",
"utils/types.d.cts",
"utils/beta_warning.cjs",
"utils/beta_warning.js",
"utils/beta_warning.d.ts",
"utils/beta_warning.d.cts",
"vectorstores.cjs",
"vectorstores.js",
"vectorstores.d.ts",
Expand Down
9 changes: 9 additions & 0 deletions langchain-core/src/utils/beta_warning.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Util function for logging a warning when a method is called.
* @param {string} func The name of the function that is in beta.
*/
export function betaWarning(func: string) {
console.warn(
`The function '${func}' is in beta. It is actively being worked on, so the API may change.`
);
}
2 changes: 2 additions & 0 deletions libs/langchain-mistralai/src/chat_models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
RunnableSequence,
} from "@langchain/core/runnables";
import { zodToJsonSchema } from "zod-to-json-schema";
import { betaWarning } from "@langchain/core/utils/beta_warning";

interface TokenUsage {
completionTokens?: number;
Expand Down Expand Up @@ -602,6 +603,7 @@ export class ChatMistralAI<
parsed: RunOutput;
}
> {
betaWarning("withStructuredOutput");
let llm: Runnable<BaseLanguageModelInput>;
let outputParser: JsonOutputKeyToolsParser | JsonOutputParser<RunOutput>;

Expand Down
2 changes: 2 additions & 0 deletions libs/langchain-openai/src/chat_models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
import { JsonOutputParser } from "@langchain/core/output_parsers";
import { JsonOutputKeyToolsParser } from "@langchain/core/output_parsers/openai_tools";
import { zodToJsonSchema } from "zod-to-json-schema";
import { betaWarning } from "@langchain/core/utils/beta_warning";
import type {
AzureOpenAIInput,
OpenAICallOptions,
Expand Down Expand Up @@ -928,6 +929,7 @@ export class ChatOpenAI<
parsed: RunOutput;
}
> {
betaWarning("withStructuredOutput");
let llm: Runnable<BaseLanguageModelInput>;
let outputParser: JsonOutputKeyToolsParser | JsonOutputParser<RunOutput>;

Expand Down

0 comments on commit de00f99

Please sign in to comment.