Skip to content

新增LLM节点 - #27

Open
aichangex wants to merge 10 commits into
yuhaowin:mainfrom
aichangex:main
Open

新增LLM节点#27
aichangex wants to merge 10 commits into
yuhaowin:mainfrom
aichangex:main

Conversation

@aichangex

@aichangex aichangex commented Aug 17, 2025

Copy link
Copy Markdown

从只能添加单个单词,升级到了可以批量添加单词,利用LLM进行分词和过滤简单词,按照单词重要性进行排序添加。欧陆词典API改为批量提交,规避QPS限制。价值上将排除网址、邮件、非英语单词等情况,同时适配句子翻译场景。

Summary by CodeRabbit

  • New Features
    • Local validation to auto-exclude emails, URLs, and other non-word content.
    • LLM-assisted word extraction with timeout fallback.
    • Batch add support, including batch submissions to 欧陆词典.
  • Improvements
    • Enhanced configuration options for LLM and timeouts.
    • More informative result and error messages.
    • Added plugin icon; improved compatibility (lower minimum app version).
  • Documentation
    • README updated to reflect batch additions, LLM-based tokenization/filtering, and 欧陆词典 batch submission.
  • Chores
    • Version bump and metadata updates (name, summary, author, homepage).

@coderabbitai

coderabbitai Bot commented Aug 17, 2025

Copy link
Copy Markdown

Walkthrough

Refactors the plugin to a local-first word validation and LLM-assisted extraction flow, adds Volcano LLM integration with timeouts/fallbacks, introduces batch writes for Eudic, updates manifest metadata and options (including new LLM settings), and refreshes README to document batch additions, local filtering, and API changes.

Changes

Cohort / File(s) Summary
Documentation
README.md
Updates features to note batch word additions, LLM-based tokenization/filtering, sorting, batch Eudic API usage, and new local validation excluding emails/URLs.
Manifest & Options
src/info.json
Bumps version to 0.2.5; renames plugin; adds icon; updates author/homepage; lowers minBobVersion; removes appcast. Expands options: updates authorization and word_only; adds Volcano LLM fields (api key, endpoint, model, system prompt), word_check_timeout_ms; tweaks wordbook_id wording.
Core Logic & Flow
src/main.js
Major refactor: adds local strict filter and LLM (Volcano) extraction with timeout and fallback. Introduces httpRequestP, error/UI helpers, tokenization/dedup, per-dictionary add handlers (including Eudic batch), Ark content parsing, yes/no parsing, and reworks translate() control flow and result/error builders.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant P as Plugin (translate)
    participant L as Local Filter
    participant V as Volcano LLM
    participant D as Dictionary API(s)

    U->>P: Submit text
    P->>L: Normalize & classify
    alt invalid
        P-->>U: Error (not a valid word input)
    else valid
        P->>V: Extract candidate words (timeout)
        alt LLM returns words
            P->>P: Dedup/trim
            alt dict_type = Eudic
                P->>D: Batch add words
            else other dicts
                loop words
                    P->>D: Add word (serial)
                end
            end
            D-->>P: Add status
            P-->>U: Summary message
        else LLM timeout/fail
            P-->>U: Structured error (with diagnostics)
        end
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

I twitch my ears at words that glide,
Filter the fluff, let letters abide.
If doubt hops in, Volcano’s my guide—
Batch to Eudic, the rest I stride.
Click, clack, add back-to-back—
A rabbit librarian, keeping track. 🐇📚

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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 coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 7

🧹 Nitpick comments (10)
README.md (2)

5-5: Unify the dictionary brand wording: “欧路” vs “欧陆”.

The project consistently uses “欧路词典” elsewhere. This line uses “欧陆词典”. Please standardize to “欧路词典” to avoid confusion.

-欧陆词典API改为批量提交,规避QPS限制。
+欧路词典 API 改为批量提交,规避 QPS 限制。

5-5: Document new LLM configuration options in the Settings section.

README describes the LLM/batch flow but doesn’t explain how to configure Volcano (API Key, Endpoint, Model, System Prompt, Timeout). Add a brief subsection under “设置” to map to the new options added in src/info.json so users can actually enable the feature.

