Socket
Socket
Sign inDemoInstall

@langchain/openai

Package Overview
Dependencies
Maintainers
5
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@langchain/openai - npm Package Compare versions

Comparing version 0.0.20 to 0.0.21

22

dist/chat_models.js

@@ -761,3 +761,3 @@ import { OpenAI as OpenAIClient } from "openai";

else {
const functionName = name ?? "extract";
let functionName = name ?? "extract";
// Is function calling

@@ -791,2 +791,16 @@ if (isZodSchema(schema)) {

else {
let openAIFunctionDefinition;
if (typeof schema.name === "string" &&
typeof schema.parameters === "object" &&
schema.parameters != null) {
openAIFunctionDefinition = schema;
functionName = schema.name;
}
else {
openAIFunctionDefinition = {
name: functionName,
description: schema.description ?? "",
parameters: schema,
};
}
llm = this.bind({

@@ -796,7 +810,3 @@ tools: [

type: "function",
function: {
name: functionName,
description: schema.description,
parameters: schema,
},
function: openAIFunctionDefinition,
},

@@ -803,0 +813,0 @@ ],

@@ -90,2 +90,29 @@ import { z } from "zod";

});
test("withStructuredOutput OpenAI function definition function calling", async () => {
const model = new ChatOpenAI({
temperature: 0,
modelName: "gpt-4-turbo-preview",
});
const calculatorSchema = z.object({
operation: z.enum(["add", "subtract", "multiply", "divide"]),
number1: z.number(),
number2: z.number(),
});
const modelWithStructuredOutput = model.withStructuredOutput({
name: "calculator",
parameters: zodToJsonSchema(calculatorSchema),
});
const prompt = ChatPromptTemplate.fromMessages([
"system",
`You are VERY bad at math and must always use a calculator.`,
"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 JSON schema JSON mode", async () => {

@@ -92,0 +119,0 @@ const model = new ChatOpenAI({

{
"name": "@langchain/openai",
"version": "0.0.20",
"version": "0.0.21",
"description": "OpenAI integrations for LangChain.js",

@@ -5,0 +5,0 @@ "type": "module",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc