miurla / morphic

An AI-powered search engine with a generative UI
https://morphic.sh
Apache License 2.0
6.31k stars 1.62k forks source link

[BUG] Gemini Model fails to invoke any tools. #357

Closed essamamdani closed 1 month ago

essamamdani commented 1 month ago

Is there an existing issue for this?

Vercel Runtime Logs

Current Behavior

I switched from OpenAI to Google Gemini Flash 1.5. It now directly provides answers using the LLM. However, after two hours, I noticed the 'toolChoice: required' setting in the Vercel AI SDK. As a result, the output continuously triggered search cards without stopping the process or generating responses based on the search results.

Here is some snaps:

Screenshot 2024-10-01 at 4 58 00 AM Screenshot 2024-10-01 at 4 59 53 AM Screenshot 2024-10-01 at 4 59 45 AM

Expected Behavior

It should function the same way as OpenAI’s GPT-4 version.

Steps To Reproduce

  1. I just added the Generative API key to the .env file.
  2. After that, I received answers directly from the LLM without any tools being executed.
  3. Later, I found the toolChoice: 'required' option and added it to the researcher.tsx file.

Environment

- OS:Mac
- Browser:Chrome

Anything else?

"@ai-sdk/google": "0.0.23", "@google/generative-ai": "^0.3.1", "ai": "^3.2.10",

miurla commented 1 month ago

This error is an issue with the Gemini model. If toolChoice is set to auto (default), the model decides whether to call the tool. If toolChoice is set to required, the model will call the tool as needed. This also depends on the model.

In the latest code, maxSteps is set to 5, so the tool should not continue to be called: https://github.com/miurla/morphic/blob/main/lib/agents/researcher.tsx#L30 https://sdk.vercel.ai/docs/ai-sdk-core/tools-and-tool-calling#multi-step-calls

Please try with the latest code. https://github.com/miurla/morphic/blob/main/package.json#L15

essamamdani commented 1 month ago

it's still the same error. After I updated the packages

Screenshot 2024-10-01 at 9 31 29 PM Screenshot 2024-10-01 at 9 32 29 PM

Still Don't call any tools:

Screenshot 2024-10-01 at 9 35 03 PM
miurla commented 1 month ago

it's still the same error. After I updated the packages

No, I explained that in the latest version, the issue of continuously calling tools has been resolved.

miurla commented 1 month ago

I found that there are limitations in the schema of the Google Generative API: https://sdk.vercel.ai/providers/ai-sdk-providers/google-generative-ai#troubleshooting-schema-limitations

PR: #358

It started calling tools. The model I confirmed was gemini-1.5-pro-002. gemini-1.5-flash-002 did not call tools. This should be dependent on the model.

image

essamamdani commented 1 month ago

Thanks Let me check.

essamamdani commented 1 month ago

Followed these steps:

git clone https://github.com/miurla/morphic cd morphic bun install nano .env added GOOGLE_GENERATIVE_AI_API_KEY and other necessary environment variables bun run dev

Screenshot 2024-10-04 at 4 45 55 PM



miurla commented 1 month ago

Did you tried some query? The model decides whether to call the tool

image

essamamdani commented 1 month ago

How can we make forceable to call tool everytime before generating the answer?