总结一下:
过程中踩的最大的坑就是关于tunnel 完毕后 查找serve的模型找不到
查看全部模型 一共两个api
分别是/api/tags 和 v1/models 的openai格式
返回的都是空白
原因是我用wsl部署的ollama 然后 pull 和 run 都是从 /usr/share/ollama/.ollama/models 里找
也默认下载到这里
然而ollama serve 默认用OLLAMA_MODELS 环境变量 默认到了 ~/.ollama/models
我们只需要一行
export OLLAMA_MODELS=/usr/share/ollama/.ollama/models
就可以解决 然后如果想自定义 serve的 port (默认是11434)
export OLLAMA_HOST=127.0.0.1:11435
就可以 然后 ollama serve
之后说一下 tunneling 使用的是
ssh -R [remoteBindAddress]:[remotePort]:[localHost]:[localPort] user@remoteServer
如果你是将ap部署在server本身上的话 第一个remote address 可以暂时忽略
我执行的就是
ssh -R 8080:localhost:11411 your_user@your_server.com
过程中好用的linux命令也附上:
查看port available与否 → sudo lsof -i:123
查看所有listen的port 用来确认tunneling是否成功 是否server的port已经在听 并准备把信息传到ollama 服务器上 → sudo lsof -i -P -n | grep LISTEN
最后快速查看是否连接成功
get model → curl [http://localhost:8080/api/tags](http://localhost:8080/api/tags) | jq 或
curl [http://localhost:8080/](http://localhost:8080/api/tags)v1/models | jq (jq 用来parse json)
问问题 →
curl [http://localhost:8080/api/generate](http://localhost:8080/api/generate) -d '{ "model": model_name, "prompt":"Why is the sky blue?" ,"stream" : false }' | jq ".response"
这样的生成一段的回答