LM Studio本地调用模型的方法
首先需要下载LM Studio,(LM Studio - Discover, download, and run local LLMs)安装好后,需要对index.js文件进行修改,主要是对相关源hugging face的地址修改。
以macOS为例:
cd /Applications/LM\ Studio.app/Contents/Resources/app/.webpack
vi main/index.js
针对源: huggingface.co 替换为 hf-mirror.com
命令: :%s'huggingface.co'hf-mirror.com'g
否则会报错:Error searching for models ‘Network error’
将对应的大模型下载到本地,然后进行正常加载大模型既可。
其次可以使用多种方式进行访问,如:使用OpenAI、curl、python-requests等等
我们以python-requests为例:
import requests
url = "http://localhost:1234/api/v0/chat/completions"
header = {
"Content-Type": "application/json"
}
set_json = {
"model": "deepseek-r1-distill-llama-8b",
"messages": [
{"role": "system", "content": "Always answer in rhymes."},
{"role": "user", "content": "如何进行机器臂模型构建,使用到什么软件和技术?"}
],
"temperature": 0.8
}
result = requests.post(url=url, json=set_json, headers=header, timeout=300.0)
print(result.json())
当前的role,只支持:'role' [user, assistant, system, tool],所以,在使用时,需要指定好。
当然,我们为了针对一些隐私数据,也可以参考B站上的up主提供的方法:DeepSeek R1 推理模型 一键包 完全本地部署 保姆级教程 断网运行 无惧隐私威胁 大语言模型推理时调参 CPU GPU 混合推理 32B 轻松本地部署_哔哩哔哩_bilibili