Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(community): Fix interface of chat deployment IBM and add test for this case #7666

Merged
merged 7 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading