crabtalk_core/model/
mod.rs1use anyhow::Result;
7use futures_core::Stream;
8pub use limits::default_context_limit;
9pub use message::{Message, MessageBuilder, Role, estimate_tokens};
10pub use request::Request;
11pub use response::{
12 Choice, CompletionMeta, CompletionTokensDetails, Delta, FinishReason, Response, Usage,
13};
14pub use stream::StreamChunk;
15pub use tool::{FunctionCall, Tool, ToolCall, ToolChoice};
16
17mod limits;
18mod message;
19mod request;
20mod response;
21mod stream;
22mod tool;
23
24pub trait Model: Sized + Clone {
33 fn send(&self, request: &Request) -> impl Future<Output = Result<Response>> + Send;
35
36 fn stream(&self, request: Request) -> impl Stream<Item = Result<StreamChunk>> + Send;
38
39 fn context_limit(&self, model: &str) -> usize {
43 default_context_limit(model)
44 }
45
46 fn active_model(&self) -> String;
48}
49
50impl Model for () {
52 async fn send(&self, _request: &Request) -> Result<Response> {
53 panic!("NoopModel::send called — not intended for real LLM calls");
54 }
55
56 #[allow(unreachable_code)]
57 fn stream(&self, _request: Request) -> impl Stream<Item = Result<StreamChunk>> + Send {
58 panic!("NoopModel::stream called — not intended for real LLM calls");
59 async_stream::stream! {
60 yield Err(anyhow::anyhow!("not implemented"));
61 }
62 }
63
64 fn context_limit(&self, _model: &str) -> usize {
65 0
66 }
67
68 fn active_model(&self) -> String {
69 String::new()
70 }
71}