Skip to content

Add Doubao Translation API service#1005

Merged
tisfeng merged 29 commits intodevfrom
feature/add-doubao-model
Nov 10, 2025
Merged

Add Doubao Translation API service#1005
tisfeng merged 29 commits intodevfrom
feature/add-doubao-model

Conversation

@tisfeng
Copy link
Copy Markdown
Owner

@tisfeng tisfeng commented Oct 4, 2025

Because the original fork repository was renamed, GitHub no longer allows maintainers to push changes, so I created a new branch PR.

Original PR #1000

Doubao-Seed-Translation Docs

image

liao and others added 17 commits September 29, 2025 08:58
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ConfigurationView/DoubaoTranslate+ConfigurableService.swift

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Removes the Brazilian Portuguese (`pt-BR`) language from the list of supported languages for the Doubao translation service.

The Doubao service does not support this specific language variant, so it has been removed to align the available language options with the service's capabilities and prevent errors.
Updates the list of supported languages for the Doubao translation service to match the official documentation. An inline link to the docs has been added for future reference.

This change removes numerous languages not supported by the API (e.g., Slovak, Greek, Hindi, Persian) and corrects the language code for Norwegian from `no` to `nb` (Bokmål).

This ensures the language list is accurate, preventing errors from attempting to use unsupported language pairs.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds Doubao Translation as a new translation service and updates documentation and UI to support configuring and using it.

  • Introduces DoubaoService with API integration, response models, and supported-language mapping.
  • Adds settings UI for API key and model configuration, assets, and localizations.
  • Updates README (EN/ZH) to list Doubao and show its language support and setup instructions.

Reviewed Changes

Copilot reviewed 15 out of 16 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
README_EN.md Adds Doubao to supported services and language matrix; adds setup section.
README.md Adds 豆包翻译 to supported services and language matrix; adds setup section.
Easydict/objc/Utility/EZLinkParser/EZSchemeParser.m Adds Doubao API key to allowed read/write keys.
Easydict/objc/Service/Model/EZServiceTypes.m Registers EZDoubaoService with service registry.
Easydict/objc/Service/Model/EZEnumTypes.m Adds EZServiceTypeDoubao constant.
Easydict/objc/Service/Model/EZEnumTypes.h Exposes EZServiceTypeDoubao.
Easydict/objc/Service/Model/EZConstKey.h Adds Doubao config keys (API key, model).
Easydict/Swift/View/.../DoubaoTranslate+ConfigurableService.swift Adds settings UI for Doubao API key and model.
Easydict/Swift/Service/Doubao/DoubaoTranslateType.swift Defines supported languages and mapping for Doubao.
Easydict/Swift/Service/Doubao/DoubaoService.swift Implements Doubao translation call, parsing, and error handling.
Easydict/Swift/Service/Doubao/DoubaoResponse.swift Response models for decoding Doubao API responses.
Easydict/Swift/Feature/Configuration/Defaults.Keys+Extension.swift Stores Doubao API key and model defaults.
Easydict/App/Localizable.xcstrings Adds localized strings for Doubao labels.
Easydict/App/Assets.xcassets/.../Doubao.imageset/Contents.json Adds Doubao service icon asset entry.
Easydict.xcodeproj/project.pbxproj Wires new files into the project/targets.

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@tisfeng
Copy link
Copy Markdown
Owner Author

tisfeng commented Oct 4, 2025

I noticed that doubao-seed-translation-250915 is used here. This is a model specifically designed for translation, and its usage differs from general large models like doubao-1-5-pro-32k-250115, as it doesn't support custom prompts.

