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>