YouTip LogoYouTip

Ollama Cli

Ollama provides multiple ways to interact with models, with the most common being inference operations through the command line. ## 1. Command Line Interaction Interacting with the model directly through the command line is the simplest way. ### Run Model Use the ollama run command to start the model and enter interactive mode: ollama run For example, we download the deepseek-coder model: ## Example ollama run deepseek-coder After starting, you can directly input questions or instructions, and the model will generate responses in real time. >>> Hello, can you help me write a piece of code? Of course. But first, I would like to know which programming language you want to use (e.g., Python, JavaScript, etc.) and what problem you want to solve or what kind of task you want to complete? This way we can provide you with more accurate content, and also make it easier for me to help you write code snippets that best suit your needs.>>> Write a Python hello world Of course! Here is a simple "Hello, World!" program:```python print("Hello, World!") ```This script will output `Hello, World!` and print it to the console. This is just the most basic Python Hello World example; Python is an interpreted, general-purpose programming language known for its simplicity and readability. It also allows users to insert variables and expressions in their code to create complex behaviors. ### Exit Interactive Mode In interactive mode, enter /bye or press Ctrl+d to exit. * * * ## 2. Single Command Interaction If you only need the model to generate a response once, you can pass the input directly in the command line. ### Use Pipe Input Pass input to the model through a pipe: ## Example echo"Who are you?"| ollama run deepseek-coder The output is as follows: I am a programming intelligent assistant developed by DeepSeek, a Chinese company, named DeepCoder. I specialize in answering questions and tasks related to computer science. If you have any topics in this field or need help, please feel free to ask! ### Use Command Line Arguments Pass input directly in the command line: ollama run deepseek-coder "Python 's hello world Code?" The output is as follows: In Python, "Hello World!" is usually this simple script:```python print("Hello World!") ```When you run this program, it outputs `Hello, World`. This is because the print() function prints the string "Hello, World" to the standard output device (stdout) - which is the information displayed on your screen (when running a Python script in the command line terminal or similar tools, it writes directly to the console. * * * ## 3. Multi-turn Conversation Ollama supports multi-turn conversations, and the model can remember context. ## Example >>> Hello, can you help me write a Python code? Of course! Please tell me what functionality you want 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 input.txt file contains: Python 's hello world Code? Pass the input.txt file content as input: ollama run deepseek-coder < input.txt * * * ## 5. Custom Prompts Define custom prompts or system instructions through Modelfile to make the model follow specific rules during interaction. ### Create Custom Model Write a Modelfile: ## Example FROM deepseek-coder SYSTEM "You are a programming assistant, dedicated to helping users write code." Then create a custom model: ollama create tutorial-coder -f ./Modelfile Run the custom model: ollama run tutorial-coder * * * ## 6. Interaction Logs Ollama records interaction logs for easy debugging and analysis. View logs: ollama logs
← Nextjs TutorialOllama Commands β†’