1.下载ollama

ollama:下载和管理模型的软件

https://ollama.com/download

2.启动ollma

或者双击图标直接启动

ollama serve

3.下载模型

(1)图形界面直接下载

(2)命令行下载

ollama run 模型名

下载完成后,直接交互

4.ollama管理

列出已下载的模型

ollama list

当前正在运行的模型

ollama ps

删除模型

ollama rm 模型名

停止运行某个模型

ollama stop 模型名

5.web交互

(具体代码自行实现,本文只负责解说关键用法)

创建文件结构

前端:stastic:css,js,html

后端:server.py

(1)html:网页首页(门面内容)

在head标签里面,关联css

 <link rel="stylesheet" href="/static/style.css" /> 

在body-footer标签最后,关联js

  <script src="/static/app.js"></script> 

(2)js:负责数据传输(路由)

定义了chat、health的路由

fetch('/api/chat', {
        method: 'POST',
        headers: {'Content-Type': 'application/json'},
        body: JSON.stringify({messages: [...]})
    })

(3)css:负责视觉排版美化

(4)server.py(@app.get/post(“/...”))

直接进入首页

@app.get("/")
async def index():
    return FileResponse(STATIC_DIR / "index.html")

挂在静态文件(联系css,html,js)

作用:让 static 目录下的所有静态资源(CSS、JS、图片等)都能通过 /static/文件相对路径 的 URL 被访问到

app.mount("/static", StaticFiles(directory=STATIC_DIR), name="static")

对应js的路由chat

@app.post("/api/chat")
async def chat(req: ChatRequest):
    # ... 处理逻辑 ...

运维测试接口(检查服务是否还在运行)

@app.get("/api/health")
async def health():
    return {
        "status": "ok",
        "model": LLM_MODEL,
        "base_url": LLM_BASE_URL,
    }

Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