Available Commands: serve Start ollama create Create a model from a Modelfile show Show information for a model run Run a model stop Stop a running model pull Pull a model from a registry push Push a model to a registry list List models ps List running models cp Copy a model rm Remove a model help Help about any command
Flags: -h, --helphelpfor ollama -v, --version Show version information
PS C:\Users\shengjie> ollama -v ollama version is 0.6.1
/set Available Commands: /set parameter ... Set a parameter /set system <string> Set system message /set history Enable history /set nohistory Disable history /set wordwrap Enable wordwrap /set nowordwrap Disable wordwrap /set format json Enable JSON mode /set noformat Disable formatting /set verbose Show LLM stats /set quiet Disable LLM stats /set system 你是一名小红书风格文案写手,请使用 Emoji 风格改写用户提供的文案,该风格以引人入胜的标题、每个段落中包含 ... 表情符号和在末尾添加相关标签为特点。请确保保持原文的意思。 Set system message. /show system 你是一名小红书风格文案写手,请使用 Emoji 风格改写用户提供的文案,该风格以引人入胜的标题、每个段落中包含表情符号和在末尾添加相关标签为特点。请确保保持原文的意思。
也可以通过ollama show --modelfile {model} 来查看具体某个模型的Modelfile。
接下来我们尝试将千问设置为一名文案改进助理:
1. 定义Modelfile
创建redbook-ai-modelfile,内容如下:
1 2 3 4 5 6 7 8
FROM deepseek-r1:7b # sets the temperature to 1 [higher is more creative, lower is more coherent] PARAMETER temperature 1 # sets the context window size to 4096, this controls how many tokens the LLM can use as context to generate the next token PARAMETER num_ctx 4096
# sets a custom system message to specify the behavior of the chat assistant SYSTEM 你是一名中文写作改进助理,你的任务是改进所提供文本的拼写、语法、清晰、简洁和整体可读性,同时分解长句,减少重复,并提供改进建议。请只提供文本的更正版本,避免包括解释。
ollama create rewrite-ai -f .\rewrite-ai-modelfile transferring model data using existing layer sha256:87f26aae09c7f052de93ff98a2282f05822cc6de4af1a2a159c5bd1acbd10ec4 using existing layer sha256:7c7b8e244f6aa1ac8c32b74f56d42c41a0364dd2dabed8d9c6030a862e805b54 using existing layer sha256:1da0581fd4ce92dcf5a66b1da737cf215d8dcf25aa1b98b44443aaf7173155f5 creating new layer sha256:f0a0557006bab292d768f2581992580aeb1eb35d38bfa558638fa79e4099df04 creating new layer sha256:0a73740ea421e924afe53e0b59fff35edd9cc156549ea84b96815ec0ba75b509 creating new layer sha256:f703e3ac557059df3e2ac9f0482a1262967664933408281b266914122986eb46 writing manifest success PS C:\Users\shengjie\Config> ollama run rewrite-ai
#### generate without stream curl http://localhost:11434/api/generate -d '{ "model": "deepseek-r1:7b", "stream": false, "prompt": "Why is the sky blue?" }'
#### generate with json mode curl http://localhost:11434/api/generate -d '{ "model": "deepseek-r1:7b", "prompt": "What color is the sky at different times of the day? Respond using JSON", "format": "json", "stream": false, "options": { "temperature": 0.8 } }'
curl http://localhost:11434/api/chat -d '{ "model": "llama3.2", "messages": [ { "role": "user", "content": "What is the weather today in Paris?" } ], "stream": false, "tools": [ { "type": "function", "function": { "name": "get_current_weather", "description": "Get the current weather for a location", "parameters": { "type": "object", "properties": { "location": { "type": "string", "description": "The location to get the weather for, e.g. San Francisco, CA" }, "format": { "type": "string", "description": "The format to return the weather in, e.g. 'celsius' or 'fahrenheit'", "enum": ["celsius", "fahrenheit"] } }, "required": ["location", "format"] } } } ] }'
POST http://localhost:11434/api/chat { "model": "llama3.2", "messages": [ { "role": "user", "content": "What is the weather today in Paris?" } ], "stream": false, "tools": [ { "type": "function", "function": { "name": "get_current_weather", "description": "Get the current weather for a location", "parameters": { "type": "object", "properties": { "location": { "type": "string", "description": "The location to get the weather for, e.g. San Francisco, CA" }, "format": { "type": "string", "description": "The format to return the weather in, e.g. 'celsius' or 'fahrenheit'", "enum": ["celsius", "fahrenheit"] } }, "required": ["location", "format"] } } } ] }
ollama run hf.co/bartowski/Llama-3.2-1B-Instruct-GGUF ollama run hf.co/mlabonne/Meta-Llama-3.1-8B-Instruct-abliterated-GGUF ollama run hf.co/arcee-ai/SuperNova-Medius-GGUF ollama run hf.co/bartowski/Humanish-LLama3-8B-Instruct-GGUF
ollama run hf.co/{username}/{repository}:{quantization}
using Microsoft.SemanticKernel; using Microsoft.SemanticKernel.ChatCompletion; using Microsoft.SemanticKernel.Connectors.Ollama;
var builder = Kernel.CreateBuilder(); var chatModelId = "llama3.2"; var embeddingModelId = "quentinz/bge-large-zh-v1.5:latest"; var endpoint = new Uri("http://localhost:11434");
var response = await kernel.InvokePromptAsync("Who are you?"); response.Display();
Function Calling 调用举例:
1 2 3 4 5 6 7 8
kernel.Plugins.Clear(); kernel.ImportPluginFromFunctions("HelperFunctions", [ kernel.CreateFunctionFromMethod(() => DateTime.UtcNow.ToString("R"), "GetCurrentDateTimeInUtc", "Retrieves the current date time in UTC."), kernel.CreateFunctionFromMethod((string location) => { return$"The weather in {location} is sunny."; }, "GetWeather", "Retrieves the weather for a location.") ]);
1 2 3 4 5 6 7 8 9 10 11 12
#pragmawarning disable SKEXP0070 OllamaPromptExecutionSettings settings = new() { FunctionChoiceBehavior = FunctionChoiceBehavior.Auto() }; var response = await kernel.InvokePromptAsync( "What is the weather today in Beijing?", new(settings)); response.Display();
response = await kernel.InvokePromptAsync("What is the time now?", new(settings));
response.Display();
Embedding 示例:
1 2 3 4 5 6 7 8 9 10
using Microsoft.SemanticKernel; using Microsoft.SemanticKernel.Embeddings;
#pragmawarning disable SKEXP0001 var embeddingGenerator = kernel.GetRequiredService<ITextEmbeddingGenerationService>();
var response = await embeddingGenerator .GenerateEmbeddingsAsync(["Ollama:Get up and running with large language models."]);