mod decode;
mod encode;
use crate::canonical::{CanonicalError, CanonicalRequest, Event};
use crate::protocol::{
DecodeState, Frame, Framing, ModelKeys, ModelsShape, Protocol, ProviderCtx, WireRequest,
};
pub struct OllamaChat;
impl Protocol for OllamaChat {
fn encode(
&self,
req: &CanonicalRequest,
ctx: &ProviderCtx,
) -> Result<WireRequest, CanonicalError> {
encode::encode(req, ctx)
}
fn path(&self, _ctx: &ProviderCtx) -> String {
encode::REQUEST_PATH.to_string()
}
fn content_type(&self) -> &str {
"application/json"
}
fn decode(&self, frame: Frame, state: &mut DecodeState) -> Result<Vec<Event>, CanonicalError> {
decode::decode(frame, state)
}
fn decode_full(
&self,
body: &[u8],
state: &mut DecodeState,
) -> Result<Vec<Event>, CanonicalError> {
decode::decode_full(body, state)
}
fn framing(&self) -> Framing {
Framing::Ndjson
}
fn models_shape(&self) -> Option<ModelsShape> {
Some(ModelsShape {
path: "/api/tags",
keys: ModelKeys {
array_key: "models",
id_key: "name",
strip: "",
context_key: "",
max_output_key: "",
display_name_key: "",
},
})
}
}