|
| 1 | +//! # Basic usage |
| 2 | +//! |
| 3 | +//! ## Installation |
| 4 | +//! Add MolyKit to your dependencies. |
| 5 | +//! ```toml |
| 6 | +//! moly-kit = { version = "*", features = ["full"] } |
| 7 | +//! ``` |
| 8 | +//! |
| 9 | +//! ## DSL |
| 10 | +//! Import the batteries-included [Chat] widget. |
| 11 | +//! ``` |
| 12 | +//! use moly_kit::widgets::chat::Chat; |
| 13 | +//! ``` |
| 14 | +//! Then, add it somewhere in your parent widget. |
| 15 | +//! ``` |
| 16 | +//! chat = <Chat> {} |
| 17 | +//! ``` |
| 18 | +//! |
| 19 | +//! ## Rust |
| 20 | +//! We need to give the chat a [BotRepo], which allows [Chat] to pull information |
| 21 | +//! about the available bots and send messages to them. |
| 22 | +//! |
| 23 | +//! A [BotRepo] can be directly created from a [BotClient], which interacts |
| 24 | +//! with (mostly remote) bot providers like OpenAI, Ollama, OpenRouter, |
| 25 | +//! Moly Server, MoFa, etc. |
| 26 | +//! |
| 27 | +//! An OpenAI compatible client comes out-of-the-box with MolyKit, [MolyClient]. |
| 28 | +//! |
| 29 | +//! So, add the following somewhere appropriate (like in `after_new_from_doc` |
| 30 | +//! from Makepad) to give [Chat] its [ChatRepo]: |
| 31 | +//! ```rust |
| 32 | +//! use moly_kit::* |
| 33 | +//! |
| 34 | +//! let mut client = MolyClient::new("https://api.openai.com".into()); |
| 35 | +//! client.set_key("<YOUR_KEY>".into()); |
| 36 | +//! |
| 37 | +//! let repo = BotRepo::from(client); |
| 38 | +//! |
| 39 | +//! self.chat(id!(chat)).write_with(|chat| { |
| 40 | +//! chat.bot_repo = repo; |
| 41 | +//! }) |
| 42 | +//! ``` |
| 43 | +//! |
| 44 | +//! # Advanced usage |
| 45 | +//! [Chat] is by default a very automatic widget, but it exposes its lifecycle |
| 46 | +//! through a "hook" mechanism. This mechanism allows you to: |
| 47 | +//! - Know that something will happen. |
| 48 | +//! - Know that something already happened. |
| 49 | +//! - Abort something before it happens. |
| 50 | +//! - Replace that aborted thing with something else. |
| 51 | +//! - Inject tasks to be executed by the [Chat]. |
| 52 | +//! - Change the payload of a task affecting the operation when executed. |
| 53 | +//! |
| 54 | +//! TODO: Continue writing. |
| 55 | +
|
1 | 56 | pub mod clients;
|
2 | 57 | pub mod protocol;
|
3 | 58 | pub mod utils;
|
|
0 commit comments