Crates.io | async-gigachat |
lib.rs | async-gigachat |
version | 0.2.0 |
source | src |
created_at | 2023-11-06 10:09:55.752293 |
updated_at | 2024-01-05 13:02:49.592814 |
description | Async bindings for Gigachat API |
homepage | https://github.com/xsayler/async-gigachat |
repository | https://github.com/xsayler/async-gigachat |
max_upload_size | |
id | 1026719 |
size | 73,828 |
Async Rust library for GigaChat
async-gigachat
is an unofficial Rust library for GigaChat REST API.
The library reads Authorization token from the environment variable GIGACHAT_AUTH_TOKEN
.
# On macOS/Linux
export GIGACHAT_AUTH_TOKEN='YTAxNj...'
# On Windows Powershell
$Env:GIGACHAT_AUTH_TOKEN='YTAxNj...'
async-gigachat
.use anyhow::Ok;
use async_gigachat::{
chat::{ChatCompletionRequestBuilder, ChatMessageBuilder, Role, Chat},
client::Client,
config::GigaChatConfig,
};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let config = GigaChatConfig::default();
let client: Client = Client::with_config(config);
let question = ChatMessageBuilder::default()
.role(Role::User)
.content("Hey, how's it going?")
.build()?;
let request = ChatCompletionRequestBuilder::default()
.messages(vec![question.clone()])
.model("GigaChat:latest")
.build()?;
let response = Chat::new(client).completion(request).await?;
println!("{}: {}", question.role, question.content);
println!("{}: {}", response.choices.get(0).unwrap().message.role, response.choices.get(0).unwrap().message.content);
Ok(())
}
This project is licensed under MIT license.