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

google[minor]: Add audio tests and audio file for google genai and vertex #6553

Merged
merged 2 commits into from
Aug 16, 2024
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
10 changes: 5 additions & 5 deletions libs/langchain-google-genai/src/tests/chat_models.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,15 @@ async function fileToBase64(filePath: string): Promise<string> {
return base64String;
}

test.skip("Gemini can understand audio", async () => {
test("Gemini can understand audio", async () => {
// Update this with the correct path to an audio file on your machine.
const audioPath =
"/Users/bracesproul/code/lang-chain-ai/langchainjs/libs/langchain-google-gauth/src/tests/data/audio.mp3";
const audioMimeType = "audio/mp3";
const audioPath = "./src/tests/data/gettysburg10.wav";
const audioMimeType = "audio/wav";

const model = new ChatGoogleGenerativeAI({
model: "gemini-1.5-pro-latest",
model: "gemini-1.5-flash",
temperature: 0,
maxRetries: 0,
});

const audioBase64 = await fileToBase64(audioPath);
Expand Down
Binary file not shown.
49 changes: 49 additions & 0 deletions libs/langchain-google-vertexai/src/tests/chat_models.int.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { test } from "@jest/globals";
import fs from "fs/promises";
import { BaseLanguageModelInput } from "@langchain/core/language_models/base";
import { ChatPromptValue } from "@langchain/core/prompt_values";
import {
Expand All @@ -14,6 +15,10 @@ import {
import { tool } from "@langchain/core/tools";
import { z } from "zod";
import { concat } from "@langchain/core/utils/stream";
import {
ChatPromptTemplate,
MessagesPlaceholder,
} from "@langchain/core/prompts";
import { GeminiTool } from "../types.js";
import { ChatVertexAI } from "../chat_models.js";

Expand Down Expand Up @@ -352,3 +357,47 @@ test("ChatGoogleGenerativeAI can stream tools", async () => {
expect(toolCalls[0].name).toBe("current_weather_tool");
expect(toolCalls[0].args).toHaveProperty("location");
});

async function fileToBase64(filePath: string): Promise<string> {
const fileData = await fs.readFile(filePath);
const base64String = Buffer.from(fileData).toString("base64");
return base64String;
}

test("Gemini can understand audio", async () => {
// Update this with the correct path to an audio file on your machine.
const audioPath = "../langchain-google-genai/src/tests/data/gettysburg10.wav";
const audioMimeType = "audio/wav";

const model = new ChatVertexAI({
model: "gemini-1.5-flash",
temperature: 0,
maxRetries: 0,
});

const audioBase64 = await fileToBase64(audioPath);

const prompt = ChatPromptTemplate.fromMessages([
new MessagesPlaceholder("audio"),
]);

const chain = prompt.pipe(model);
const response = await chain.invoke({
audio: new HumanMessage({
content: [
{
type: "media",
mimeType: audioMimeType,
data: audioBase64,
},
{
type: "text",
text: "Summarize the content in this audio. ALso, what is the speaker's tone?",
},
],
}),
});

expect(typeof response.content).toBe("string");
expect((response.content as string).length).toBeGreaterThan(15);
});
Loading