Skip to content

airi with subtitle and translate#1496

Open
mujiaoMJ wants to merge 7 commits intomoeru-ai:mainfrom
mujiaoMJ:main
Open

airi with subtitle and translate#1496
mujiaoMJ wants to merge 7 commits intomoeru-ai:mainfrom
mujiaoMJ:main

Conversation

@mujiaoMJ
Copy link
Copy Markdown

Description

添加了字幕与翻译的代理程序
subtitle.txt:字幕文本内容存放的位置
proxy-llm.py:代理,填写百度翻译所需要的信息(密钥,url之类的)
subtitlepy.py:字幕

字幕文件,自行填写注释的内容, DeepSeek API Key,百度翻译AppID,百度翻译密钥(注意区分“密钥”与“api key”)
 创建本地url的代码(最后一行):uvicorn.run(app, host="127.0.0.1", port=9000, log_level="info")
此处默认的是http://localhost:9000,在chat服务里的Base URL就填这个
其他相关信息在代码里有注释。
可以设定special words,用来将特定的内容翻译为你期望的内容
字幕文件
字幕文本文件,被proxy-llm与subtitlepy读取
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 681a9b8cd9

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread proxy-llm.py
Comment on lines +117 to +121
text = chunk.decode('utf-8', errors='ignore')
lines = text.split('\n')
for line in lines:
line = line.strip()
if line.startswith('data: ') and '[DONE]' not in line:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Buffer SSE fragments before parsing deltas

Treating each aiter_bytes() chunk as complete SSE lines is unsafe because chunk boundaries are arbitrary; JSON payloads are often split across chunks. In that case line.startswith('data: ')/json.loads(...) misses fragments and silently skips them, so content_parts becomes incomplete and the subtitle text can drop words or entire segments under normal network conditions.

Useful? React with 👍 / 👎.

Comment thread proxy-llm.py
)

try:
resp = httpx.get(url, timeout=15)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid blocking the event loop during translation

This endpoint is async, but baidu_translate performs a synchronous httpx.get call. When translation runs, the event loop is blocked for up to the timeout, which stalls other concurrent streaming requests and can delay or freeze responses in multi-client usage. Use an async client call from the request context instead.

Useful? React with 👍 / 👎.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Warning

Gemini encountered an error creating the review. You can try again by commenting /gemini review.

@peachoolong-uwu
Copy link
Copy Markdown

这也太胶水了

不如去开个feature request等人好好实现吧

@shinohara-rin shinohara-rin added the pr-review/hold/unsure Pull Request that unsure about purpose, not sure if needed label Mar 29, 2026
@mujiaoMJ
Copy link
Copy Markdown
Author

这也太胶水了

不如去开个feature request等人好好实现吧

感谢你的建议!其实本来就自己做出来用的,但官方的人貌似希望做个参考,叫我做了个PR。完全没有动源代码主要是因为把源代码全部理解一遍太困难了,做个外置的简单些还能顺便做字幕并适配后续版本。

@nekomeowww nekomeowww added scope/agent Scope related to how we harness agent, or build the agent workflow feature Related to feature labels Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Related to feature pr-review/hold/unsure Pull Request that unsure about purpose, not sure if needed scope/agent Scope related to how we harness agent, or build the agent workflow

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants