Skip to content

Commit

Permalink
fix(community): Fix interface of chat deployment IBM and add test for…
Browse files Browse the repository at this point in the history
… this case (#7666)
  • Loading branch information
FilipZmijewski authored Feb 11, 2025
1 parent b33a19f commit 5449925
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
4 changes: 3 additions & 1 deletion libs/langchain-community/src/chat_models/ibm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,11 @@ export interface WatsonxCallOptionsChat
}

export interface WatsonxCallOptionsDeployedChat
extends WatsonxCallDeployedParams,
extends Omit<BaseChatModelCallOptions, "stop">,
WatsonxCallDeployedParams,
WatsonxChatBasicOptions {
promptIndex?: number;
tool_choice?: TextChatParameterTools | string | "auto" | "any";
}

type ChatWatsonxToolType = BindToolsInput | TextChatParameterTools;
Expand Down
23 changes: 23 additions & 0 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,6 +12,10 @@ 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 {
BaseChatModel,
BaseChatModelCallOptions,
} from "@langchain/core/language_models/chat_models";
import { ChatWatsonx } from "../ibm.js";

describe("Tests for chat", () => {
Expand Down Expand Up @@ -713,6 +717,24 @@ describe("Tests for chat", () => {
expect(res.tool_calls[0].args.a).not.toBe(res.tool_calls[1].args.a);
expect(res.tool_calls[0].args.b).not.toBe(res.tool_calls[1].args.b);
});
test("React agent creation", async () => {
const model = new ChatWatsonx({
projectId: process.env.WATSONX_AI_PROJECT_ID,
serviceUrl: process.env.WATSONX_AI_SERVICE_URL as string,
watsonxAIApikey: process.env.WATSONX_AI_APIKEY,
watsonxAIAuthType: "iam",
version: "2024-05-31",
model: "mistralai/mistral-large",
});
const testModel = (
model: BaseChatModel<BaseChatModelCallOptions, AIMessageChunk>
) => {
// eslint-disable-next-line no-instanceof/no-instanceof
if (model instanceof BaseChatModel) return true;
else throw new Error("Wrong model passed");
};
expect(testModel(model)).toBeTruthy();
});
});

describe("Test withStructuredOutput usage", () => {
Expand Down Expand Up @@ -762,6 +784,7 @@ describe("Tests for chat", () => {
for await (const chunk of res) {
expect(typeof chunk).toBe("object");
object = chunk;
console.log(chunk);
}
expect("setup" in object).toBe(true);
expect("punchline" in object).toBe(true);
Expand Down

0 comments on commit 5449925

Please sign in to comment.