Python入門トップページ


目次

  1. 仮想環境を構築し,watchdog をインストールする
  2. Watchdog でフォルダを監視する
  3. 新しいファイルを検知する
  4. 検知した新しいファイルを待ち行列フォルダに移動する
  5. 文字起こし処理用のワーカープログラムのひな形を作成する
  6. ワーカープログラムを常駐化する
  7. フォルダ監視とワーカープログラムでパイプライン処理する
  8. 処理用フォルダを設置してそこで処理を行う
  9. ファイルサイズの変化を監視する
  10. サイズの大きなファイルのコピーに対応する
  11. タイムスタンプを表示する
  12. Subprocess で外部コマンドを起動する
  13. WhisperX の設定を行う
  14. ワーカープログラムで音声データからの文字起こしを実行する
  15. 文字起こし結果を完了用フォルダに移動する
  16. ログを保存し例外を処理する
  17. サブフォルダに結果を格納する
  18. Ollama をインストールする
  19. Python から Ollama にプロンプトを送る
  20. Ollama 処理を関数化する
  21. 文字起こしデータから議事録を作成する
  22. サイズの大きなテキストファイルにも対応する
  23. ワーカープログラムで文字起こし結果から議事録を生成する
  24. 議事録をマークダウンファイルに出力する
  25. 文字コードを強制的に指定する

フォルダ監視により,音声ファイルから文字起こしと議事録生成を自動化しよう

Python から Ollama にプロンプトを送る

Ollama のインストールが終わったので,Python から簡単なプロンプトを送信して画面に表示する最も簡単なプログラムを作成して実行してみます.

具体的には,次のとおり subprocess を利用して ollama を実行し,qwen3:8b モデルに「こんにちは」という短いプロンプトを送信します.

ollama.py
import subprocess

result = subprocess.run(
    ["ollama", "run", "qwen3:8b", "こんにちは"],
    capture_output=True,
    text=True,
    encoding="utf-8"
)

print(result.stdout)

次のコマンドで実行します.「こんにちは」というプロンプトに対する回答が生成され,画面に表示されました.

(py313watchdog) PS C:\Users\rinsaka\Documents\python\watchdog> python ollama.py ⏎
Thinking...
Okay, the user greeted me with "こんにちは" which means "Hello" in Japanese. I should respond in Japanese to keep the conversation natural.

First, I need to acknowledge their greeting. A simple "こんにちは" back would be good. Then, maybe add a friendly line to invite them to ask questions or talk about anything.

I should make sure the response is polite and welcoming. Maybe something like: "こんにちは!何か質問がありますか?または、話したいことがあればどうぞ。" which translates to "Hello! Do you have any questions, or is there something you'd like to talk about?"

Wait, that's a bit long. Maybe shorten it to "こんにちは!何か質問がありますか?" to keep it concise. Alternatively, use a more casual tone. Let me check the previous examples. The user might prefer a friendly and open-ended response.

Another option: "こんにちは!よろしくお願いします。何かお手伝いできることがありますか?" meaning "Hello! Please take care. Is there anything I can help with?" That's also good.

I think the key is to be welcoming and offer assistance. So the response should be friendly and invite the user to ask questions or share their needs. Let's go with "こんにちは!何か質問がありますか?" as it's straightforward and polite.
...done thinking.

こんにちは!何か質問がありますか?


(py313watchdog) PS C:\Users\rinsaka\Documents\python\watchdog>

目次に戻る