This repository has been archived by the owner on Oct 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
726 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: Release | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v*' | ||
workflow_dispatch: | ||
|
||
jobs: | ||
Build: | ||
if: startsWith(github.ref, 'refs/tags/v') | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- run: bash release.sh ${{ github.ref }} | ||
|
||
- name: Release | ||
uses: softprops/action-gh-release@v1 | ||
with: | ||
draft: false | ||
files: | | ||
dist/*.bobplugin | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GT_TOKEN }} | ||
|
||
- run: rm -rf dist | ||
|
||
- uses: stefanzweifel/git-auto-commit-action@v4 | ||
with: | ||
branch: main | ||
commit_message: new release! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,37 @@ | ||
# bob-plugin-doubao-translate | ||
基于 豆包Doubao API 的文本翻译、文本润色、语法纠错 Bob 插件。 | ||
<div> | ||
<h1 align="center">Doubao Translator Bob Plugin</h1> | ||
</div> | ||
|
||
## 简介 | ||
|
||
基于 [豆包Doubao API](https://www.volcengine.com/product/doubao) 的文本翻译、文本润色、语法纠错 Bob 插件。 | ||
|
||
### 语言模型 | ||
|
||
* `Doubao-pro-128k`(默认使用) | ||
* `Doubao-pro-32k` | ||
* `Doubao-pro-4k` | ||
* `Doubao-lite-128k` | ||
* `Doubao-lite-32k` | ||
* `Doubao-lite-4k` | ||
* `Doubao-embedding` | ||
* `Moonshot-v1-128k` | ||
* `Moonshot-v1-128k` | ||
* `Moonshot-v1-128k` | ||
|
||
## 使用方法 | ||
|
||
1. 安装 [Bob](https://bobtranslate.com/guide/#%E5%AE%89%E8%A3%85) (版本 >= 1.8.0),一款 macOS 平台的翻译和 OCR 软件 | ||
|
||
2. 下载此插件: [bob-plugin-doubao-translate.bobplugin](https://github.com/djx30103/bob-plugin-doubao-translate/releases/latest) | ||
|
||
3. 安装此插件 | ||
|
||
4. 去 [火山方舟控制台](https://console.volcengine.com/ark) 开通管理(开通服务) -> 模型推理(为每个模型创建接入点) -> API Key管理(创建 API Key) | ||
|
||
5. 把 API Key、推理点ID 填入 Bob 偏好设置 > 服务 > 此插件配置界面对应的输入框中,选择你要使用的模型,点击保存即可。 | ||
|
||
## 感谢 | ||
|
||
本仓库参考部分其他优秀源码,感谢[bob-plugin-cohere](https://github.com/missuo/bob-plugin-cohere)、[bob-plugin-gemini-translate](https://github.com/BrianShenCC/bob-plugin-gemini-translate)。 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/bash | ||
|
||
version=${1#refs/tags/v} | ||
zip -r -j bob-plugin-doubao-translate-$version.bobplugin src/* | ||
|
||
sha256_doubao=$(sha256sum bob-plugin-doubao-translate-$version.bobplugin | cut -d ' ' -f 1) | ||
echo $sha256_doubao | ||
|
||
download_link="https://github.com/djx30103/bob-plugin-doubao-translate/releases/download/v$version/bob-plugin-doubao-translate-$version.bobplugin" | ||
|
||
new_version="{\"version\": \"$version\", \"desc\": \"None\", \"sha256\": \"$sha256_doubao\", \"url\": \"$download_link\", \"minBobVersion\": \"1.8.0\"}" | ||
|
||
json_file='appcast.json' | ||
json_data=$(cat $json_file) | ||
|
||
updated_json=$(echo $json_data | jq --argjson new_version "$new_version" '.versions = [$new_version] + .versions') | ||
|
||
echo $updated_json > $json_file | ||
mkdir dist | ||
mv *.bobplugin dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
var utils = require("./utils.js"); | ||
|
||
const defaultUrl = "https://ark.cn-beijing.volces.com/api/v3/chat/completions"; | ||
const streamRequest = async ({ url, headers, body, query }) => { | ||
let resultText = ""; | ||
return $http.streamRequest({ | ||
method: "POST", | ||
url: url, | ||
header: headers, | ||
body: body, | ||
streamHandler: (stream) => { | ||
|
||
let streamText = stream.text; | ||
const dataReg = /^data: /gm; | ||
const doneReg = /\s*\[DONE\]\s*/; | ||
|
||
// 使用正则表达式将 streamText 按 "data: " 分割为多个块 | ||
const dataBlocks = streamText.split(dataReg); | ||
|
||
dataBlocks.forEach((block) => { | ||
// 去除首尾空格和换行符 | ||
block = block.trim(); | ||
|
||
// 检测和移除 [DONE] 标记 | ||
if (doneReg.test(block)) { | ||
block = block.replace(doneReg, ''); | ||
} | ||
|
||
|
||
// 忽略空块 | ||
if (block === "") { | ||
return; | ||
} | ||
|
||
const resultJson = JSON.parse(block); | ||
resultText += resultJson.choices[0].delta.content; | ||
query.onStream({ result: { toParagraphs: [resultText] } }); | ||
}); | ||
}, | ||
handler: (result) => { | ||
if (result.response.statusCode >= 400) { | ||
utils.handleError(query.onCompletion, result); | ||
} else { | ||
query.onCompletion({ result: { toParagraphs: [resultText]} }); | ||
} | ||
}, | ||
}); | ||
}; | ||
|
||
const normalRequest = async ({ url, headers, body , query}) => { | ||
return $http.request({ | ||
method: "POST", | ||
url: url, | ||
header: headers, | ||
body: body, | ||
handler: (result) => { | ||
if (result.response.statusCode >= 400) { | ||
utils.handleError(query.onCompletion, result); | ||
} else { | ||
const data = result.data; | ||
$log.info(JSON.stringify(data)); | ||
query.onCompletion({ result: { toParagraphs: [data.choices[0].message.content] } }); | ||
} | ||
}, | ||
}); | ||
}; | ||
|
||
exports.streamRequest = streamRequest; | ||
exports.normalRequest = normalRequest; | ||
exports.defaultUrl = defaultUrl; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.