[PR #189] [MERGED] fix: corrected latency accuracy #210

Closed
opened 2026-02-15 21:16:15 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/langgenius/dify-plugin-sdks/pull/189
Author: @immortal-wm
Created: 8/7/2025
Status: Merged
Merged: 9/16/2025
Merged by: @Yeuoly

Base: mainHead: fix/latency-issue


📝 Commits (5)

  • b33c3df fix latency calc
  • 24aed38 feat: add timing context management to AIModel for latency tracking
  • 533edc9 feat: implement ModelFactory for dynamic model instance creation
  • 002b702 feat: add unit tests for model registry and mock model provider
  • e8b6a99 apply ruff

📊 Changes

13 files changed (+540 additions, -74 deletions)

View changed files

python/dify_plugin/core/model_factory.py (+39 -0)
📝 python/dify_plugin/core/plugin_registration.py (+8 -7)
python/dify_plugin/interfaces/exec/ai_model.py (+6 -0)
📝 python/dify_plugin/interfaces/model/ai_model.py (+26 -1)
📝 python/dify_plugin/interfaces/model/large_language_model.py (+35 -31)
📝 python/dify_plugin/interfaces/model/moderation_model.py (+5 -7)
📝 python/dify_plugin/interfaces/model/rerank_model.py (+5 -6)
📝 python/dify_plugin/interfaces/model/speech2text_model.py (+5 -4)
📝 python/dify_plugin/interfaces/model/text_embedding_model.py (+5 -7)
📝 python/dify_plugin/interfaces/model/tts_model.py (+17 -11)
python/tests/interfaces/model/test_ai_model_timing_context.py (+84 -0)
python/tests/interfaces/model/test_llm_timing_context.py (+132 -0)
python/tests/test_model_registry_get_model.py (+173 -0)

📄 Description

image image

The latency is much smaller than the actual execution time because each LLM call doesn't have its own started_at timestamp— they all share the same class variable.


🔄 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-plugin-sdks/pull/189 **Author:** [@immortal-wm](https://github.com/immortal-wm) **Created:** 8/7/2025 **Status:** ✅ Merged **Merged:** 9/16/2025 **Merged by:** [@Yeuoly](https://github.com/Yeuoly) **Base:** `main` ← **Head:** `fix/latency-issue` --- ### 📝 Commits (5) - [`b33c3df`](https://github.com/langgenius/dify-plugin-sdks/commit/b33c3df99120c09f7addce96ea0941dd85a82950) fix latency calc - [`24aed38`](https://github.com/langgenius/dify-plugin-sdks/commit/24aed3847d5068486710054b785d3020573345ee) feat: add timing context management to AIModel for latency tracking - [`533edc9`](https://github.com/langgenius/dify-plugin-sdks/commit/533edc9cd342c3aa4d41c3b5646e6703e16101a0) feat: implement ModelFactory for dynamic model instance creation - [`002b702`](https://github.com/langgenius/dify-plugin-sdks/commit/002b702660845b478c39751bde87812bebcd5f3e) feat: add unit tests for model registry and mock model provider - [`e8b6a99`](https://github.com/langgenius/dify-plugin-sdks/commit/e8b6a9950cac439c1daff539fd58e69292248be8) apply ruff ### 📊 Changes **13 files changed** (+540 additions, -74 deletions) <details> <summary>View changed files</summary> ➕ `python/dify_plugin/core/model_factory.py` (+39 -0) 📝 `python/dify_plugin/core/plugin_registration.py` (+8 -7) ➕ `python/dify_plugin/interfaces/exec/ai_model.py` (+6 -0) 📝 `python/dify_plugin/interfaces/model/ai_model.py` (+26 -1) 📝 `python/dify_plugin/interfaces/model/large_language_model.py` (+35 -31) 📝 `python/dify_plugin/interfaces/model/moderation_model.py` (+5 -7) 📝 `python/dify_plugin/interfaces/model/rerank_model.py` (+5 -6) 📝 `python/dify_plugin/interfaces/model/speech2text_model.py` (+5 -4) 📝 `python/dify_plugin/interfaces/model/text_embedding_model.py` (+5 -7) 📝 `python/dify_plugin/interfaces/model/tts_model.py` (+17 -11) ➕ `python/tests/interfaces/model/test_ai_model_timing_context.py` (+84 -0) ➕ `python/tests/interfaces/model/test_llm_timing_context.py` (+132 -0) ➕ `python/tests/test_model_registry_get_model.py` (+173 -0) </details> ### 📄 Description <img width="601" height="551" alt="image" src="https://github.com/user-attachments/assets/a9608f81-b569-4e02-a7b3-58e4f9fc0e2e" /> <img width="891" height="811" alt="image" src="https://github.com/user-attachments/assets/0e712b2c-fac3-4a02-ad9b-8862936d91a4" /> **The latency is much smaller than the actual execution time because each LLM call doesn't have its own started_at timestamp— they all share the same class variable.** --- <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-15 21:16:15 -05:00
yindo closed this issue 2026-02-15 21:16:15 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify-plugin-sdks#210