graphrt_core/text_model.rs
1//! A model that turns a system prompt and a user message into text.
2//!
3//! Work that happens outside a run (drafting a skill from a description,
4//! suggesting lessons from earlier feedback) needs one plain completion and
5//! nothing else of a chat model: no tools, no streaming, no run context. This
6//! trait is that much and no more, so the crates that do such work do not
7//! depend on a model provider. `graphrt-llm` implements it for any chat model.
8
9use std::fmt;
10
11use futures::future::BoxFuture;
12
13/// One completion request.
14#[derive(Clone, Debug, PartialEq, Eq)]
15pub struct TextRequest {
16 /// Instructions for the model.
17 pub system: String,
18 /// The material to work on.
19 pub user: String,
20 /// Upper bound of the answer, in tokens.
21 pub max_tokens: u32,
22}
23
24/// The model could not answer.
25#[derive(Clone, Debug, PartialEq, Eq, thiserror::Error)]
26#[error("{0}")]
27pub struct TextModelError(pub String);
28
29/// A model that answers one request with text.
30pub trait TextModel: Send + Sync + fmt::Debug {
31 /// Answer `request`.
32 fn complete(&self, request: TextRequest) -> BoxFuture<'_, Result<String, TextModelError>>;
33}