分享据说媲美chatGPT的llama2 本地部署和使用

头像
2KG
82阅读5评论

不知道有人感兴趣不?超级简单,用来处理简单的问题应该很方便
我是用的linux,跑的7b模型(需要16g显存)

curl https://ollama.ai/install.sh | sh
ollama run llama2

有api接口可以调用,所以可以也开启远程:

sudo mkdir -p /etc/systemd/system/ollama.service.d
sudo vi /etc/systemd/system/ollama.service.d/environment.conf

[Service]
Environment="OLLAMA_HOST=0.0.0.0:11434"

systemctl daemon-reload
systemctl restart ollama

不带上下文的远程简单对话py

import requests
import json


def generate(prompt):
    try:
        url = "http://********:11434/api/generate"
        payload = {
            "model": "llama2",
            "prompt": prompt,
        }
        with requests.post(url, json=payload, stream=True) as response:
            response.raise_for_status()
            final_context = None
            full_response = ""
            for line in response.iter_lines():
                if line:
                    chunk = json.loads(line)
                    if not chunk.get("done"):
                        response_piece = chunk.get("response", "")
                        full_response += response_piece
                        print(response_piece, end="", flush=True)
                    else:
                        final_context = chunk.get("context")
            return full_response, final_context
    except requests.exceptions.RequestException as e:
        print(f"An error occurred: {e}")
        return None, None


while 1:
    generate(input("\n:  "))

生成的数据还是仅供参考
据说媲美chatGPT的llama2 本地部署和使用

分享主题:
经历/经验
城市:
其他
收藏
举报
加载中…
精选评论
头像
等级3

老哥请问有能本地用的AI生成图片的项目吗?

头像
等级1

哈哈哈,我刚搞了个这个,确实好玩。
你可以用用ollama-webui,这个用起来更方便一点。
我目前正在下70B的模型

有上线的项目,这个就是拿来试试
你那资源不错哇,70b的模型,用的什么显卡?