文档
项目设置
lmstudio
是一个发布在 PyPI 上的库,它允许您在自己的项目中使用 lmstudio-python
。它是开源的,并在 GitHub 上开发。您可以在这里找到源代码。
lmstudio-python
由于 lmstudio-python
已发布到 PyPI,因此可以使用 pip
或您偏好的项目依赖管理器进行安装(这里展示了 pdm
和 uv
,但其他 Python 项目管理工具也提供类似的依赖添加命令)。
pip install lmstudio
文档中的所有示例都假定服务器 API 在本地默认端口上运行。创建客户端实例时,可以通过传递一个 "host:port"
字符串来覆盖服务器 API 的网络位置。
import lmstudio as lms
SERVER_API_HOST = "localhost:1234"
# This must be the *first* convenience API interaction (otherwise the SDK
# implicitly creates a client that accesses the default server API host)
lms.configure_default_client(SERVER_API_HOST)
# Note: the dedicated configuration API was added in lmstudio-python 1.3.0
# For compatibility with earlier SDK versions, it is still possible to use
# lms.get_default_client(SERVER_API_HOST) to configure the default client
在本页
安装 lmstudio-python
自定义服务器 API 主机和 TCP 端口