fanyi icon indicating copy to clipboard operation
fanyi copied to clipboard

feat: revert OpenAI support

Open noscripter opened this issue 10 months ago • 5 comments

Description by Korbit AI

What change is being made?

Reintroduce OpenAI support to the command line translator, allowing translation options via iciba, deepseek, and OpenAI, with configurable API keys and custom API hosts for OpenAI.

Why are these changes being made?

The pull request reinstates OpenAI support to enhance the versatility of the translator by leveraging OpenAI's capabilities. This update offers users the choice of translation sources and improves configuration flexibility, accommodating various use cases with the ability to switch between APIs via custom settings.

Is this description stale? Ask me to generate a new description by commenting /korbit-generate-pr-description


[!IMPORTANT] Reintroduces OpenAI support in fanyi CLI with configurable API key and host, updates documentation and configuration handling.

  • Behavior:
    • Reintroduces OpenAI support in index.mjs for translations, configurable via OPENAI_API_KEY and OPENAI_API_HOST.
    • Updates bin/fanyi.mjs to handle new configuration options for OpenAI.
  • Documentation:
    • Updates README.md to include instructions for setting up OpenAI API key and host.
    • Adds OpenAI to the list of supported translation sources in README.md.
  • Configuration:
    • Modifies fanyi config set command in bin/fanyi.mjs to support OPENAI_API_KEY and OPENAI_API_HOST.
  • Misc:
    • Adds "openai" to keywords in package.json.

This description was created by Ellipsis for 68632b7932f67a1b10dc3f0af6b52a70b8836375. You can customize this summary. It will automatically update as commits are pushed.

noscripter avatar May 07 '25 03:05 noscripter

Walkthrough

本次更改重新引入了 OpenAI 作为翻译源,并在 README、配置命令和主翻译逻辑中增加了对 OpenAI API 的支持。新增了相关配置项(如 API Key 和自定义 Host),并完善了使用说明和错误提示,支持与现有 iciba、deepseek 并存。

Changes

文件/分组 变更摘要
README.md 更新文档,重新添加 OpenAI 作为翻译源,补充配置说明、示例命令和变更日志,详细介绍 OpenAI 相关设置。
bin/fanyi.mjs 配置命令支持设置 OPENAI_API_KEYOPENAI_API_HOST,帮助信息增加 OpenAI 配置示例。
index.mjs 主翻译逻辑新增 OpenAI API 支持,处理相关配置项,完善错误提示,与 iciba、deepseek 并存。

Sequence Diagram(s)

sequenceDiagram
    participant 用户
    participant CLI
    participant 配置
    participant OpenAI API
    participant iciba/deepseek

    用户->>CLI: 运行翻译命令
    CLI->>配置: 读取 openai、OPENAI_API_KEY、OPENAI_API_HOST
    alt openai 启用且 API Key 存在
        CLI->>OpenAI API: 发送翻译请求(带系统提示和用户词条)
        OpenAI API-->>CLI: 返回翻译结果
        CLI->>用户: 输出翻译(带渐变样式)
    else deepseek 启用
        CLI->>deepseek: 发送翻译请求
        deepseek-->>CLI: 返回翻译结果
        CLI->>用户: 输出翻译
    else iciba 启用
        CLI->>iciba: 发送翻译请求
        iciba-->>CLI: 返回翻译结果
        CLI->>用户: 输出翻译
    end

Possibly related PRs

  • afc163/fanyi#101:该 PR 移除 OpenAI 支持,与本次重新引入 OpenAI 的改动直接冲突且相关。

Suggested labels

size:S

Poem

🐇
OpenAI 归队,翻译更灵活,
配置新钥匙,主机随你设。
彩色输出词,文档细细说,
兔子敲键盘,功能又一波!
🎉✨


📜 Recent review details

Configuration used: CodeRabbit UI Review profile: CHILL Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 68632b7932f67a1b10dc3f0af6b52a70b8836375 and 9f6c39034ac29faf0a8f0aa7cb8561d990672919.

📒 Files selected for processing (1)
  • index.mjs (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • index.mjs
✨ Finishing Touches
  • [ ] 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar May 07 '25 03:05 coderabbitai[bot]

Walkthrough

This pull request reintroduces OpenAI support to the Fānyì (翻译) project. It updates the README to reflect the change, modifies configuration options to include OpenAI API settings, and adjusts the main translation logic to incorporate OpenAI as a translation source alongside iciba and deepseek.

Changes

Files Summary
README.md Updated to include OpenAI as a translation source and added instructions for configuring OpenAI API keys and host.
bin/fanyi.mjs Modified to handle new configuration options for OpenAI API key and host.
index.mjs Enhanced to integrate OpenAI as a translation source, including error handling and API key validation.
package.json Updated keywords to include 'openai'.

petercat-assistant[bot] avatar May 07 '25 03:05 petercat-assistant[bot]

你发给我的邮件已经收到了~辛苦了~

tsejx avatar May 07 '25 03:05 tsejx

ci is broken

afc163 avatar May 12 '25 02:05 afc163

conflicted

afc163 avatar May 13 '25 05:05 afc163