Skip to content

安装与 feature

ai-profile 尚未发布到 crates.io,目前通过 git 依赖接入。

加依赖

toml
# Cargo.toml
[dependencies]
ai-profile = { git = "https://github.com/bkywksj/ai-profile", features = ["chat", "client"] }

生产项目建议锁到具体提交,避免上游改动在你毫无察觉时进来:

toml
ai-profile = { git = "https://github.com/bkywksj/ai-profile", rev = "aa4eea4", features = ["chat", "client"] }

为什么先不发 crates.io

crates.io 的版本永久不可撤回0.1.0 一旦发出去就占住了这个名字。 在第一个真实接入方(sigil)跑通之前,API 形状还可能调整 —— 现在发布只会制造需要长期背负的兼容包袱。

feature 矩阵

feature默认作用带来的依赖
chat对话能力的预置与类型
image生图能力(规划中)
video视频能力(规划中)
tts语音合成(规划中)
client真实 HTTP 调用(Verifier / verifyreqwesttokio

默认只开 chat

toml
ai-profile = { git = "..." }              # = features = ["chat"]

不开 client 时你得到什么

纯数据 + 纯函数:预置清单、服务商目录、ai.profile 解析生成、端点拼接、模型清单清洗。 全部不需要网络,也不需要异步运行时 —— 依赖只有 serde / serde_json / thiserror

这个形态能编到 Android / iOS,也适合只想用预置数据、HTTP 走自己那一套的项目。

toml
# 只要数据层,HTTP 我自己发
ai-profile = { git = "https://github.com/bkywksj/ai-profile", default-features = false, features = ["chat"] }

开 client 时多了什么

Verifierverify() 以及围绕它们的纯函数(diagnose / suggest_url / parse_model_ids …)。

reqwestdefault-features = false + rustls-tls 引入 —— 不拉 OpenSSL, 避免在 Windows 上触发「要装 Perl 才能编译」这类构建依赖。

开了 client 就把 reqwest 拉进了你的公开依赖

Verifier::from_builder 接收 reqwest::ClientBuilder,所以 reqwest 的大版本进入了本 crate 的公开 API。 reqwest 0.12 → 0.13 会是本 crate 的 major 变更。

这是刻意付的代价,理由见版本策略

多能力应用

需要多种能力时一起开。能力之间互不依赖,开哪个就有哪个的预置:

toml
# StoryLoom:对话 + 生图 + 视频 + 语音全都要
ai-profile = { git = "...", features = ["chat", "image", "video", "tts", "client"] }
toml
# sigil:只做对话
ai-profile = { git = "...", features = ["chat", "client"] }

Kind 枚举的成员是按 feature 编译的 —— 没开 videoKind::Video 根本不存在, 不会有「界面上出现了一个本应用不支持的选项」这种问题。

下游 match 必须带 _ 分支

KindProtocolVerifyError 等公开枚举都带 #[non_exhaustive]。 这让本 crate 加枚举值只算 minor 版本,代价是你的 match 必须写 _ => ... 兜底。

验证安装

rust
fn main() {
    let all = ai_profile::presets();
    println!("内置 {} 条预置", all.len());
    for p in all.iter().take(3) {
        println!("  {} — {}", p.key, p.label);
    }
}
text
内置 19 条预置
  anthropic_official — Anthropic 官方
  claude_code — Claude Code 客户端(自定义接口地址)
  codex — Codex 客户端(自定义接口地址)

下一步

MIT 协议开源 · 文档同样欢迎 PR