Skip to main content

prompt_getter

Function prompt_getter 

Source
pub fn prompt_getter<F, Fut>(get: F) -> PromptHandler
where F: Fn(RequestContext, JsonObject) -> Fut + Send + Sync + 'static, Fut: Future<Output = Vec<PromptMessage>> + Send + 'static,
Expand description

Adapts a prompt getter into the PromptHandler a server stores.

Takes a future, as resource_reader does. A reader that has nothing to await is written as a plain fn and wrapped by #[server]’s expansion; calling the adapter directly means passing an async fn, because wrapping is the macro’s job and doing it here would mean every caller writes it.

The revision the content blocks are spelled for comes from the context, not from a parameter, because it is the session’s answer and not the caller’s to guess.

§Examples

use protocol_droid::application::server::builder::PromptHandler;
use protocol_droid::application::server::context::RequestContext;
use protocol_droid::application::server::read::prompt_getter;
use protocol_droid::domain::ir::{
    Content, JsonObject, PromptMessage, Role, TextContent,
};

async fn greeting(_context: RequestContext, _arguments: JsonObject) -> Vec<PromptMessage> {
    vec![PromptMessage::new(
        Role::User,
        Content::Text(TextContent::new("hello")),
    )]
}

let handler: PromptHandler = prompt_getter(greeting);
assert!(std::sync::Arc::strong_count(&handler) >= 1);