use crate::core::ChatMessage;
use crate::engine::SamplingRuntimeOverride;
use crate::client::EndpointRef;
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct SippRequestContext {
pub request_id: Option<String>,
}
pub type RequestExtra = serde_json::Map<String, serde_json::Value>;
pub const DEFAULT_TRANSCRIPTION_MAX_TOKENS: u32 = 512;
#[derive(Debug, Clone, PartialEq, Default)]
pub struct SippTextOptions {
pub max_tokens: Option<u32>,
pub temperature: Option<f32>,
pub top_p: Option<f32>,
pub stop: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Default)]
pub struct LocalTextOptions {
pub context_key: Option<String>,
pub grammar: Option<String>,
pub json_schema: Option<String>,
pub sampling: Option<SamplingRuntimeOverride>,
pub media: Vec<Vec<u8>>,
}
impl LocalTextOptions {
#[cfg(not(target_family = "wasm"))]
pub(crate) fn has_fields(&self) -> bool {
self.context_key.is_some()
|| self.grammar.is_some()
|| self.json_schema.is_some()
|| self.sampling.is_some()
|| !self.media.is_empty()
}
}
#[derive(Debug, Clone, PartialEq, Default)]
pub struct LocalEmbedOptions {
pub context_key: Option<String>,
pub normalize: Option<bool>,
}
impl LocalEmbedOptions {
#[cfg(not(target_family = "wasm"))]
pub(crate) fn has_fields(&self) -> bool {
self.context_key.is_some() || self.normalize.is_some()
}
}
#[derive(Debug, Clone, PartialEq, Default)]
pub struct SippQueryRequest {
pub endpoint: Option<EndpointRef>,
pub prompt: String,
pub options: SippTextOptions,
pub local: LocalTextOptions,
pub extra: RequestExtra,
pub emit_tokens: bool,
}
#[derive(Debug, Clone, PartialEq, Default)]
pub struct SippChatRequest {
pub endpoint: Option<EndpointRef>,
pub messages: Vec<ChatMessage>,
pub options: SippTextOptions,
pub local: LocalTextOptions,
pub extra: RequestExtra,
pub emit_tokens: bool,
}
#[derive(Debug, Clone, PartialEq, Default)]
pub struct SippEmbedRequest {
pub endpoint: Option<EndpointRef>,
pub input: String,
pub local: LocalEmbedOptions,
pub extra: RequestExtra,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SippListenRequest {
pub endpoint: Option<EndpointRef>,
pub audio: Vec<u8>,
pub language: Option<String>,
pub max_tokens: Option<u32>,
}
impl SippListenRequest {
pub fn new(audio: impl Into<Vec<u8>>) -> Self {
Self {
endpoint: None,
audio: audio.into(),
language: None,
max_tokens: None,
}
}
pub fn language(mut self, language: impl Into<String>) -> Self {
self.language = Some(language.into());
self
}
pub fn max_tokens(mut self, max_tokens: u32) -> Self {
self.max_tokens = Some(max_tokens);
self
}
}
impl From<Vec<u8>> for SippListenRequest {
fn from(audio: Vec<u8>) -> Self {
Self::new(audio)
}
}
impl From<&[u8]> for SippListenRequest {
fn from(audio: &[u8]) -> Self {
Self::new(audio)
}
}
impl<const N: usize> From<[u8; N]> for SippListenRequest {
fn from(audio: [u8; N]) -> Self {
Self::new(audio)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SippSpeakRequest {
pub endpoint: Option<EndpointRef>,
pub text: String,
pub language: Option<String>,
pub speaker_audio: Option<Vec<u8>>,
pub max_duration_ms: Option<u32>,
}
impl SippSpeakRequest {
pub fn new(text: impl Into<String>) -> Self {
Self {
endpoint: None,
text: text.into(),
language: None,
speaker_audio: None,
max_duration_ms: None,
}
}
pub fn language(mut self, language: impl Into<String>) -> Self {
self.language = Some(language.into());
self
}
pub fn speaker(mut self, audio: impl Into<Vec<u8>>) -> Self {
self.speaker_audio = Some(audio.into());
self
}
pub fn max_duration_ms(mut self, max_duration_ms: u32) -> Self {
self.max_duration_ms = Some(max_duration_ms);
self
}
}
impl From<String> for SippSpeakRequest {
fn from(text: String) -> Self {
Self::new(text)
}
}
impl From<&str> for SippSpeakRequest {
fn from(text: &str) -> Self {
Self::new(text)
}
}