-
Notifications
You must be signed in to change notification settings - Fork 8.4k
feat: add native Gemini 3.8 Flash support #7284
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,27 +20,44 @@ def mock_google_api_key(): | |
| yield | ||
|
|
||
|
|
||
| def test_gemini_completion_is_used_when_google_provider(): | ||
| @pytest.mark.parametrize( | ||
| "model, expected_model", | ||
| [ | ||
| ("google/gemini-2.0-flash-001", "gemini-2.0-flash-001"), | ||
| ("google/gemini-3.8-flash", "gemini-3.8-flash"), | ||
| ], | ||
| ) | ||
| def test_gemini_completion_is_used_when_google_provider(model, expected_model): | ||
| """ | ||
| Test that GeminiCompletion from completion.py is used when LLM uses provider 'google' | ||
| Test that GeminiCompletion is used when LLM uses provider 'google' | ||
| """ | ||
| llm = LLM(model="google/gemini-2.0-flash-001") | ||
| llm = LLM(model=model) | ||
|
|
||
| assert llm.__class__.__name__ == "GeminiCompletion" | ||
| assert llm.provider == "gemini" | ||
| assert llm.model == "gemini-2.0-flash-001" | ||
| assert llm.model == expected_model | ||
|
|
||
|
|
||
|
|
||
| def test_gemini_completion_is_used_when_gemini_provider(): | ||
| @pytest.mark.parametrize( | ||
| "model, expected_model", | ||
| [ | ||
| ("gemini/gemini-2.0-flash-001", "gemini-2.0-flash-001"), | ||
| ("gemini/gemini-3.8-flash", "gemini-3.8-flash"), | ||
| ], | ||
| ) | ||
| def test_gemini_completion_is_used_when_gemini_provider(model, expected_model): | ||
| """ | ||
| Test that GeminiCompletion is used when provider is 'gemini' | ||
| """ | ||
| llm = LLM(model="gemini/gemini-2.0-flash-001") | ||
|
|
||
| from crewai.llms.providers.gemini.completion import GeminiCompletion | ||
|
|
||
| llm = LLM(model=model) | ||
|
|
||
| assert isinstance(llm, GeminiCompletion) | ||
| assert llm.provider == "gemini" | ||
| assert llm.model == "gemini-2.0-flash-001" | ||
| assert llm.model == expected_model | ||
|
|
||
|
|
||
| def test_gemini_completion_module_is_imported(): | ||
| """ | ||
|
|
@@ -350,10 +367,8 @@ def test_gemini_raises_error_when_model_not_supported(): | |
|
|
||
| mock_client.models.generate_content.side_effect = ClientError(404, mock_response) | ||
|
|
||
| llm = LLM(model="google/model-doesnt-exist") | ||
|
|
||
| with pytest.raises(Exception): # Should raise some error for unsupported model | ||
| llm.call("Hello") | ||
| with pytest.raises(ImportError, match="Unable to initialize LLM"): | ||
| LLM(model="google/model-doesnt-exist") | ||
|
Comment on lines
+370
to
+371
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Preserve coverage of API-level unsupported-model errors. The new assertion fails during 🤖 Prompt for AI Agents |
||
|
|
||
|
|
||
| def test_gemini_vertex_ai_setup(): | ||
|
|
@@ -440,6 +455,8 @@ def test_gemini_model_detection(): | |
| """ | ||
| # Test Gemini model naming patterns that actually work with provider detection | ||
| gemini_test_cases = [ | ||
| "gemini/gemini-3.8-flash", | ||
| "google/gemini-3.8-flash", | ||
| "google/gemini-2.0-flash-001", | ||
| "gemini/gemini-2.0-flash-001", | ||
| "google/gemini-1.5-pro", | ||
|
|
@@ -469,6 +486,11 @@ def test_gemini_context_window_size(): | |
| context_size_2_0 = llm_2_0.get_context_window_size() | ||
| assert context_size_2_0 > 500000 | ||
|
|
||
| # Test Gemini 3.8 Flash | ||
| llm_3_8 = LLM(model="google/gemini-3.8-flash") | ||
| context_size_3_8 = llm_3_8.get_context_window_size() | ||
| assert context_size_3_8 == 891289 | ||
|
Comment on lines
+489
to
+492
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Make the context-window test prove the model-specific mapping.
🤖 Prompt for AI Agents |
||
|
|
||
| # Test Gemini 1.5 Pro | ||
| llm_1_5 = LLM(model="google/gemini-1.5-pro") | ||
| context_size_1_5 = llm_1_5.get_context_window_size() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: crewAIInc/crewAI
Length of output: 50372
🤖 get_repo_knowledge executed:
get_repo_knowledge crewAIInc/crewAI /tmp/coderabbit-repo-knowledge/crewaiinc-crewai-a921f2d1/learnings /tmp/coderabbit-repo-knowledge/crewaiinc-crewai-a921f2d1/conventionsLength of output: 9150
🏁 Script executed:
Repository: crewAIInc/crewAI
Length of output: 23549
🌐 Web query:
site:ai.google.dev Gemini 3.8 Flash temperature top_p top_k GenerateContentConfig💡 Result:
For Gemini 3.x models, including Gemini 3.8 Flash, the sampling parameters
temperature,top_p, andtop_kare deprecated [1][2]. These parameters are ignored by the API, and supplying them in requests for these models is officially discouraged, as it may result in errors in future updates [1]. Google strongly recommends removing these parameters from yourGenerateContentConfigand using the default settings, as Gemini 3's reasoning capabilities are specifically optimized for them [3][4][2]. Modifying these values, particularly setting thetemperaturebelow its default of 1.0, can lead to degraded performance or unexpected behaviors, such as looping, especially during complex reasoning or mathematical tasks [3][4]. If you are migrating existing code, you should striptemperature,top_p, andtop_kfrom yourgeneration_configorGenerateContentConfigdefinitions [1][2]. For controlling model output behavior in Gemini 3.x, you should rely on the default configuration and system instructions rather than traditional sampling parameter tuning [3][2].Citations:
Handle deprecated sampling parameters for Gemini 3.8.
GeminiCompletion._prepare_generation_config()forwardstemperature,top_p, andtop_ktoGenerateContentConfigfor every model. Google recommends removing these parameters for Gemini 3.x. Add a mocked Gemini 3.8 request test that asserts these fields are omitted, then update the provider to enforce this behavior.🤖 Prompt for AI Agents