3个版本
0.0.3 | 2024年4月22日 |
---|---|
0.0.2 | 2024年4月22日 |
0.0.1 | 2024年4月22日 |
#396 in 异步
20KB
254 行
CONVA AI Copilots的Rust SDK
这是用于使用CONVA AI Co-pilots的Rust Crate
用法
将以下内容添加到您的Cargo.toml中
[dependencies]
conva_ai = "0.0.3"
futures-util = "0.3"
tokio = { version = "1.37.0", features = ["full"] }
注意:以下是在部署此包时包的版本,并不代表最新支持的包号。请查阅 futures-util
和 tokio
文档以获取最新包版本。
示例
1. 使用CONVA Co-pilot生成响应的简单示例
use conva_ai::base::{AsyncConvaAI, BaseClient};
use futures_util::stream::StreamExt;
#[tokio::main]
async fn main() {
const COPILOT_ID: &str = "your-copilot-id";
const COPILOT_VERSION: &str = "your-copilot-version";
const API_KEY: &str = "your-copilot-apikey";
let mut client: BaseClient = AsyncConvaAI::init(
&String::from(COPILOT_ID),
&String::from(COPILOT_VERSION),
&String::from(API_KEY)
);
let result = client.invoke_capability("how are you?".to_string(), false, "default".to_string()).await;
match result {
Ok(mut out) => {
while let Some(val) = &out.next().await {
match val {
Ok(val) => println!("Response {:?}", val),
Err(e) => println!("{:?}", e)
}
}
},
Err(e) => println!("{:?}", e)
}
()
}
2. 如何清除历史记录
CONVA AI客户端默认会跟踪您的对话历史,并使用它作为智能响应的上下文
您可以通过执行以下代码来清除对话历史
use conva_ai::base::{AsyncConvaAI, BaseClient};
use futures_util::stream::StreamExt;
#[tokio::main]
async fn main() {
const COPILOT_ID: &str = "your-copilot-id";
const COPILOT_VERSION: &str = "your-copilot-version";
const API_KEY: &str = "your-copilot-apikey";
let mut client: BaseClient = AsyncConvaAI::init(
&String::from(COPILOT_ID),
&String::from(COPILOT_VERSION),
&String::from(API_KEY)
);
client.clear_history();
()
}
如果您正在构建一个不需要跟踪对话历史的应用程序,您可以禁用历史记录跟踪
client.use_history(false)
您可以通过以下方式启用历史记录:
client.use_history(True)
3. 调试响应
Conva AI使用生成式AI为您提供查询的响应。为了帮助您理解响应背后的推理,我们还提供了AI的推理
use conva_ai::base::{AsyncConvaAI, BaseClient};
use futures_util::stream::StreamExt;
#[tokio::main]
async fn main() {
const COPILOT_ID: &str = "your-copilot-id";
const COPILOT_VERSION: &str = "your-copilot-version";
const API_KEY: &str = "your-copilot-apikey";
let mut client: BaseClient = AsyncConvaAI::init(
&String::from(COPILOT_ID),
&String::from(COPILOT_VERSION),
&String::from(API_KEY)
);
let result = client.invoke_capability("how are you?".to_string(), false, "default".to_string()).await;
match result {
Ok(mut out) => {
while let Some(val) = &out.next().await {
match val {
Ok(val) => {
println!("{:?}", val.reason)
},
Err(e) => println!("{:?}", e)
}
}
},
Err(e) => println!("{:?}", e)
}
()
}
4. 如何使用能力组
能力组用于控制Co-pilot将访问的能力列表。您可以在使用 invoke_capability
方法时使用能力组
let result = client.invoke_capability("how are you?".to_string(), false, "<CAPABILITY_GROUP>".to_string()).await;
match result {
Ok(mut out) => {
while let Some(val) = &out.next().await {
match val {
Ok(val) => {
println!("{:?}", val.reason)
},
Err(e) => println!("{:?}", e)
}
}
},
Err(e) => println!("{:?}", e)
}
()
依赖关系
~5–16MB
~234K SLoC