使用ollama + webui 运行任意大模型

安装ollama 

https://hub.docker.com/r/ollama/ollama

docker run -d -v ~/Documents/work/softs/docker/ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama

验证安装

# 进入容器
 docker exec -it ollama bash
# 运行大模型
ollama run llama2
# 发送请求(会有很多输出,一直到结束)
curl http://localhost:11434/api/generate -d '{
  "model": "llama2",
  "prompt":"Why is the sky blue?"
}'

可以选择其支持的模型列表GitHub - ollama/ollama: Get up and running with Llama 2, Mistral, Gemma, and other large language models.

安装webui

GitHub - open-webui/open-webui: User-friendly WebUI for LLMs (Formerly Ollama WebUI)

# host.docker.internal == 127.0.0.1  主要是mac下docker 不支持127.0.0.1
docker run -d -p 3000:8080 -e OLLAMA_BASE_URL=http://host.docker.internal:11434 -v ~/Documents/work/softs/docker/open-webui:/app/backend/data --name open-webui --restart always ghcr.io/open-webui/open-webui:main

验证安装

访问http://127.0.0.1:3000,开始对话

构建自己的知识库(anything llm)

GitHub - Mintplex-Labs/anything-llm: A multi-user ChatGPT for any LLMs and vector database. Unlimited documents, messages, and storage in one privacy-focused app. Now available as a desktop application with a built-in LLM!

安装

Download AnythingLLM for Desktop

选择模型模型 ollama 

ollama pull nomic-embed-text 支持长文本的效果比较好。

最终的配置

建立文档库

开始用自己的文档对话

### Ollama WebUI 实现方式 Ollama WebUI 是一个用于与语言模型进行交互的图形界面工具。为了设置并使用该Web UI,可以通过官方提供的安装指南完成部署工作[^4]。 #### 安装过程 对于希望本地运行此项目的开发者而言,可以从GitHub上获取源码: ```bash git clone https://github.com/ollama-webui/ollama-webui.git cd ollama-webui ``` 上述命令会下载最新的版本到当前文件夹下,并进入该项目的工作目录内[^3]。 #### 启动服务 一旦成功克隆仓库之后,在终端执行必要的构建指令以及启动服务器脚本即可让应用在线。通常情况下,默认监听端口为`http://localhost:8080`,此时可以在任意现代浏览器访问指定链接查看效果[^2]。 #### 功能展示 当用户打开默认URL `http://localhost:8080`时,将会看到Ollama WebUI所提供的示例页面。这个界面上包含了多种配置选项和支持的功能特性,使得操作更加直观便捷。 #### 示例代码片段 下面是一个简化版的HTML模板,展示了如何创建基本布局来承载聊天对话框和其他组件: ```html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Ollama Chat</title> <style> body { font-family: Arial, sans-serif; } .chat-container { max-width: 600px; margin: auto; padding: 20px; border: 1px solid #ccc; } textarea { width: calc(100% - 2em); height: 100px; display:block;margin-bottom:.5rem;} button {display:block;width:fit-content;margin:auto} </style> </head> <body> <div class="chat-container"> <textarea id="inputText"></textarea><br/> <button onclick="sendMessage()">发送消息</button> <ul id="messageList"></ul> <!-- 显示消息列表 --> </div> <script type="text/javascript"> function sendMessage() { const inputField = document.getElementById('inputText'); let messageContent = inputField.value; // 假设这里有一个函数可以向后端API提交请求 fetch('/api/chat', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({ text:messageContent }) }).then(response => response.json()) .then(data => updateMessageList(data.reply)); function updateMessageList(reply){ var ul=document.getElementById("messageList"); var li=document.createElement("li"); li.appendChild(document.createTextNode(reply)); ul.appendChild(li); } inputField.value=''; } // 初始化加载历史记录或其他逻辑... </script> </body> </html> ``` 这段代码提供了一个简单的前端框架,允许用户输入文本并通过AJAX调用来模拟与后台系统的通信流程[^1]。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

昵称不能为null

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值