I can draft the “设置” subsection that mirrors the new options (volcano_api_key/endpoint/model/llm_system_prompt/word_check_timeout_ms) and include a minimal example.

src/info.json (2)

6-7: Manifest summary claims “LLM 超时>5s默认通过”,but main.js currently does not default-pass on LLM failure.

Either update the behavior in translate()/extractWordsByLLMVolcano() to implement default-pass on timeout, or revise this summary to match current behavior (which returns a structured error/debug message).

Would you like me to adjust translate() to (a) fall back to localExtractWords() when statusCode=0/timeout, or (b) default-pass the raw input in single-word mode only?


67-72: Expose “max words to add” as an option to match code intent.

main.js reads llm_words_max_add but the manifest doesn’t define it; it always falls back to 200. Add this option so users can control batch size.

   {
     "identifier": "word_check_timeout_ms",
     "type": "text",
     "title": "LLM 超时(毫秒)",
     "textConfig": { "type": "visible", "placeholderText": "5000" }
-    },
+    },
+    {
+      "identifier": "llm_words_max_add",
+      "type": "text",
+      "title": "LLM 抽取最大单词数",
+      "textConfig": { "type": "visible", "placeholderText": "200" }
+    },
src/main.js (6)

110-115: withTimeout() is a no-op; either implement or remove.

Given we rely on $http.timeout and cancelSignal, this no-op can be removed to avoid misleading future readers. If you want a true business-level timeout, I can provide a safe wrapper that doesn’t rely on setTimeout.


529-549: ok predicate uses cleaned.length >= 0 (always true).

If the intent is “HTTP success regardless of words length,” this is fine. Otherwise, consider > 0 and handle empty set as non-fatal success upstream, as you already do. No change required if by design.

-      ok: sc >= 200 && sc < 300 && cleaned.length >= 0,
+      ok: sc >= 200 && sc < 300 && cleaned.length >= 0, // by design: ok even when 0 words

572-587: Eudic single-add result handling is OK, but message could be more actionable.

On non-201, consider surfacing server message to help users fix configuration.

-      if (res && res.response && res.response.statusCode === 201) {
+      if (res && res.response && res.response.statusCode === 201) {
         cb({ result: buildResult("添加单词成功:" + word) });
       } else {
-        cb({ error: buildError("欧路词典 token 或配置有误,请检查。") });
+        var serverMsg = (res && res.data && res.data.message) ? String(res.data.message) : "请检查欧路 token / 单词本 id";
+        cb({ error: buildError("欧路写入失败:" + serverMsg) });
       }

772-792: LLM failure path returns debug error; manifest/README suggest default-pass or graceful fallback.

Current behavior propagates a detailed error. If you want “超时>5s默认通过并写入单词本,” consider falling back to localExtractWords() when winfo.statusCode === 0 or errorMessage includes “timeout”, then proceed with the same add flow.

I can provide a guarded fallback here that triggers only on timeouts to avoid masking real 4xx/5xx errors.


341-352: Unused helper: shouldAddToWordbook().

Dead code increases maintenance cost. Remove or integrate into classifyInput/translate.


353-373: Unused helper: parseYesNo().

No call sites remain after refactor to extraction flow. Safe to remove.

📜 Review details

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

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 1d0ec11 and d4b463c.

📒 Files selected for processing (3)
  • README.md (2 hunks)
  • src/info.json (1 hunks)
  • src/main.js (1 hunks)
🔇 Additional comments (3)
README.md (1)

15-15: Good addition — explicitly calls out local filtering.

This aligns with the code’s local regex/tokenization gate before invoking LLM.

src/main.js (2)

223-241: Local strict word filter looks solid.

Good coverage: excludes emails/URLs/whitespace/CJK/digits/underscores; allows internal hyphen/apostrophe and rejects consecutive --/''.


641-659: Batch Eudic path looks correct and matches official API.

Good: POST /studylist/words with category_id, language, words; 201 expected; timeout and cancelSignal wired.

Comment thread src/info.json
Comment thread src/info.json
Comment thread src/main.js
Comment thread src/main.js
Comment thread src/main.js
Comment thread src/main.js
Comment thread src/main.js
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.

1 participant