From b4010cb6ebb0b32b3ce4c26ccb08cc187e284252 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20=C5=BBmijewski?= Date: Thu, 17 Oct 2024 13:56:43 +0200 Subject: [PATCH] Fix bugs --- .../src/chat_models/ibm.ts | 2 +- .../src/chat_models/tests/ibm.int.test.ts | 29 +++++++------------ .../tests/ibm.standard.int.test.ts | 2 +- .../chat_models/tests/ibm.standard.test.ts | 2 +- libs/langchain-community/src/utils/ibm.ts | 7 ++--- 5 files changed, 15 insertions(+), 27 deletions(-) diff --git a/libs/langchain-community/src/chat_models/ibm.ts b/libs/langchain-community/src/chat_models/ibm.ts index e30efb7ee129..5db1d3d3499f 100644 --- a/libs/langchain-community/src/chat_models/ibm.ts +++ b/libs/langchain-community/src/chat_models/ibm.ts @@ -63,7 +63,7 @@ import { import { isZodSchema } from "@langchain/core/utils/types"; import { zodToJsonSchema } from "zod-to-json-schema"; import { NewTokenIndices } from "@langchain/core/callbacks/base"; -import { WatsonxAuth, WatsonxParams } from "../types/watsonx_ai.js"; +import { WatsonxAuth, WatsonxParams } from "../types/ibm.js"; import { _convertToolCallIdToMistralCompatible, authenticateAndSetInstance, diff --git a/libs/langchain-community/src/chat_models/tests/ibm.int.test.ts b/libs/langchain-community/src/chat_models/tests/ibm.int.test.ts index 77b81dc72631..8c922e1f0ad0 100644 --- a/libs/langchain-community/src/chat_models/tests/ibm.int.test.ts +++ b/libs/langchain-community/src/chat_models/tests/ibm.int.test.ts @@ -12,25 +12,11 @@ import { LLMResult } from "@langchain/core/outputs"; import { ChatPromptTemplate } from "@langchain/core/prompts"; import { tool } from "@langchain/core/tools"; import { NewTokenIndices } from "@langchain/core/callbacks/base"; -import { readFile } from "node:fs"; +import * as fs from "node:fs/promises"; +import { fileURLToPath } from "node:url"; +import * as path from "node:path"; import { ChatWatsonx } from "../ibm.js"; -const loadFile = () => { - return new Promise((resolve, reject) => { - readFile( - "/Users/filipzmijewski/Desktop/langchainjs/libs/langchain-community/src/chat_models/tests/data/hotdog.jpg", - (err, data) => { - if (err) { - console.error("Error reading file:", err); - reject(err); - } - const base64String = data.toString("base64"); - resolve(base64String); - } - ); - }); -}; - describe("Tests for chat", () => { describe("Test ChatWatsonx invoke and generate", () => { test("Basic invoke", async () => { @@ -827,7 +813,11 @@ describe("Tests for chat", () => { projectId: process.env.WATSONX_AI_PROJECT_ID ?? "testString", max_new_tokens: 100, }); - const encodedString = await loadFile(); + const __filename = fileURLToPath(import.meta.url); + const __dirname = path.dirname(__filename); + const encodedString = await fs.readFile( + path.join(__dirname, "/data/hotdog.jpg") + ); const question = "What is on the picture"; const messages = [ { @@ -840,7 +830,8 @@ describe("Tests for chat", () => { { type: "image_url", image_url: { - url: "data:image/jpeg;base64," + encodedString, + url: + "data:image/jpeg;base64," + encodedString.toString("base64"), }, }, ], diff --git a/libs/langchain-community/src/chat_models/tests/ibm.standard.int.test.ts b/libs/langchain-community/src/chat_models/tests/ibm.standard.int.test.ts index 347c1c0f54f5..03b8eb4b3351 100644 --- a/libs/langchain-community/src/chat_models/tests/ibm.standard.int.test.ts +++ b/libs/langchain-community/src/chat_models/tests/ibm.standard.int.test.ts @@ -8,7 +8,7 @@ import { WatsonxCallOptionsChat, WatsonxCallParams, } from "../ibm.js"; -import { WatsonxAuth } from "../../types/watsonx_ai.js"; +import { WatsonxAuth } from "../../types/ibm.js"; class ChatWatsonxStandardIntegrationTests extends ChatModelIntegrationTests< WatsonxCallOptionsChat, diff --git a/libs/langchain-community/src/chat_models/tests/ibm.standard.test.ts b/libs/langchain-community/src/chat_models/tests/ibm.standard.test.ts index adac4cee9a14..6c7ab7d5576a 100644 --- a/libs/langchain-community/src/chat_models/tests/ibm.standard.test.ts +++ b/libs/langchain-community/src/chat_models/tests/ibm.standard.test.ts @@ -9,7 +9,7 @@ import { WatsonxCallOptionsChat, WatsonxCallParams, } from "../ibm.js"; -import { WatsonxAuth } from "../../types/watsonx_ai.js"; +import { WatsonxAuth } from "../../types/ibm.js"; class ChatWatsonxStandardTests extends ChatModelUnitTests< WatsonxCallOptionsChat, diff --git a/libs/langchain-community/src/utils/ibm.ts b/libs/langchain-community/src/utils/ibm.ts index a218c0dc6fe7..acbb86f1a304 100644 --- a/libs/langchain-community/src/utils/ibm.ts +++ b/libs/langchain-community/src/utils/ibm.ts @@ -4,19 +4,16 @@ import { BearerTokenAuthenticator, CloudPakForDataAuthenticator, } from "ibm-cloud-sdk-core"; -import { WatsonxAuth, WatsonxInit } from "../types/ibm.js"; import { JsonOutputKeyToolsParserParams, JsonOutputToolsParser, } from "@langchain/core/output_parsers/openai_tools"; -import { - BaseLLMOutputParser, - OutputParserException, -} from "@langchain/core/output_parsers"; +import { OutputParserException } from "@langchain/core/output_parsers"; import { z } from "zod"; import { ChatGeneration } from "@langchain/core/outputs"; import { AIMessageChunk } from "@langchain/core/messages"; import { ToolCall } from "@langchain/core/messages/tool"; +import { WatsonxAuth, WatsonxInit } from "../types/ibm.js"; export const authenticateAndSetInstance = ({ watsonxAIApikey,