103 lines
5.1 KiB
Markdown
103 lines
5.1 KiB
Markdown
# Rust LLM应用开发库
|
||
|
||
`Rust` `LLM` `AI` `向量数据库` `Agent`
|
||
|
||
## 目录
|
||
|
||
- [目录](#目录)
|
||
- [Rig 是什么?](#rig-是什么)
|
||
- [高级特性](#高级特性)
|
||
- [谁在生产中使用 Rig?](#谁在生产中使用-rig)
|
||
- [快速开始](#快速开始)
|
||
- [简单示例](#简单示例)
|
||
- [集成支持](#集成支持)
|
||
|
||
## Rig 是什么?
|
||
|
||
Rig 是一个用于构建可扩展、模块化、符合人体工程学的 **LLM 驱动**应用程序的 Rust 库。
|
||
|
||
更多关于此 crate 的信息可以在[官方文档](https://docs.rig.rs)和 [crate 文档](https://docs.rs/rig-core/latest/rig/)(API 参考)中找到。
|
||
|
||
## 特性
|
||
|
||
- 支持多轮流式传输和提示的智能体工作流
|
||
- 完整的 [GenAI 语义约定](https://opentelemetry.io/docs/specs/semconv/gen-ai/) 兼容性
|
||
- 20+ 模型提供商,统一在单一接口下
|
||
- 10+ 向量存储集成,统一在单一接口下
|
||
- 完整支持 LLM 补全和嵌入工作流
|
||
- 支持转录、音频生成和图像生成模型能力
|
||
- 以最少的样板代码将 LLM 集成到您的应用中
|
||
- 完整的 WASM 兼容性(仅核心库)
|
||
|
||
## 谁在使用 Rig?
|
||
|
||
以下是使用 Rig 的公司和个人的非完整列表:
|
||
|
||
- [St Jude](https://www.stjude.org/) —— 在 [`proteinpaint`](https://github.com/stjude/proteinpaint)(一款基因组可视化工具)中使用 Rig 构建聊天机器人功能。
|
||
- [Coral Protocol](https://www.coralprotocol.org/) —— 大量使用 Rig,包括内部使用以及作为 [Coral Rust SDK](https://github.com/Coral-Protocol/coral-rs) 的一部分。
|
||
- [VT Code](https://github.com/vinhnx/vtcode) —— 一款基于 Rust 的终端编码智能体,通过 Tree-sitter 和 ast-grep 实现语义代码智能。使用 `rig` 简化 LLM 调用并实现模型选择器。
|
||
- [Dria](https://dria.co/) —— 去中心化 AI 网络,当前将 Rig 用于其[计算节点](https://github.com/firstbatchxyz/dkn-compute-node)。
|
||
- [Nethermind](https://www.nethermind.io/) —— 在其 [Neural Interconnected Nodes Engine](https://github.com/NethermindEth/nine) 框架中使用 Rig。
|
||
- [Neon](https://neon.com) —— 在其 [app.build](https://github.com/neondatabase/appdotbuild-agent) V2 Rust 版本中使用 Rig。
|
||
- [Listen](https://github.com/piotrostr/listen) —— 致力于成为 AI 投资组合管理智能体首选框架,驱动 [Listen 应用](https://app.listen-rs.com/)。
|
||
|
||
您也在生产中使用 Rig?[提交 Issue](https://www.github.com/0xPlaygrounds/rig/issues) 将您的名字添加进来!
|
||
|
||
## 快速开始
|
||
|
||
```bash
|
||
cargo add rig-core
|
||
```
|
||
|
||
### 简单示例
|
||
|
||
```rust
|
||
use rig::{client::CompletionClient, completion::Prompt, providers::openai};
|
||
|
||
#[tokio::main]
|
||
async fn main() {
|
||
// 创建 OpenAI 客户端和模型
|
||
// 需要设置 `OPENAI_API_KEY` 环境变量
|
||
let openai_client = openai::Client::from_env();
|
||
|
||
let gpt4 = openai_client.agent("gpt-4").build();
|
||
|
||
// 提示模型并打印响应
|
||
let response = gpt4
|
||
.prompt("Who are you?")
|
||
.await
|
||
.expect("Failed to prompt GPT-4");
|
||
|
||
println!("GPT-4: {response}");
|
||
}
|
||
```
|
||
|
||
注意:使用 `#[tokio::main]` 需要启用 tokio 的 `macros` 和 `rt-multi-thread` 特性,或直接使用 `full` 启用所有特性(`cargo add tokio --features macros,rt-multi-thread`)。
|
||
|
||
您可以在各 crate 的 `examples` 目录(如 [`rig-core/examples`](./rig-core/examples))中找到更多示例。更详细的使用案例会定期发布在我们的 [Dev.to 博客](https://dev.to/0thtachi),并添加到 Rig 官方文档 [(docs.rig.rs)](http://docs.rig.rs)。
|
||
|
||
## 支持的集成
|
||
|
||
向量存储以独立的伴生 crate 形式提供:
|
||
|
||
- MongoDB:[`rig-mongodb`](https://github.com/0xPlaygrounds/rig/tree/main/rig-mongodb)
|
||
- LanceDB:[`rig-lancedb`](https://github.com/0xPlaygrounds/rig/tree/main/rig-lancedb)
|
||
- Neo4j:[`rig-neo4j`](https://github.com/0xPlaygrounds/rig/tree/main/rig-neo4j)
|
||
- Qdrant:[`rig-qdrant`](https://github.com/0xPlaygrounds/rig/tree/main/rig-qdrant)
|
||
- SQLite:[`rig-sqlite`](https://github.com/0xPlaygrounds/rig/tree/main/rig-sqlite)
|
||
- SurrealDB:[`rig-surrealdb`](https://github.com/0xPlaygrounds/rig/tree/main/rig-surrealdb)
|
||
- Milvus:[`rig-milvus`](https://github.com/0xPlaygrounds/rig/tree/main/rig-milvus)
|
||
- ScyllaDB:[`rig-scylladb`](https://github.com/0xPlaygrounds/rig/tree/main/rig-scylladb)
|
||
- AWS S3Vectors:[`rig-s3vectors`](https://github.com/0xPlaygrounds/rig/tree/main/rig-s3vectors)
|
||
- HelixDB:[`rig-helixdb`](https://github.com/0xPlaygrounds/rig/tree/main/rig-helixdb)
|
||
|
||
以下提供商以独立的伴生 crate 形式提供:
|
||
|
||
- AWS Bedrock:[`rig-bedrock`](https://github.com/0xPlaygrounds/rig/tree/main/rig-bedrock)
|
||
- Fastembed:[`rig-fastembed`](https://github.com/0xPlaygrounds/rig/tree/main/rig-fastembed)
|
||
- Eternal AI:[`rig-eternalai`](https://github.com/0xPlaygrounds/rig/tree/main/rig-eternalai)
|
||
- Google Vertex:[`rig-vertexai`](https://github.com/0xPlaygrounds/rig/tree/main/rig-vertexai)
|
||
|
||
我们还有一些其他关联 crate,提供使用 Rig 时可能有用的附加功能:
|
||
|
||
- `rig-onchain-kit` —— [Rig Onchain Kit](https://github.com/0xPlaygrounds/rig-onchain-kit),旨在使 Solana/EVM 与 Rig 之间的交互更易于实现。 |