Skip to content

Commit

Permalink
Fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
FilipZmijewski committed Oct 17, 2024
1 parent fd7633d commit b4010cb
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 27 deletions.
2 changes: 1 addition & 1 deletion libs/langchain-community/src/chat_models/ibm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
29 changes: 10 additions & 19 deletions libs/langchain-community/src/chat_models/tests/ibm.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 = [
{
Expand All @@ -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"),
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 2 additions & 5 deletions libs/langchain-community/src/utils/ibm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit b4010cb

Please sign in to comment.