基于ollama本地化部署deepseek
可以通过ollama安装并运行deepseek模型,启动模型后可以通过程序和接口进行调用。
一、 部署
本地化部署:
1、安装ollama
https://ollama.com/library/deepseek-r1:8b
配置要求:例如deepseek-r1:8b模型需要16G运行内存,8G独立显卡
2、cmd运行deepseek安装
命令:`
ollama run deepseek-r1:8b
运行此模型电脑cpu使用率20%,运行内存占用(4G),GPU占用(3G)
3、启动成功运行后,可以访问地址(http://127.0.0.1:11434/),也可以通过cmd命令窗口进行访问
二、 调用
1、 使用Chatbox调用(配置本地化部署ip进行访问)
2、 接口测试工具访问(postman)
3、 通过程序进行访问(需要写访问接口程序调用本地部署接口)
vue示例代码如下:
<template>
<div>
<h1>本地化 DeepSeek-r1:8b AI大模型</h1>
<textarea v-model="inputText" placeholder="请输入你的问题或指令"></textarea>
<button @click="callOllamaAPI">发送请求</button>
<div v-if="loading">加载中...</div>
<div v-if="response">
<h2>模型响应:</h2>
<pre>{{ response }}</pre>
</div>
<div v-if="error">
<h2>错误信息:</h2>
<pre>{{ error }}</pre>
</div>
</div>
</template>
<script>
import axios from 'axios';
export default {
data() {
return {
inputText: '', // 用户输入的文本
response: null, // 模型返回的响应
error: null, // 错误信息
loading: true, // 加载状态
};
},
methods: {
async callOllamaAPI() {
// 检查输入是否为空
if (!this.inputText.trim()) {
alert('请输入内容');
return;
}
this.loading = true; // 开始加载
this.error = null; // 清空错误信息
this.response = null; // 清空响应
//const apiUrl = 'http://localhost:8080/http://localhost:11435/api/generate'; // Ollama API 地址
const apiUrl = 'http://127.0.0.1:11434/api/generate'; // 使用代理地址
const payload = {
model: 'deepseek-r1:8b', // 指定模型
prompt: this.inputText, // 用户输入的内容
stream: false, // 是否启用流式响应
};
try {
const response = await axios.post(apiUrl, payload, {
headers: {
'Content-Type': 'application/json',
//'Authorization': 'Bearer 1', // 如果需要认证
},
});
this.response = response.data.response; // 获取模型响应
} catch (err) {
this.error = err.response ? err.response.data : err.message; // 捕获错误
} finally {
this.loading = false; // 结束加载
}
},
},
};
</script>
<style scoped>
textarea {
width: 100%;
height: 100px;
margin-bottom: 10px;
}
button {
padding: 10px 20px;
background-color: #42b983;
color: white;
border: none;
cursor: pointer;
}
button:hover {
background-color: #369f6e;
}
pre {
background-color: #f4f4f4;
padding: 10px;
border-radius: 5px;
}
</style>