ScrapboxTranslator v2を作る
コスト:ざっくり $4 / 1000 page くらいのイメージ
時間:2.7 * {number of page} 秒
注意:
OpenAI APIのhard limitを超えると翻訳が失敗する
ので、かかるコストより高いhard limitを設定しておくべき
ただの思考メモの箇条書きをそのまま英訳しても読みづらい
元々他人に読まれにくい文章が、さらに読まれづらくなる
> 箇条書きの構造を保ったまま上手く翻訳させる方法を探していたけど、もはやその必要が無い気もしてきた
> 箇条書きのメモを元にブログっぽい文章を生成させるほうが良いのかも
> Rewrite the content above in English. Make it like a blog post.
> うーん、ただの授業メモをまるで正しい講義資料かのように翻訳してしまうな
> Convert the notes in bullet points to a cohesive, well-structured personal writing
> これだと二行のメモが百行くらいの文章に展開されてしまう
> Convert the style of this personal note from bullet points to cohesive easy-to-read markdown paragraphs in English. [Brackets] are links, and [https://gyazo.com/~] are image links, so preserve the links inside.
> タスクをあくまでも"style"の変換に絞ることで、文章量は同じになるようにする
> このpromptは結構ありかも?

> というかもはやexport先はscrapboxである必要がないな
> markdownでexportしてHugo使うかな
これが結構うまくいきそう
これは手動(ChatGPT)でやった
出力はいっそMarkdownの方が良いかもしれない
LLMはscrapboxページよりもmarkdownページを多く食ってるので、markdownの方がフォーマットに従わせやすそう
なんなら入力もMarkdownの方が良さそう
Scrapbox to Markdownのフォーマット変換と翻訳を同時にやらせるのは得策ではない
結局Scrapbox記法のままうまくやる方法が見つかったので、markdownは使わないことに
タイトルの翻訳は別でやる
JSON Arrayで入出力をやれば、v1みたいに内容が飛ばされて翻訳がずれることがなくなると思う
ChatGPTで作ったので、あんまりコードの構造とか頭に入ってない
0から作り直した方が早そう
本文のtranslation
原文のtoken sizeによる場合分け
~2kなら、4k gpt-3.5を使う
2k~8kなら、16k gpt-3.5を使う
値段は倍するけど、まあ倍程度ならこの実装で良いかなと思う
箇条書きのメモを元にブログっぽい文章を生成させるので、下手に区切るとクオリティ下がると思う
8k~なら、8kに切って翻訳する
そこまで長い かつ 大事な文章なら別途手動で翻訳してくれという意図

メモ
Prompt injection的なことが書いてあるページがあると壊れそう
こんなpromptになった

prompt example for specific page# Task
Convert the style of this personal note from bullet points to cohesive easy-to-read structured paragraphs with [keywords] in English.
[Keywords] in the input are in square brackets, so all in the output must be in square brackets too.
For example, "[ディープラーニング]の[研究]" should be converted to "[research] on [deep learning]."
Links like [https://gyazo.com/~] in the input are in square brackets, so all in the output must be in square brackets too.
# Output Rules
Keywords and links shown below must be included in the output.
[https://gyazo.com/ae5efe61c0a900df786a3034b2f1082e]
[絵]
[デッサン]
[IBJapanese]
[文学分析]
system promptの最後に「これらのリンクを生成文章に含んでくれ」と具体的に指定している
これで、翻訳後のnon-箇条書き文章にもリンクが含まれるようになった
リンクのタイトルは日本語なの?

翻訳の揺れによって異なる訳され方をするのではと心配になった
no, they are all in English

やってないこと
更新部分のみ翻訳
でもページ翻訳ロジックを切り出したので前よりは作りやすいと思う
エラーの処理
とりあえずエラーで中断せずに最後まで処理してほしいので、エラーはprintだけして無視している
翻訳処理にエラーが起きたら、そのページ/タイトルは日本語のままになるはず
temp上げて再チャレンジとかやりたい
期待!

自分のScrapboxもGPTでの翻訳に移行したいと思ってGithubのコードを眺めてた
今作りつつあるプロジェクトも可能なら英訳したい