[PR #144] feat: add automatic language detection for responses #148

Open
opened 2026-10-26 21:12:43 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/deepseek-ai/DeepSeek-VL2/pull/144
Author: @Libres-coder
Created: 11/12/2025
Status: 🔄 Open

Base: main ← Head: main


📝 Commits (2)

  • a037ee9 feat: add automatic language detection for responses
  • 4ee6b38 add

📊 Changes

2 files changed (+19 additions, -2 deletions)

View changed files

📝 deepseek_vl2/serve/inference.py (+6 -0)
📝 web_demo.py (+13 -2)

📄 Description

Summary:
This PR introduces automatic language detection for user input, enabling DeepSeek-VL2 to dynamically adjust its response language (e.g., Chinese or English) based on the detected input language. This resolves the issue where the model would sometimes unexpectedly switch to English during Chinese conversations.

Key Changes:

  • web_demo.py:
    • Added langdetect import.
    • Implemented automatic language detection in predict function.
    • Configured generate_prompt_with_history to set a system message based on the detected language.
  • deepseek_vl2/serve/inference.py:
    • Modified convert_conversation_to_prompts to include the system message in the conversation payload passed to the model.
  • requirements.txt:
    • Added langdetect as a dependency.

Problem Solved:
Previously, the model could inconsistently switch its response language, even when the user maintained a single language (e.g., Chinese). This change ensures the model receives a clear language instruction via a system message, leading to stable and contextually appropriate language responses.

Verification Steps:

  1. Ensure all dependencies are installed: pip install -r requirements.txt
  2. Run the web demo: python web_demo.py --model_name DeepSeek-VL2-tiny
  3. In the Gradio interface, try inputs in both Chinese and English and observe the model's response language.
    • Example Chinese input: "你好,请介绍一下你自己" (Expected: Chinese response)
    • Example English input: "Hello, please introduce yourself" (Expected: English response)
    • Example mixed input: "请问你有什么好的idea吗" (Expected: Chinese response based on primary language)

🔄 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/deepseek-ai/DeepSeek-VL2/pull/144 **Author:** [@Libres-coder](https://github.com/Libres-coder) **Created:** 11/12/2025 **Status:** 🔄 Open **Base:** `main` ← **Head:** `main` --- ### 📝 Commits (2) - [`a037ee9`](https://github.com/deepseek-ai/DeepSeek-VL2/commit/a037ee9ed2d14eaa79fe8ab86d95190bf09c6d19) feat: add automatic language detection for responses - [`4ee6b38`](https://github.com/deepseek-ai/DeepSeek-VL2/commit/4ee6b3845549992eed88d9ffd15edfe174a4dd6f) add ### 📊 Changes **2 files changed** (+19 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `deepseek_vl2/serve/inference.py` (+6 -0) 📝 `web_demo.py` (+13 -2) </details> ### 📄 Description **Summary:** This PR introduces automatic language detection for user input, enabling DeepSeek-VL2 to dynamically adjust its response language (e.g., Chinese or English) based on the detected input language. This resolves the issue where the model would sometimes unexpectedly switch to English during Chinese conversations. **Key Changes:** - `web_demo.py`: - Added `langdetect` import. - Implemented automatic language detection in `predict` function. - Configured `generate_prompt_with_history` to set a system message based on the detected language. - `deepseek_vl2/serve/inference.py`: - Modified `convert_conversation_to_prompts` to include the system message in the conversation payload passed to the model. - `requirements.txt`: - Added `langdetect` as a dependency. **Problem Solved:** Previously, the model could inconsistently switch its response language, even when the user maintained a single language (e.g., Chinese). This change ensures the model receives a clear language instruction via a system message, leading to stable and contextually appropriate language responses. **Verification Steps:** 1. Ensure all dependencies are installed: `pip install -r requirements.txt` 2. Run the web demo: `python web_demo.py --model_name DeepSeek-VL2-tiny` 3. In the Gradio interface, try inputs in both Chinese and English and observe the model's response language. - Example Chinese input: "你好,请介绍一下你自己" (Expected: Chinese response) - Example English input: "Hello, please introduce yourself" (Expected: English response) - Example mixed input: "请问你有什么好的idea吗" (Expected: Chinese response based on primary language) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
deepseek-ai/DeepSeek-VL2#148
No description provided.