1.Ollama
Ollama 是一个开源的大型语言模型(LLM)平台,旨在让用户能够轻松地在本地运行、管理和与大型语言模型进行交互。
Ollama 提供了一个简单的方式来加载和使用各种预训练的语言模型,支持文本生成、翻译、代码编写、问答等多种自然语言处理任务。
Ollama 的特点在于它不仅仅提供了现成的模型和工具集,还提供了方便的界面和 API,使得从文本生成、对话系统到语义分析等任务都能快速实现。
与其他 NLP 框架不同,Ollama 旨在简化用户的工作流程,使得机器学习不再是只有深度技术背景的开发者才能触及的领域。
Ollama 支持多种硬件加速选项,包括纯 CPU 推理和各类底层计算架构(如 Apple Silicon),能够更好地利用不同类型的硬件资源。
Ollama 简介 | 菜鸟教程https://www.runoob.com/ollama/ollama-intro.html
2.Ollama下载
Ollama下载 - 官方正版 - 极客应用Ollama可以部署开箱即用的Ai大模型,省去安装环境和下载模型的步骤,让零基础的人也能在本地启动并运行 DeepSeek-R1,Llama 3.3,Gemma 2等AI大模型https://www.gy328.com/app/ollama/根据系统选择下载对应的Ollama版本
3.cmd模型基本操作
检测是否安装
ollama --version
启动下载对应模型
ollama run llama3.2
选择模型应注意:7B模型至少8GB内存,13B模型需要16GB
退出模型
/bye
具体对应操作查看菜鸟教程
Ollama 基本概念 | 菜鸟教程https://www.runoob.com/ollama/ollama-basic.html参考博客
Ollama保姆级教程_ollama ps-CSDN博客文章浏览阅读5.7k次,点赞28次,收藏39次。Ollama能够更容易的让大模型在本地运行起来,没错,是运行起来,至于交互就差点意思了。总不能总是铜鼓命令行来交互吧,这样也太不优雅了!实际上Ollama主要是用来提供服务的,也就是作为服务端,但是可以通过配合其他的UI界面来更方便的使用大模型,例如Open WebUI等。Ollama官网:https://ollama.com/downloadOllama文档:https://github.com/ollama/ollama/tree/main/docs。_ollama pshttps://blog.csdn.net/andyyah/article/details/140891679?fromshare=blogdetail&sharetype=blogdetail&sharerId=140891679&sharerefer=PC&sharesource=2301_76671906&sharefrom=from_link
4.Ollama javascript接入
4.1 前端项目中引入Ollama依赖包(sdk)
npm i ollama
4.2 vue2中安装axios库
使用axios
库来发送HTTP请求到Ollama的API。
npm install axios
4.3 api.js调用模型Api
import axios from 'axios';const API_URL = 'http://localhost:11434'; // Ollama默认的API端口是11434export const generateText = async (prompt) => {try {const response = await axios.post(`${API_URL}/api/generate`, {model: 'mistral', // 指定模型prompt: prompt, // 输入的提示文本stream: true, // 流式传输结果(可选)});if (response.data) {return response.data;} else {throw new Error('No data received');}} catch (error) {console.error('Error generating text:', error);throw error;}
};
4.4 组件中使用服务
调用服务生成文本结果
<template><div><textarea v-model="prompt" placeholder="Enter your prompt"></textarea><button @click="generateText">Generate</button><div v-if="generatedText">{{ generatedText }}</div></div>
</template><script>
import { generateText } from './api'; // 引入你的API服务文件export default {data() {return {prompt: '',generatedText: ''};},methods: {async generateText() {try {const response = await generateText(this.prompt);this.generatedText = response; // 直接处理响应或根据需要解析响应数据流等逻辑(取决于API的实现)} catch (error) {console.error('Error generating text:', error);}}}
};
</script>
运行项目与模型,注意node版本对应。
API 参考文档 -- Ollama 中文文档|Ollama官方文档https://ollama.cadn.net.cn/api.html
5.node版本不匹配请使用nvm管理版本
node-nvm node版本管理器使用-CSDN博客node-nvm node版本管理器使用https://blog.csdn.net/2301_76671906/article/details/146038866?fromshare=blogdetail&sharetype=blogdetail&sharerId=146038866&sharerefer=PC&sharesource=2301_76671906&sharefrom=from_link