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.24 to 0.0.25

3

dist/chat_models.js

@@ -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

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