LLM之LM studio:LM studio的简介、安装和使用方法、案例应用之详细攻略

本文详细介绍了LMStudio,一款用于在本地运行和管理大型语言模型的桌面应用,包括其特点、安装步骤、使用服务器和端点、文本嵌入功能,以及如何部署和应用LLMs如Llama3。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

LLM之LM studio:LM studio的简介、安装和使用方法、案例应用之详细攻略

目录

LM Studio的简介

1、使用LM Studio的特点

2、支持的平台:最低硬件/软件要求

LM Studio的安装和使用方法

1、LM Studio 服务器:通过运行在 localhost 上的 OpenAI 风格的 HTTP 服务器使用本地 LLM

支持的端点

使用本地服务器

检查当前加载的模型

响应(遵循 OpenAI 的格式)

进行推断请求(使用 OpenAI 的“Chat Completions”格式)

支持的有效负载参数

2、文本嵌入:使用 LM Studio 的嵌入服务器本地生成文本嵌入(适用于 RAG 应用程序)

从 LM Studio 的本地服务器获取文本嵌入

如何

示例请求:

示例回应:

可用的嵌入模型是哪些?

特色模型:

3、使用方法

LM Studio的案例应用

LLMs之Llama3:手把手教你(只需三步)实现Llama3模型本地部署并对话测试—基于LM Studio的GUI界面直接对话聊天或进一步结合Lobe Chat框架(更优雅的实现类似ChatGPT聊天+包括丰富Agent角色市场)


LM Studio的简介

LM Studio的口号是发现、下载并运行本地 LLMs。LM Studio 是一款桌面应用程序,可在您的计算机上运行本地大型语言模型(LLMs)。

官网LM Studio - Discover, download, and run local LLMs

文档Welcome | LM Studio

1、使用LM Studio的特点

>> 在笔记本电脑上运行llm,完全脱机
>> 通过应用内聊天界面或OpenAI兼容的本地服务器使用模型
>> 从HuggingFace���存储库下载任何兼容的模型文件
>> 在应用程序的主页上发现新的和值得注意的法学硕士

LM Studio支持HuggingFace上的任何ggml Llama, MPT和StarCoder模型(Llama 2, Orca, Vicuna, Nous Hermes, WizardCoder, MPT等)

2、支持的平台:最低硬件/软件要求

M1/M2/M3 Mac,或支持AVX2处理器的Windows PC。Linux有测试版。建议至少 16GB 的 RAM。对于 PC,建议至少 6GB 的 VRAM。支持 NVIDIA/AMD GPU。
>> Windows (x86, x64, AVX2):拥有支持 AVX2 的处理器(通常是较新的 PC)的 Windows
>> macOS (Apple Silicon - M1/M2/M3):搭载 macOS 13.6 或更新版本的 Apple Silicon Mac(M1/M2/M3)。
>> Linux (x86, Ubuntu 22.04, AVX2):拥有支持 AVX2 的处理器(通常是较新的 PC)的Linux PC

LM Studio的安装和使用方法

下载地址LM Studio - Discover, download, and run local LLMs

Linux地址https://releases.lmstudio.ai/linux/0.2.18/beta/LM_Studio-0.2.18.AppImage

Windowshttps://releases.lmstudio.ai/windows/0.2.18-a/latest/LM-Studio-0.2.18-Setup.exe

>> LM Studio 服务器:介绍了如何使用 LM Studio 中的本地服务器通过 API 来加载和运行本地 LLM,并提供了关于请求和响应格式的信息以及如何进行推断请求的示例。
>> 文本嵌入:介绍了文本嵌入的概念,以及如何使用 LM Studio 的嵌入服务器来生成文本嵌入。还提供了关于请求和响应格式的信息以及如何获取文本嵌入的示例请求和响应。

1、LM Studio 服务器:通过运行在 localhost 上的 OpenAI 风格的 HTTP 服务器使用本地 LLM

源文地址:Local LLM Server | LM Studio

您可以通过在本地主机上运行的 API 服务器使用您在 LM Studio 中加载的 LLM。
请求和响应遵循 OpenAI 的 API 格式。
将当前使用 OpenAI 的任何代码指向 localhost:PORT 以使用本地 LLM。

支持的端点

GET /v1/models
POST /v1/chat/completions
POST /v1/embeddings
POST /v1/completions

其中,POST /v1/embeddings 是 LM Studio 0.2.19 中的新功能。在此处阅读有关它的信息。

使用本地服务器

第1步,如果尚未安装 LM Studio,请安装它。从 https://lmstudio.ai 获取应用程序安装程序。
第2步,从应用程序中搜索并下载 LLM,例如 TheBloke/Mistral-7B-Instruct-v0.2-GGUF(磁盘上约 4GB)
第3步,转到本地服务器选项卡(<- 在左侧)
第4步,通过从下拉菜单中选择它来加载您下载的任何 LLM。
第5步,通过单击绿色的“启动服务器”按钮来启动服务器。

您的 LM Studio 现在已准备好接受传入的 API 请求。您可以安全地最小化应用程序;服务器将继续运行。

检查当前加载的模型

curl http://localhost:1234/v1/models

响应(遵循 OpenAI 的格式)

在下述情况下,TheBloke/phi-2-GGUF 和 lmstudio-ai/gemma-2b-it-GGUF 都已加载。

