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(gemini): use function role for message contains tool-result #1634

Merged
merged 2 commits into from
Feb 10, 2025

Conversation

thucpn
Copy link
Collaborator

@thucpn thucpn commented Feb 10, 2025

Error: Content with role 'user' can't contain 'functionResponse' part

Chat History when debugging:

const chatHistory = [
	{ role: "user", parts: [{ text: "How much is 5 + 5? then divide by 2" }] },
	{ role: "model", parts: [{ functionCall: { name: "sumNumbers", args: { a: 5, b: 5 } } }] },
	{ role: "user", parts: [{ functionResponse: { name: "sumNumbers", response: { result: "10" } } }] },
	{ role: "model", parts: [{ functionCall: { name: "divideNumbers", args: { a: 10, b: 2 } } }] }
];

VALID_PARTS_PER_ROLE from @google/generative-ai package
https://github.com/google-gemini/generative-ai-js/blob/2df2af03bb07dcda23b07af1a7135a8b461ae64e/src/methods/chat-session-helpers.ts#L34

const VALID_PARTS_PER_ROLE = {
	user: ["text", "inlineData"],
	function: ["functionResponse"],
	model: ["text", "functionCall", "executableCode", "codeExecutionResult"],
	system: ["text"],
};

Copy link

changeset-bot bot commented Feb 10, 2025

🦋 Changeset detected

Latest commit: 65a0bcf

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@llamaindex/google Patch
llamaindex Patch
@llamaindex/unit-test Patch
@llamaindex/doc Patch
@llamaindex/cloudflare-worker-agent-test Patch
@llamaindex/next-agent-test Patch
@llamaindex/nextjs-edge-runtime-test Patch
@llamaindex/next-node-runtime-test Patch
@llamaindex/waku-query-engine-test Patch
@llamaindex/autotool Patch
@llamaindex/experimental Patch
@llamaindex/autotool-01-node-example Patch
@llamaindex/autotool-02-next-example Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Feb 10, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
llamaindex-ts-doc ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 10, 2025 5:57am

Copy link

pkg-pr-new bot commented Feb 10, 2025

Open in Stackblitz

@llamaindex/autotool

npm i https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/autotool@1634

@llamaindex/cloud

npm i https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/cloud@1634

@llamaindex/community

npm i https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/community@1634

@llamaindex/core

npm i https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/core@1634

@llamaindex/env

npm i https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/env@1634

llamaindex

npm i https://pkg.pr.new/run-llama/LlamaIndexTS/llamaindex@1634

@llamaindex/experimental

npm i https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/experimental@1634

@llamaindex/node-parser

npm i https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/node-parser@1634

@llamaindex/readers

npm i https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/readers@1634

@llamaindex/wasm-tools

npm i https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/wasm-tools@1634

@llamaindex/workflow

npm i https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/workflow@1634

@llamaindex/anthropic

npm i https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/anthropic@1634

@llamaindex/clip

npm i https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/clip@1634

@llamaindex/cohere

npm i https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/cohere@1634

@llamaindex/deepinfra

npm i https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/deepinfra@1634

@llamaindex/google

npm i https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/google@1634

@llamaindex/groq

npm i https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/groq@1634

@llamaindex/huggingface

npm i https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/huggingface@1634

@llamaindex/mistral

npm i https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/mistral@1634

@llamaindex/mixedbread

npm i https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/mixedbread@1634

@llamaindex/ollama

npm i https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/ollama@1634

@llamaindex/openai

npm i https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/openai@1634

@llamaindex/portkey-ai

npm i https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/portkey-ai@1634

@llamaindex/replicate

npm i https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/replicate@1634

@llamaindex/vercel

npm i https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/vercel@1634

@llamaindex/vllm

npm i https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/vllm@1634

commit: 65a0bcf

@marcusschiesser marcusschiesser merged commit b6ea2bf into main Feb 10, 2025
23 checks passed
@marcusschiesser marcusschiesser deleted the tp/use-function-role-for-function-response-part branch February 10, 2025 05:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants