@langchain/openai
Advanced tools
Comparing version 0.0.24 to 0.0.25
@@ -816,4 +816,5 @@ import { OpenAI as OpenAIClient } from "openai"; | ||
else { | ||
functionName = schema.title ?? functionName; | ||
openAIFunctionDefinition = { | ||
name: schema.title ?? functionName, | ||
name: functionName, | ||
description: schema.description ?? "", | ||
@@ -820,0 +821,0 @@ parameters: schema, |
@@ -149,2 +149,39 @@ import { z } from "zod"; | ||
}); | ||
test("withStructuredOutput JSON schema", async () => { | ||
const model = new ChatOpenAI({ | ||
temperature: 0, | ||
modelName: "gpt-4-turbo-preview", | ||
}); | ||
const jsonSchema = { | ||
title: "calculator", | ||
description: "A simple calculator", | ||
type: "object", | ||
properties: { | ||
operation: { | ||
type: "string", | ||
enum: ["add", "subtract", "multiply", "divide"], | ||
}, | ||
number1: { type: "number" }, | ||
number2: { type: "number" }, | ||
}, | ||
}; | ||
const modelWithStructuredOutput = model.withStructuredOutput(jsonSchema); | ||
const prompt = ChatPromptTemplate.fromMessages([ | ||
"system", | ||
`You are VERY bad at math and must always use a calculator. | ||
Respond with a JSON object containing three keys: | ||
'operation': the type of operation to execute, either 'add', 'subtract', 'multiply' or 'divide', | ||
'number1': the first number to operate on, | ||
'number2': the second number to operate on. | ||
`, | ||
"human", | ||
"Please help me!! What is 2 + 2?", | ||
]); | ||
const chain = prompt.pipe(modelWithStructuredOutput); | ||
const result = await chain.invoke({}); | ||
console.log(result); | ||
expect("operation" in result).toBe(true); | ||
expect("number1" in result).toBe(true); | ||
expect("number2" in result).toBe(true); | ||
}); | ||
test("withStructuredOutput includeRaw true", async () => { | ||
@@ -151,0 +188,0 @@ const model = new ChatOpenAI({ |
{ | ||
"name": "@langchain/openai", | ||
"version": "0.0.24", | ||
"version": "0.0.25", | ||
"description": "OpenAI integrations for LangChain.js", | ||
@@ -5,0 +5,0 @@ "type": "module", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
290306
7466