Skip to content

Commit 8bd9088

Browse files
committed
more docs
1 parent 669b6c0 commit 8bd9088

File tree

4 files changed

+64
-10
lines changed

4 files changed

+64
-10
lines changed

moly-kit/src/lib.rs

+55
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,58 @@
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+
156
pub mod clients;
257
pub mod protocol;
358
pub mod utils;

moly-kit/src/widgets/chat.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//! A batteries-included chat to to implement chatbots.
2-
31
use futures::{stream::AbortHandle, StreamExt};
42
use makepad_widgets::*;
53
use std::cell::{Ref, RefMut};
@@ -173,6 +171,7 @@ impl<'e> ChatHookWriter<'e> {
173171
}
174172
}
175173

174+
/// A batteries-included chat to to implement chatbots.
176175
#[derive(Live, LiveHook, Widget)]
177176
pub struct Chat {
178177
#[deref]
@@ -490,6 +489,8 @@ fn chat_actions<'e>(
490489
.filter(move |a| a.widget_uid == widget_uid)
491490
}
492491

492+
// TODO: Since `ChatRef` is generated by a macro, I can't document this to give
493+
// these functions better visibility from the module view.
493494
impl ChatRef {
494495
/// Immutable access to the underlying [Chat].
495496
///

moly-kit/src/widgets/messages.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
//! View over a conversation with messages.
2-
//!
3-
//! This is mostly a dummy widget. Prefer using and adapting [crate::widgets::chat::Chat] instead.
4-
51
use std::cell::{Ref, RefMut};
62

73
use crate::{
@@ -233,6 +229,9 @@ struct Editor {
233229
buffer: String,
234230
}
235231

232+
/// View over a conversation with messages.
233+
///
234+
/// This is mostly a dummy widget. Prefer using and adapting [crate::widgets::chat::Chat] instead.
236235
#[derive(Live, LiveHook, Widget)]
237236
pub struct Messages {
238237
#[deref]

moly-kit/src/widgets/prompt_input.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
//! A prepared text input for conversation with bots.
2-
//!
3-
//! This is mostly a dummy widget. Prefer using and adapting [crate::widgets::chat::Chat] instead.
4-
51
use makepad_widgets::*;
62
use std::cell::{Ref, RefMut};
73

@@ -98,6 +94,9 @@ pub enum Interactivity {
9894
Disabled,
9995
}
10096

97+
/// A prepared text input for conversation with bots.
98+
///
99+
/// This is mostly a dummy widget. Prefer using and adapting [crate::widgets::chat::Chat] instead.
101100
#[derive(Live, LiveHook, Widget)]
102101
pub struct PromptInput {
103102
#[deref]

0 commit comments

Comments
 (0)