DEV Community

Cover image for datasette-llm 0.1a11:通过 OpenAI 兼容接口接入本地模型
arthur
arthur

Posted on

datasette-llm 0.1a11:通过 OpenAI 兼容接口接入本地模型

写好标智库

更新要点:支持 OpenAI 兼容接口

datasette-llm 是 Datasette 的大语言模型配置中间层插件,负责为其他 Datasette 插件配置模型。

0.1a11 版本新增了 OpenAI 兼容接口支持。只要模型服务提供兼容接口,就可以接入 Datasette,不必限定模型的部署位置。对于通过 LM Studio、Ollama 或 llama.cpp 运行本地模型的开发者,这也提供了将本地模型与 Datasette Agent 连接起来的方式。

对于关注本地模型与数据工具集成的写好标智库读者,这次更新值得关注的重点是:模型服务通过兼容接口接入后,可以配合 Datasette Agent 完成数据库对话查询。

配置示例:连接 LM Studio

下面通过 uvx 启动 Datasette,并加载 datasette-agent。运行前需要准备:

  • 一个可用的 content.db 数据库文件。
  • 已启动的本地模型服务。
  • 与实际服务一致的接口地址和模型名称。
uvx --with datasette-agent datasette \
  --root --secret 1 \
  -s plugins.datasette-llm.default_model '{
    "model": "lmstudio-qwen",
    "model_name": "qwen/qwen3.8-27b",
    "api_base": "http://localhost:1234/v1"
  }' content.db
Enter fullscreen mode Exit fullscreen mode

配置中有三个关键字段:

字段 示例值 说明
model lmstudio-qwen 示例中的模型标识
model_name qwen/qwen3.8-27b 模型服务使用的模型名称,需要按实际部署填写
api_base 本机 1234 端口下的 /v1 接口 OpenAI 兼容接口的基础地址

如果改用 Ollama、llama.cpp 或其他兼容服务,需要相应调整模型名称与接口地址,不能直接照搬示例值。

安全提醒:示例使用了 --root 和固定值 --secret 1,不应未经调整就用于公开部署。

接入后:用自然语言查询数据库

演示中,用户向 Datasette Agent 提问:“有多少个仓库和多少条发布记录?”

Agent 随后调用数据库与表信息工具,并执行以下 SQL:

SELECT
  (SELECT COUNT(*) FROM repos) AS repo_count,
  (SELECT COUNT(*) FROM releases) AS release_count;
Enter fullscreen mode Exit fullscreen mode

演示数据库返回了 200 个仓库、1,889 条发布记录,Agent 再将查询结果整理为自然语言回答。这里的数字仅对应演示数据库,并不代表其他数据库的内容。

这次更新的意义

这次更新扩展了 Datasette 的模型接入方式:提供 OpenAI 兼容接口的模型服务,包括本地运行的模型,都可以通过 datasette-llm 接入插件体系。

在上述示例中,各组件的分工也很清晰:本地模型服务提供模型接口,datasette-llm 承担模型配置,Datasette Agent 则结合数据库工具完成查询与结果表达。

Top comments (1)

Collapse
 
alexshev profile image
Alex Shev •

OpenAI-compatible endpoints make local model adoption much easier, but configuration compatibility should not imply capability compatibility. I’d expose the selected endpoint, model identifier, context limit, and unsupported feature behavior in the Datasette UI or logs. That prevents a local fallback from silently changing result quality or tool behavior when an agent configuration is moved between environments.