🦙

Raycast無料版でもローカルLLMを使えば翻訳できる

に公開

RaycastのPro版にはAIチャット機能とTranslate機能があります。

https://www.raycast.com/pro

が、ローカルにOllamaがインストールされている状態なら、Ollama AI extensionを使った翻訳ができます。

https://www.raycast.com/massimiliano_pasquini/raycast-ollama

Ollamaの導入

Ollamaがまだない場合はこちらから。

https://ollama.com/

以下は手順の一例です。

$ brew install ollama
$ which ollama
/opt/homebrew/bin/ollama
$ brew services start ollama # サービスとして起動しておく
$ ollama pull gemma3:12b # 適当なやつをpull

翻訳コマンドの定義

以下のページ(再掲)からextensionをインストールしましょう。

https://www.raycast.com/massimiliano_pasquini/raycast-ollama

Ollama extensionにはビルトインでTranslateコマンドがありますが、これだと言語をいちいち指定しなければなりません。


Ollama translate

筆者のユースケースは基本的に日英翻訳、かつエンジニアリングに関するドキュメントの翻訳がほとんどなので、「日本語だったら英語に、英語だったら日本語にしてください」をカスタムコマンドとして定義しました。
これを定義するには、まずCreate custom commandを実行します。


Ollama create custom command

こういう画面になるので、モデルとプロンプトを設定します。


Ollama create custom command

日英翻訳のプロンプトは以下の本に載せたものを使いました。

https://zenn.dev/kawarimidoll/books/6064bf6f193b51/viewer/90a5be

Raycastのプロンプトでは{selection}で選択範囲を取得できるので、こんな感じになります。

You are an excellent Japanese-English translator. You can translate the original text correctly without losing its meaning. You also have deep knowledge of system engineering and are good at translating technical documents. Translate the text below from English to Japanese if it is in English, or from Japanese to English if it is in Japanese. Please do not include unnecessary line numbers, comments, etc. in the result.
{selection}

これはRaycastのQuicklinkとして保存されます。TranslateJEみたいなわかりやすい名前をつけて保存しましょう。


Raycast create quicklink

エイリアスかホットキーを仕掛けておくと簡単に呼び出せて便利です。


Raycast extension settings

こんな感じで使用できます。{selection}を使っているので、コピーする必要はありません。

作成した翻訳コマンドの動作例

Discussion