fxd-app-gpt-bat/translate:批量处理和翻译APP

为什么

GPT等大模型不适合一次性处理大量内容,即使现在上下文窗口足够了,但还是容易出错和中断。于是我们改为将长文本分段,每一段用提示词单独处理,最后将处理结果拼合。

是什么

fxd-app-gpt-bat 是 GPT::BAT 网页应用的命令行版本,主要适用于命令行和在FlowDeer³中作为节点。

GPT::BAT网页版

严格地说,fxd-app-gpt-bat 只是 GPT::BAT 功能的子集,它只提供「参考字数分段」的分隔方式,也不提供预览和token计算。如果你执行简单的任务,可以优先使用网页版

如何使用

fxd-app-gpt-bat 是一个 fxd app,你可以通过 fxd-cli 或者 FlowDeer 运行它。

在安装完成 fxd-cli 之后,你可以通过以下命令直接安装 fxd-app-gpt-bat

fxd _install fxd-app-gpt-bat

然后运行帮助命令,可以查看它的方法和对应的参数:

fxd GptBat help
Version:
 1.0.1
Usage:
 fxd gpt-bat [command] [options]

Command - main:
 --char_count <number>  每次处理的字符数 (default: 1000)
 --prompt <string>      提示词 (required)
 --ai_key <string>      AI密钥
 --ai_apibase <string>  AI接口地址
 --ai_model <string>    AI模型
 --format <string>      返回结果格式 (default: json)
 --content <string>     待处理的长文本 (required)

Command - file:
 --char_count <number>  每次处理的字符数 (default: 1000)
 --prompt <string>      提示词 (required)
 --ai_key <string>      AI密钥
 --ai_apibase <string>  AI接口地址
 --ai_model <string>    AI模型
 --format <string>      返回结果格式 (default: json)
 --file_path <string>   待处理的文件路径 (required)

使用实例

按20个字符模糊分段(以句号和换行分隔,然后参考20个字符长度重组为数组)处理content:

fxd gptBat --content="之所以这么整合,是因为我们发现 FlowDeer 如果要得到好的效果,需要强大的工具支持,而方小代正好提供了这一切;同时,不管是方小代还是思维树,本质都是对 组件和流程的编排。因此,我们将其整合到 FlowDeer 这一统一品牌下边." --charCount=20 --prompt="原文:{{{content}}} 翻译为英文:" --aiKey="[FXD_SETTINGS::DEFAULT_AI_CHAT_KEY]"  --format="text"

其中 [FXD_SETTINGS::DEFAULT_AI_CHAT_KEY] 是 FXD 系统设置中的变量,可以在 FlowDeer³的设置页面设置。输出结果:

分为 2 段
处理第 1/2 段
The reason for this integration is that we found that FlowDeer requires powerful tool support to achieve good results, and Fangxiaodai provides everything needed for this; at the same time, both Fangxiaodai and MindMap are essentially arrangements of components and processes.
处理第 2/2 段
Therefore, we will integrate it under the unified brand of FlowDeer.
[
  'The reason for this integration is that we found that FlowDeer requires powerful tool support to achieve good results, and Fangxiaodai provides everything needed for this; at the same time, both Fangxiaodai and MindMap are essentially arrangements of components and processes.',
  'Therefore, we will integrate it under the unified brand of FlowDeer.'
]

format=text时会输出调试信息,调试完成后可以改成JSON返回:

fxd gptBat --content="之所以这么整合,是因为我们发现 FlowDeer 如果要得到好的效果,需要强大的工具支持,而方小代正好提供了这一切;同时,不管是方小代还是思维树,本质都是对 组件和流程的编排。因此,我们将其整合到 FlowDeer 这一统一品牌下边." --charCount=20 --prompt="原文:{{{content}}} 翻译为英文:" --aiKey="[FXD_SETTINGS::DEFAULT_AI_CHAT_KEY]"  --format="json"

输出结果:

{
    "message": "success",
    "data": "The reason for this integration is that we found that in order for FlowDeer to achieve good results, powerful tool support is needed, which FANG Xiao Dai just happens to provide; at the same time, whether it is FANG Xiao Dai or Mind Map, they are fundamentally about the arrangement of components and processes.\nTherefore, we will consolidate it under the unified brand FlowDeer."
}

如果有较多文字内容,尤其包含换行时,建议使用 file 方法,以文件作为输入:

fxd gptBat file --filePath="test.txt" --charCount=20 --prompt="原文:{{{content}}} 翻译为英文:" --aiKey="[FXD_SETTINGS::DEFAULT_AI_CHAT_KEY]"  --format="json"

衍生应用

翻译是一个常用场景,于是我们在 fxd-app-gpt-bat 的基础上封装了 fxd-app-translate 应用。

安装:

fxd _install fxd-app-translate

帮助:

fxd translate help
Version:
 1.0.3
Usage:
 fxd translate [command] [options]

Command - main:
 --char_count <number>  每次处理的字符数 (default: 1000)
 --ai_key <string>      AI密钥
 --ai_apibase <string>  AI接口地址
 --ai_model <string>    AI模型
 --format <string>      返回结果格式 (default: json)
 --from_lang <string>   源语言 (default: 中文)
 --to_lang <string>     目标语言 (default: 英文)
 --summarize_first <boolean>    是否先进行摘要 (default: false)
 --content <string>     待处理的长文本 (required)

Command - file:
 --char_count <number>  每次处理的字符数 (default: 1000)
 --ai_key <string>      AI密钥
 --ai_apibase <string>  AI接口地址
 --ai_model <string>    AI模型
 --format <string>      返回结果格式 (default: json)
 --from_lang <string>   源语言 (default: 中文)
 --to_lang <string>     目标语言 (default: 英文)
 --summarize_first <boolean>    是否先进行摘要 (default: false)
 --file_path <string>   待处理的文件路径 (required)

使用它的好处是无需传入提示词,同时它还支持 summarize_first 参数,将其设置为 true,会要求AI线读一遍文章,写一个翻译提示。这样之后再单独翻译某一段时,可以了解更多的上下文。

使用实例:

fxd translate --content="所以这么整合,是因为我们发现 FlowDeer 如果要 得到好的效果,需要强大的工具支持,而方小代正好提供了这一切;同时,不管是方小代还是思维树,本质都是 对 组件和流程的编排。因此,我们将其整合到 FlowDeer 这一统一品牌下边" --charCount=20 --toLang="日文" --aiKey="[FXD_SETTINGS::DEFAULT_AI_CHAT_KEY]"

返回内容:

{
    "message": "success",
    "data": "したがって、この統合を行う理由は、FlowDeerが良い結果を得るためには強力なツールのサポートが必要であり、方小代がそれを提供しているためです。また、方小代や思维树において、本質的にはコンポーネントとプロセスの配置に関するものです。\nTherefore, we have integrated it under the unified brand of FlowDeer. (Japanese)"
}
如果对文章内容有疑问或者有经验分享,请在评论中留言,我们会及时回复。
发表回复