Therefore, perhaps we could create two separate services: one DoubaoTranslationService specifically for the translation model, as currently implemented in this PR; and another DoubaoAIService that can use other general models, similar to the Zhipu service (#955), supporting the general OpenAI API.

This is a custom OpenAI service I duplicated, and the test is ok.

image

@Liaoworking
Copy link
Copy Markdown
Contributor

Because the original fork repository was renamed, GitHub no longer allows maintainers to push changes, so I created a new branch PR.

Original PR #1000

Doubao-Seed-Translation Docs

image

Thanks for your reminder about the issue with my repository name. I will add the updates to the new branch in my next commit.

Liaoworking and others added 2 commits October 12, 2025 23:42
* feat: add stream response support for Doubao Service

* feat: add localized translation

* doc: add comment for Doubao service query

* doc: update comment for DoubaoService

* perf(DoubaoService): optimize streaming byte processing

- Batch process bytes in 1KB chunks instead of one-by-one
- Only decode when buffer threshold reached or event boundary detected
- Process remaining buffer data after stream ends
- Significantly improves performance for large responses

---------

Co-authored-by: liao <liaoworking@gamil.com>
@tisfeng
Copy link
Copy Markdown
Owner Author

tisfeng commented Oct 12, 2025

@Liaoworking Please help resolve these conversations.

@Liaoworking
Copy link
Copy Markdown
Contributor

@Liaoworking Please help resolve these conversations.

Thanks for the note! I’ll resolve these ASAP.

Liaoworking and others added 3 commits October 18, 2025 21:38
…ethods (#1016)

* refactor: Split contentStreamTranslate() into smaller methods

* docs: Improve method documentation

---------

Co-authored-by: liao <liaoworking@gamil.com>
This commit refactors the `parseSSEEvent` function in `DoubaoService` to enhance its clarity, robustness, and adherence to Swift best practices.

The key improvements include:
- Replaced magic strings ("event:", "data:", "[DONE]") with named constants.
- Simplified the parsing logic by using more idiomatic Swift for string manipulation.
- Consolidated multiple guard statements into a single, more readable check.
- Added error logging for JSON decoding failures to improve debuggability.
This commit refactors the `processCompleteEvents` function in `DoubaoService` to improve its readability and maintainability.

The main changes include:
- Enhanced the documentation comments for the function and its parameters to provide better clarity.
- Introduced a named constant for the SSE event separator ("\n\n").
- Replaced `components(separatedBy:)` with the more idiomatic `split(separator:)` for parsing events.
- Adopted a `guard let ... else { continue }` pattern for a cleaner control flow when handling parsed content.
@tisfeng
Copy link
Copy Markdown
Owner Author

tisfeng commented Oct 18, 2025

@Liaoworking hi, I just made a simple refactoring of the SSE parsing logic, please take a look.

@Liaoworking
Copy link
Copy Markdown
Contributor

@Liaoworking hi, I just made a simple refactoring of the SSE parsing logic, please take a look.
Thanks for the refactoring! I'll check it out soon and leave my feedback.

@Liaoworking
Copy link
Copy Markdown
Contributor

@Liaoworking hi, I just made a simple refactoring of the SSE parsing logic, please take a look.

I've finished reviewing your changes and left a comment. Thanks for the refactoring!

tisfeng and others added 7 commits October 19, 2025 10:20
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ConfigurationView/DoubaoTranslate+ConfigurableService.swift

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…nd documentation

This commit fixes the incomplete Doubao Translation service integration by:

1. Adding the missing Doubao service icon asset configuration (Doubao.png)
2. Updating the English README to properly document the Doubao Translation service
3. Adding the Doubao Translate section to the table of contents for better navigation

The service was previously added in commits 5d62f68 and 0fec7cb but was missing the visual assets and documentation, making it incomplete for end users.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit implements a constraint on the Doubao Translation service to limit its usage to translation tasks only.

The key changes include:
1. Added `supportedQueryType()` method to return `.translation` specifically
2. Added explanatory comment noting that `doubao-seed-translation-250915` model only supports translation tasks
3. This prevents the service from being used for dictionary or sentence queries where it's not designed to function

This restriction ensures users only leverage the Doubao service for its intended translation functionality, avoiding potential errors or unexpected behavior when used for unsupported query types.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@tisfeng
Copy link
Copy Markdown
Owner Author

tisfeng commented Nov 9, 2025

@Liaoworking hi, I fixed all conversations, and restrict Doubao service to translation-only queries

@tisfeng
Copy link
Copy Markdown
Owner Author

tisfeng commented Nov 9, 2025

Please review this PR, I cannot approve it by myself.

@Jerry23011
Copy link
Copy Markdown
Collaborator

I don’t have a doubao API and quite busy recently. If the code looks good I can approve.

@Liaoworking
Copy link
Copy Markdown
Contributor

@Liaoworking hi, I fixed all conversations, and restrict Doubao service to translation-only queries

Thanks for the commit. I reviewed it and it looks good with no problems.

@tisfeng
Copy link
Copy Markdown
Owner Author

tisfeng commented Nov 10, 2025

ok, let's merge it

@tisfeng tisfeng merged commit 079f55c into dev Nov 10, 2025
4 checks passed
@tisfeng tisfeng deleted the feature/add-doubao-model branch November 10, 2025 13:04
@tisfeng
Copy link
Copy Markdown
Owner Author

tisfeng commented Nov 10, 2025

@Liaoworking Thanks your PR 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants