我在运行Ubuntu的Azure虚拟机上安装并配置了ollama,并尝试从另一台机器进行API调用,类似于我正在尝试设置自己的ollama服务器,但遇到了API连接问题。
我尝试运行本地主机API,例如:
curl http://localhost:11434/api/generate -d '{ "model": "llama2", "prompt":"Why is the sky blue?", "response": "The", "done": false}'
这是成功的,
我为虚拟机的11434端口设置了入站规则,并尝试使用虚拟机的公共IP进行API调用,结果连接失败:连接被拒绝
我应该使用密码或身份验证吗?我缺少什么?
curl http://<public ip>:11434/api/generate -d '{ "model": "llama2", "prompt":"Why is the sky blue?", "response": "The", "done": false}'
回答:
在查阅文档后,首先我们需要通过设置主机端口和允许的来源来运行Ollama服务器,以便与其通信。
运行
export OLLAMA_HOST="0.0.0.0:8888" OLLAMA_ORIGINS="*" ollama serve
*
表示所有,如果你想使用特定的IP,请使用http://
或https://
后跟你要允许的IP。
然后启动Ollama服务器,方法是
ollama serve
然后运行API,例如
curl http://<pub-ip>:8888/api/pull -d '{ "name": "llama2"}'
拉取镜像只需一次即可(你可以拉取你想要的模型)
以及
curl http://<pub-ip>:8888/api/generate -d '{ "model": "llama2", "prompt":"Why is the sky blue?", "response": "The", "done": false}'