fix(ts-oss): forward responseFormat to Gemini in generateResponse (#6468)

This commit is contained in:
Abhishek Chauhan
2026-07-23 19:48:33 +05:30
committed by GitHub
parent a71d7bdbe3
commit e6281ab724
2 changed files with 40 additions and 0 deletions
+31
View File
@@ -185,6 +185,37 @@ describe("GoogleLLM (unit)", () => {
expect(response.toolCalls[1].name).toBe("add_graph_memory");
});
// Regression: generateResponse accepted a responseFormat argument but never
// forwarded it, so Gemini was never told to emit JSON (parity with the Python
// SDK's mem0/llms/gemini.py, which sets response_mime_type/response_schema).
it("forwards json_object responseFormat as responseMimeType", async () => {
mockGenerateContent.mockResolvedValueOnce({
text: '{"facts": ["fact1"]}',
functionCalls: null,
});
const llm = new GoogleLLM({ apiKey: "test-key" });
await llm.generateResponse([{ role: "user", content: "Extract facts" }], {
type: "json_object",
});
const callArgs = mockGenerateContent.mock.calls[0][0];
expect(callArgs.config.responseMimeType).toBe("application/json");
});
it("does not set responseMimeType when no responseFormat is given", async () => {
mockGenerateContent.mockResolvedValueOnce({
text: "plain text",
functionCalls: null,
});
const llm = new GoogleLLM({ apiKey: "test-key" });
await llm.generateResponse([{ role: "user", content: "Hello" }]);
const callArgs = mockGenerateContent.mock.calls[0][0];
expect(callArgs.config.responseMimeType).toBeUndefined();
});
it("formats generateChat messages and joins Gemini response parts", async () => {
mockGenerateContent.mockResolvedValueOnce({
candidates: [