async_gigachat/lib.rs
1//! Async Rust library for GigaChat REST API based on GigaChatAPI spec.
2//!
3//! ## Creating client
4//!
5//! ```
6//! use async_gigachat::{client::Client, config::GigaChatConfig};
7//!
8//! // Create a GigaChat client with authorization token from env var GIGACHAT_AUTH_TOKEN with scope env var GIGACHAT_API_SCOPE and default auth url, base url.
9//! let client = Client::new();
10//!
11//! // Above is shortcut for
12//! let config = GigaChatConfig::default();
13//! let client = Client::with_config(config);
14//!
15//! // OR use authorization token and scope from different source
16//! let auth_token = "YTAxNj...";
17//! let config = GigaChatConfig::builder()
18//! .auth_token(auth_token)
19//! .scope("GIGACHAT_API_PERS")
20//! .build();
21//!
22//! let client = Client::with_config(config);
23//!
24//! // Use custom auth url or base url
25//! let config = GigaChatConfig::builder()
26//! .auth_url("https://myhost.com/api/v1/oauth")
27//! .api_base_url("https://myhost.com/api/v2")
28//! .build();
29//!
30//! let client = Client::with_config(config);
31//! ```
32//!
33//! ## Making requests
34//!
35//!```
36//!# tokio_test::block_on(async {
37//!
38//! use async_gigachat::{
39//! chat::{Chat, ChatCompletionRequestBuilder, ChatMessage, Role},
40//! client::Client,
41//! config::GigaChatConfig,
42//! };
43//!
44//! // Create client
45//! let client = Client::new();
46//!
47//! // Create request using builder pattern
48//! let request = ChatCompletionRequestBuilder::default()
49//! .messages(vec![ChatMessage {
50//! role: Some(Role::User),
51//! content: "Hey, how's it going?".into(),
52//! }])
53//! .model("GigaChat:latest")
54//! .build()
55//! .unwrap();
56//!
57//! // Call API
58//! let response = Chat::new(client)
59//! .completion(request)
60//! .await
61//! .unwrap();
62//!
63//! println!("{}", response.choices.get(0).unwrap().message.content);
64//! # });
65//!```
66//!
67//! ## Examples
68//! For full working examples for all supported features see [examples](https://github.com/xsayler/async-gigachat/tree/main/examples) directory in the repository.
69//!
70pub mod api;
71pub mod chat;
72pub mod client;
73pub mod config;
74pub mod errors;
75pub mod model;
76pub mod result;
77pub mod token;