{
  "data": [
    {
      "id": "TheBloke/phi-2-GGUF/phi-2.Q4_K_S.gguf",
      "object": "model",
      "owned_by": "organization-owner",
      "permission": [
        {}
      ]
    },
    {
      "id": "lmstudio-ai/gemma-2b-it-GGUF/gemma-2b-it-q4_k_m.gguf",
      "object": "model",
      "owned_by": "organization-owner",
      "permission": [
        {}
      ]
    }
  ],
  "object": "list"
}%  

进行推断请求(使用 OpenAI 的“Chat Completions”格式)

在此示例中,本地服务器运行在端口 1234 上。您可以在应用程序中的服务器控制栏中更改它。
第1步,打开您的终端(在 Windows 上尝试 Git Bash)
第2步,复制并运行以下请求

curl http://localhost:1234/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{ 
  "messages": [ 
    { "role": "system", "content": "You are a helpful coding assistant." },
    { "role": "user", "content": "How do I init and update a git submodule?" }
  ], 
  "temperature": 0.7, 
  "max_tokens": -1,
  "stream": true
}'

支持的有效负载参数

有关每个参数的说明,请参阅 https://platform.openai.com/docs/api-reference/chat/create

model
top_p
top_k
messages
temperature
max_tokens
stream
stop
presence_penalty
frequency_penalty
logit_bias
repeat_penalty
seed

2、文本嵌入:使用 LM Studio 的嵌入服务器本地生成文本嵌入(适用于 RAG 应用程序)

注意:文本嵌入处于测试版。从这里下载支持它的 LM Studio。请在 LM Studio Discord 上报告任何错误/反馈。

文本嵌入是将文本表示为数字向量的一种方法。嵌入经常在检索增强生成(RAG)应用程序中使用。继续阅读了解如何使用 LM Studio 的嵌入服务器完全本地生成文本嵌入。

从 LM Studio 的本地服务器获取文本嵌入

从版本 0.2.19 开始,LM Studio 包括一个文本嵌入端点,允许您生成嵌入。
请求和响应格式遵循 OpenAI 的 API 格式。在此处阅读有关它的信息。
示例用途包括 RAG 应用程序、代码搜索应用程序以及任何需要文本嵌入的应用程序。

如何

需要 LM Studio 0.2.19 或更新版本。从 lmstudio.ai/beta-releases.html 下载测试版。
第1步,转到本地服务器选项卡(<- 在左侧)并启动服务器。
第2步,通过选择它从嵌入模型设置下拉菜单中选择一个文本嵌入模型来加载它。
第3步,利用 POST /v1/embeddings 端点获取您文本的嵌入。

示例请求:

假设服务器正在端口 1234 上监听
支持的输入类型是字符串和字符串数组(字符串数组)

curl http://localhost:1234/v1/embeddings \
  -H "Content-Type: application/json" \
  -d '{
    "input": "Your text string goes here",
    "model": "model-identifier-here"
  }'

示例回应:
{
  "object": "list",
  "data": [
    {
      "object": "embedding",
      "embedding": [
        -0.005118194036185741,
        -0.05910402536392212,
        ... truncated ...
        -0.02389773353934288
      ],
      "index": 0
    }
  ],
  "model": "nomic-ai/nomic-embed-text-v1.5-GGUF/nomic-embed-text-v1.5.Q5_K_M.gguf",
  "usage": {
    "prompt_tokens": 0, 
    "total_tokens": 0
  }
}

可用的嵌入模型是哪些?

任何 GGUF 格式的 BERT 模型都应该可以使用。如果遇到问题,请在 LM Studio Discord 上报告错误。

特色模型:

nomic-embed-text-v1.5
bge-large-en-v1.5

通过 LM Studio 内置的模型下载器搜索并下载这些模型。

3、使用方法

LM Studio的案例应用

持续更新中……

LLMs之Llama3:手把手教你(只需三步)实现Llama3模型本地部署并对话测试—基于LM Studio的GUI界面直接对话聊天或进一步结合Lobe Chat框架(更优雅的实现类似ChatGPT聊天+包括丰富Agent角色市场)

https://yunyaniu.blog.csdn.net/article/details/138203821

### LMSTUDIO SERVER SETUP AND CONFIGURATION #### Server Installation Prerequisites For the installation of an lmStudio server, ensuring that all prerequisites are met can prevent common issues such as those seen with failed installations or invalid configurations. The environment must support necessary services and dependencies required by the lmStudio application to function properly[^1]. #### Configuration Requirements An improperly configured system may lead to errors similar to messages indicating `Invalid configuration information`. This suggests that before running any setup programs for lmStudio, it's crucial to verify that all specified parameters match the actual hardware and software conditions on which lmStudio will operate[^2]. #### Detailed Setup Process To set up the lmStudio server correctly: Ensure the Jack server—a component possibly involved in audio processing within lmStudio—is both installed and operational. Failures like `Ensuring Jack server is installed and started FAILED` suggest potential problems either during this phase or due to missing components critical for its operation. ```bash # Example command to start a service (this should be adapted based on specific requirements) sudo systemctl start jackd.service ``` After confirming that all dependent systems including but not limited to the Jack server are functioning normally, proceed with configuring lmStudio according to official documentation guidelines provided by the developers or maintainers of lmStudio. During this process, pay close attention to setting correct paths, permissions, network settings, etc., which directly affect whether the server starts successfully after completion of the setup procedure. #### Verification Post-Setup Once the setup has been completed without encountering error messages related to configuration validity or dependency failures, perform tests using predefined scenarios to ensure everything operates as expected under normal circumstances.
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一个处女座的程序猿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值