Views
No views yet
1# 使用 Homebrew 安装
2brew install ollama
3
4# 或者下载 DMG 安装包1# 使用 curl 安装
2curl -fsSL https://ollama.ai/install.sh | shxmodel2-1b-q4_k_m.gguf)1git lfs install
2git clone https://huggingface.co/XiaoduoAILab/Xmodel-2-ollama1# 使用 wget 下载(Linux/macOS)
2wget https://huggingface.co/XiaoduoAILab/Xmodel-2-ollama/resolve/main/xmodel2-1b-q4_k_m.gguf
3
4# 使用 curl 下载
5curl -L -o xmodel2-1b-q4_k_m.gguf https://huggingface.co/XiaoduoAILab/Xmodel-2-ollama/resolve/main/xmodel2-1b-q4_k_m.ggufModelfile 配置文件:1FROM .\xmodel2-1b-q4_k_m.gguf
2
3# 上下文 & 采样
4PARAMETER num_ctx 8192
5PARAMETER temperature 0.7
6PARAMETER top_p 0.9
7PARAMETER repeat_penalty 1.05
8PARAMETER stop "<|im_start|>"
9PARAMETER stop "<|im_end|>"
10
11# 必须的对齐模板
12TEMPLATE """{{ if .System }}<|im_start|>system
13{{ .System }}<|im_end|>{{ end }}<|im_start|>user
14{{ .Prompt }}<|im_end|>
15<|im_start|>assistant
16"""
17
18# 系统人设
19SYSTEM "你是由 晓多科技上海 AI 实验室的 Xmodel-2 驱动的智能助手。"FROM: 指定模型文件路径PARAMETER num_ctx 8192: 设置上下文长度为 8192 tokensPARAMETER temperature 0.7: 控制生成文本的随机性(0-1)PARAMETER top_p 0.9: 核采样参数,控制词汇选择范围PARAMETER repeat_penalty 1.05: 重复惩罚,避免重复内容PARAMETER stop: 设置停止标记TEMPLATE: 定义对话模板格式SYSTEM: 设置模型的系统提示词xmodel2-1b-q4_k_m.ggufModelfile 配置文件ollama create xmodel2:1b -f ./Modelfilegathering model components
copying file sha256:46a807aa506683ecf864134e5c0eef85ef90eb1f45f1a4e7193369a5cd6b8685 100%
parsing GGUF
using existing layer sha256:46a807aa506683ecf864134e5c0eef85ef90eb1f45f1a4e7193369a5cd6b8685
creating new layer sha256:5565485590f209e8a5f99f4dc0d3311f535a880aacf5d041aa3385ba01469358
creating new layer sha256:8b69d80892459b63c7741fab95e288c647f0194b00c328bdc5e44ee2417c191a
creating new layer sha256:3584f535bc6ac95f33ffd05aab768b4f7fdcf831e0325f11428df24126e096fb
writing manifest
successsuccess 表示模型创建成功!ollama run xmodel2:1b1import requests
2import json
3
4def chat_with_xmodel2(prompt):
5 response = requests.post(
6 'http://localhost:11434/api/generate',
7 json={
8 'model': 'xmodel2:1b',
9 'prompt': prompt,
10 'stream': False
11 }
12 )
13 return response.json()['response']
14
15# 使用示例
16result = chat_with_xmodel2("你好,请介绍一下你自己")
17print(result)1curl -X POST http://localhost:11434/api/generate -d '{
2 "model": "xmodel2:1b",
3 "prompt": "你好,请写一首关于春天的诗",
4 "stream": false
5}'ollama listollama rm xmodel2:1bollama cp xmodel2:1b xmodel2-backupollama show xmodel2:1bModelfile 文件中的参数,然后重新创建模型:1ollama rm xmodel2:1b
2ollama create xmodel2:1b -f ./Modelfiletemperature 值控制创造性num_ctx 适应不同长度的对话top_p 和 repeat_penalty