Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@langchain/google-common

Package Overview
Dependencies
Maintainers
5
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@langchain/google-common - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

52

dist/utils/common.js

@@ -21,2 +21,54 @@ import { isModelGemini, validateGeminiParams } from "./gemini.js";

ret.tools = options?.tools;
// Ensure tools are formatted properly for Gemini
const geminiTools = options?.tools
?.map((tool) => {
if ("function" in tool &&
// eslint-disable-next-line @typescript-eslint/no-explicit-any
"parameters" in tool.function) {
// Tool is in OpenAI format. Convert to Gemini then return.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const castTool = tool.function;
const cleanedParameters = castTool.parameters;
if ("$schema" in cleanedParameters) {
delete cleanedParameters.$schema;
}
if ("additionalProperties" in cleanedParameters) {
delete cleanedParameters.additionalProperties;
}
const toolInGeminiFormat = {
functionDeclarations: [
{
name: castTool.name,
description: castTool.description,
parameters: cleanedParameters,
},
],
};
return toolInGeminiFormat;
}
else if ("functionDeclarations" in tool) {
return tool;
}
else {
return null;
}
})
.filter((tool) => tool !== null);
const structuredOutputTools = options?.tools
?.map((tool) => {
if ("lc_namespace" in tool) {
return tool;
}
else {
return null;
}
})
.filter((tool) => tool !== null);
if (structuredOutputTools &&
structuredOutputTools.length > 0 &&
geminiTools &&
geminiTools.length > 0) {
throw new Error(`Cannot mix structured tools with Gemini tools.\nReceived ${structuredOutputTools.length} structured tools and ${geminiTools.length} Gemini tools.`);
}
ret.tools = geminiTools ?? structuredOutputTools;
return ret;

@@ -23,0 +75,0 @@ }

57

dist/utils/gemini.js

@@ -124,16 +124,35 @@ import { AIMessage, AIMessageChunk, } from "@langchain/core/messages";

}, "");
const content = JSON.parse(contentStr);
return [
{
role: "function",
parts: [
{
functionResponse: {
name: message.tool_call_id,
response: content,
try {
const content = JSON.parse(contentStr);
return [
{
role: "function",
parts: [
{
functionResponse: {
name: message.tool_call_id,
response: content,
},
},
},
],
},
];
],
},
];
}
catch (_) {
return [
{
role: "function",
parts: [
{
functionResponse: {
name: message.tool_call_id,
response: {
response: contentStr,
},
},
},
],
},
];
}
}

@@ -334,2 +353,14 @@ export function baseMessageToContent(message) {

const fields = partsToBaseMessageFields([part]);
if (typeof fields.content === "string") {
return new AIMessageChunk(fields);
}
else if (fields.content.every((item) => item.type === "text")) {
const newContent = fields.content
.map((item) => ("text" in item ? item.text : ""))
.join("");
return new AIMessageChunk({
...fields,
content: newContent,
});
}
return new AIMessageChunk(fields);

@@ -336,0 +367,0 @@ }

{
"name": "@langchain/google-common",
"version": "0.0.2",
"version": "0.0.3",
"description": "Core types and classes for Google services.",

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

Sorry, the diff of this file is not supported yet

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