[PR #1329] [MERGED] feat(gemini):Improvements for Gemini 2.5 Series(Thinking mode) #1837

Closed
opened 2026-02-16 10:24:08 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/langgenius/dify-official-plugins/pull/1329
Author: @liiir1985
Created: 7/23/2025
Status: Merged
Merged: 7/24/2025
Merged by: @crazywoola

Base: mainHead: feature/gemini-improvements


📝 Commits (6)

  • d2049e6 fixed the issue that prompt token count calculation is far more than it actually costs under streaming mode.
  • e1bf0e1 Added CoT support for Gemini2.5 series
  • fcb64c8 Bump the plugin version
  • ac86909 Merge branch 'main' into feature/gemini-improvements
  • a5013d8 Bump the plugin version
  • 1335e37 Fixed the thinking_budget configurations for Geimini 2.5-Flash

📊 Changes

13 files changed (+142 additions, -8 deletions)

View changed files

📝 models/gemini/manifest.yaml (+1 -1)
📝 models/gemini/models/llm/gemini-2.5-flash-lite-preview-06-17.yaml (+11 -0)
📝 models/gemini/models/llm/gemini-2.5-flash-lite.yaml (+11 -0)
📝 models/gemini/models/llm/gemini-2.5-flash-preview-04-17.yaml (+11 -0)
📝 models/gemini/models/llm/gemini-2.5-flash-preview-05-20.yaml (+11 -0)
📝 models/gemini/models/llm/gemini-2.5-flash.yaml (+11 -0)
📝 models/gemini/models/llm/gemini-2.5-pro-exp-03-25.yaml (+12 -0)
📝 models/gemini/models/llm/gemini-2.5-pro-preview-03-25.yaml (+11 -0)
📝 models/gemini/models/llm/gemini-2.5-pro-preview-05-06.yaml (+11 -0)
📝 models/gemini/models/llm/gemini-2.5-pro-preview-06-05.yaml (+11 -0)
📝 models/gemini/models/llm/gemini-2.5-pro.yaml (+11 -0)
📝 models/gemini/models/llm/llm.py (+29 -6)
📝 models/gemini/requirements.txt (+1 -1)

📄 Description

Related Issues or Context

-Fixed the token usage count calculation for gemini, prompt token usage count was counted multiple times in streaming mode
-Add CoT support for Gemini 2.5 series, and added the thinking budget setting to control it.

This PR contains Changes to LLM Models Plugin

  • My Changes Affect Token Consumption Metrics

Fixed the token calculation, which was wrong.
Before:
The prompt token usage count was ridiculously high.
image

After:
It shows the actual token usage count
image

  • My Changes Affect Other LLM Functionalities (Reasoning Process, Grounding, Prompt Caching, etc.)

Added CoT support for Gemini 2.5 series, can use the thinking_budget to control the token used for CoT and to enable/disable the thinking mode.
The content of CoT is surrounded with <thinking></thinking>.
image
image

Version Control (Any Changes to the Plugin Will Require Bumping the Version)

  • I have Bumped Up the Version in Manifest.yaml

Dify Plugin SDK Version

  • I have Ensured dify_plugin>=0.3.0,<0.5.0 is in requirements.txt (SDK docs)

Environment Verification (If Any Code Changes)

Local Deployment Environment

  • Dify Version is: 1.6.0, I have Tested My Changes on Local Deployment Dify with a Clean Environment That Matches the Production Configuration.

SaaS Environment

  • I have Tested My Changes on cloud.dify.ai with a Clean Environment That Matches the Production Configuration

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/langgenius/dify-official-plugins/pull/1329 **Author:** [@liiir1985](https://github.com/liiir1985) **Created:** 7/23/2025 **Status:** ✅ Merged **Merged:** 7/24/2025 **Merged by:** [@crazywoola](https://github.com/crazywoola) **Base:** `main` ← **Head:** `feature/gemini-improvements` --- ### 📝 Commits (6) - [`d2049e6`](https://github.com/langgenius/dify-official-plugins/commit/d2049e67e2365278cc200e2294b95b736bde1b29) fixed the issue that prompt token count calculation is far more than it actually costs under streaming mode. - [`e1bf0e1`](https://github.com/langgenius/dify-official-plugins/commit/e1bf0e17398ee9d326e78a8759d54a0ab3221d6b) Added CoT support for Gemini2.5 series - [`fcb64c8`](https://github.com/langgenius/dify-official-plugins/commit/fcb64c8eacf043f4613ace8845934ea283f84a7a) Bump the plugin version - [`ac86909`](https://github.com/langgenius/dify-official-plugins/commit/ac86909fcfe3e66c6a90065ab1f8772f50ec7aab) Merge branch 'main' into feature/gemini-improvements - [`a5013d8`](https://github.com/langgenius/dify-official-plugins/commit/a5013d860466872db683db27eb4fb26b90b17708) Bump the plugin version - [`1335e37`](https://github.com/langgenius/dify-official-plugins/commit/1335e37a8edc25f814b5315da757c5140920c73d) Fixed the thinking_budget configurations for Geimini 2.5-Flash ### 📊 Changes **13 files changed** (+142 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `models/gemini/manifest.yaml` (+1 -1) 📝 `models/gemini/models/llm/gemini-2.5-flash-lite-preview-06-17.yaml` (+11 -0) 📝 `models/gemini/models/llm/gemini-2.5-flash-lite.yaml` (+11 -0) 📝 `models/gemini/models/llm/gemini-2.5-flash-preview-04-17.yaml` (+11 -0) 📝 `models/gemini/models/llm/gemini-2.5-flash-preview-05-20.yaml` (+11 -0) 📝 `models/gemini/models/llm/gemini-2.5-flash.yaml` (+11 -0) 📝 `models/gemini/models/llm/gemini-2.5-pro-exp-03-25.yaml` (+12 -0) 📝 `models/gemini/models/llm/gemini-2.5-pro-preview-03-25.yaml` (+11 -0) 📝 `models/gemini/models/llm/gemini-2.5-pro-preview-05-06.yaml` (+11 -0) 📝 `models/gemini/models/llm/gemini-2.5-pro-preview-06-05.yaml` (+11 -0) 📝 `models/gemini/models/llm/gemini-2.5-pro.yaml` (+11 -0) 📝 `models/gemini/models/llm/llm.py` (+29 -6) 📝 `models/gemini/requirements.txt` (+1 -1) </details> ### 📄 Description ## Related Issues or Context -Fixed the token usage count calculation for gemini, prompt token usage count was counted multiple times in streaming mode -Add CoT support for Gemini 2.5 series, and added the thinking budget setting to control it. ## This PR contains Changes to *LLM Models Plugin* <!-- LLM Models Test Example: --> <!-- https://github.com/langgenius/dify-official-plugins/blob/main/.assets/test-examples/llm-plugin-tests/llm_test_example.md --> - [x] My Changes Affect Token Consumption Metrics Fixed the token calculation, which was wrong. Before: The prompt token usage count was ridiculously high. <img width="779" height="819" alt="image" src="https://github.com/user-attachments/assets/fcb6ba89-9ea2-4cf0-a33f-59c46197a6c2" /> After: It shows the actual token usage count <img width="791" height="814" alt="image" src="https://github.com/user-attachments/assets/b4fe7185-7a8e-4871-8ce8-193b8ee6402f" /> <!-- 📷 Include Screenshots/Videos Demonstrating the Fix, New Feature, or the Behavior Before/After Breaking Changes. --> - [x] My Changes Affect Other LLM Functionalities (Reasoning Process, Grounding, Prompt Caching, etc.) Added CoT support for Gemini 2.5 series, can use the thinking_budget to control the token used for CoT and to enable/disable the thinking mode. The content of CoT is surrounded with ```<thinking></thinking>```. <img width="382" height="438" alt="image" src="https://github.com/user-attachments/assets/6393f868-736b-4444-8f7e-18ec67a3fd7e" /> <img width="868" height="848" alt="image" src="https://github.com/user-attachments/assets/c652add6-6e79-48b4-a3b0-cc9c6b96da82" /> <!-- 📷 Include Screenshots/Videos Demonstrating the Fix, New Feature, or the Behavior Before/After Breaking Changes. --> ## Version Control (Any Changes to the Plugin Will Require Bumping the Version) - [X] I have Bumped Up the Version in Manifest.yaml ## Dify Plugin SDK Version - [x] I have Ensured `dify_plugin>=0.3.0,<0.5.0` is in requirements.txt ([SDK docs](https://github.com/langgenius/dify-plugin-sdks/blob/main/python/README.md)) ## Environment Verification (If Any Code Changes) ### Local Deployment Environment - [x] Dify Version is: 1.6.0<!-- Specify Your Version (e.g., 1.2.0) -->, I have Tested My Changes on Local Deployment Dify with a Clean Environment That Matches the Production Configuration. <!-- - Python Virtual Env Matching Manifest.yaml & requirements.txt - No Breaking Changes in Dify That May Affect the Testing Result --> ### SaaS Environment - [ ] I have Tested My Changes on cloud.dify.ai with a Clean Environment That Matches the Production Configuration <!-- - Python Virtual Env Matching Manifest.yaml & requirements.txt --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-16 10:24:08 -05:00
yindo closed this issue 2026-02-16 10:24:08 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify-official-plugins#1837