Ollama Model Interaction
Ollama provides multiple ways to interact with models, the most common being inference operations via the command line.
1. Command-Line Interaction
Interacting with the model directly via the command line is the simplest way.
Run the Model
Useollama runcommand to start the model and enter interactive mode:
ollama run <model-name>
For example, we download the qwen3.5 model:
Example
After startup, you can directly input questions or commands, and the model will generate responses in real time.
>>> 你好,你能帮我写一段代码吗?
当然可以。但是首先我想知道您希望在哪种编程语言中实现这个功能(例如Python、JavaScript等)和要解决什么问题或者完成的任务是什么样的例子呢?这样我们可以为您提供更准确的
内容,同时也方便我帮助你写出最适合您的代码片段。
>>> 写一段 python hello world
当然可以!这是一个简单的 "Hello, World!" 程序:
```python
print("Hello, World!")
```
这个脚本会输出 `Hello, World!`,并将其打印到控制台上。这只是最基本的 Python Hello world示例;Python是一种解释型、通用型的编程语言以其简洁性和易读性而闻名。它还允许
用户在代码中插入变量和表达式来创建复杂的行为。
Exit Interactive Mode
In interactive mode, type/byeor pressCtrl+d to exit.
2. Single-Command Interaction
If you only need the model to generate a single response, you can pass the input directly on the command line.
Using Pipe Input
Pass the input to the model via a pipe:
Example
The output is as follows:

Using Command-Line Arguments
Pass the input directly on the command line:
ollama run qwen3.5 "Python 的 hello world 代码?"
The output is as follows:
在 Python 中,"Hello World!" 通常是这段简单的脚本:
```python
print("Hello World!")
```
当你运行这个程序时,它会输出 `Hello, World`。这是因为 print() 函数将字符串 "Hello, World" 打印到标准输出设备 (stdout) - 也就是你的屏幕上显示的信息(在这种情况下是命
令行终端或类似的工具中运行 Python 脚本时,它会直接写入控制台。
3. Multi-Turn Conversation
Ollama supports multi-turn conversations, and the model can remember context.
Example
Of course! Please tell me what functionality you need to implement.
>>>I want to write a function to calculate the Fibonacci sequence.
Okay, here is a simple Python function:
def fibonacci(n):
if n <= 1:
return n
else:
return fibonacci(n-1) + fibonacci(n-2)
4. File Input
You can pass file content as input to the model.
Assume the content of input.txt is:
Python 的 hello world 代码?
Use the content of input.txt as input:
ollama run qwen3.5 < input.txt
5. Custom Prompt
Define custom prompts or system instructions through the Modelfile to make the model follow specific rules during interactions.
Create a Custom Model
Write a Modelfile:
Example
SYSTEM "You are a programming assistant, dedicated to helping users write code."
ollama create example-coder -f ./Modelfile
Run the custom model:
ollama run example-coder
6. Interaction Logs
Ollama records interaction logs for convenient debugging and analysis.
View logs:
ollama logsOther Extensions