Skip to main content

save_async

Function save_async 

Source
pub async fn save_async<S: AsyncStore + ?Sized>(
    store: &S,
    log: &str,
    conversation: &mut Conversation,
) -> Result<(), SessionError>
Expand description

save to an AsyncStore: the log read once, then the blobs of new images written, then the changes appended with one write, which the store makes only if the log is still as it was read. A save reads only its own log, so one store holds many conversations, a log each. A save cut short, such as by a dropped future, has appended nothing, a cut last line (set aside by the next save), or, for a remote store that already applied it, all of it.

use rig_core::message::Message;
use rig_memory::{MemoryStore, load_async, save_async};

let store = MemoryStore::default();
let mut conversation = load_async(&store, "user-123").await?;
conversation.push(Message::user("My name is Alice."));
save_async(&store, "user-123", &mut conversation).await?;
assert_eq!(load_async(&store, "user-123").await?, conversation);

ยงErrors

As save. Of two saves that read the log at the same length, even at once, the store takes one and the other fails with SessionError::Changed. A save that fails leaves conversation with its unsaved changes, so it can be tried again.