use serde::{Deserialize, Serialize};
use crate::util::epoch_millis;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LlmCallRecord {
pub call_type: String,
pub prompt: String,
pub response: String,
pub model: String,
pub endpoint: String,
pub lora: Option<String>,
pub latency_ms: u64,
pub timestamp_ms: u64,
pub worker_id: Option<usize>,
pub error: Option<String>,
}
impl LlmCallRecord {
pub fn new(call_type: impl Into<String>, model: impl Into<String>) -> Self {
Self {
call_type: call_type.into(),
prompt: String::new(),
response: String::new(),
model: model.into(),
endpoint: String::new(),
lora: None,
latency_ms: 0,
timestamp_ms: epoch_millis(),
worker_id: None,
error: None,
}
}
pub fn prompt(mut self, prompt: impl Into<String>) -> Self {
self.prompt = prompt.into();
self
}
pub fn response(mut self, response: impl Into<String>) -> Self {
self.response = response.into();
self
}
pub fn endpoint(mut self, endpoint: impl Into<String>) -> Self {
self.endpoint = endpoint.into();
self
}
pub fn lora(mut self, lora: impl Into<String>) -> Self {
self.lora = Some(lora.into());
self
}
pub fn latency_ms(mut self, latency: u64) -> Self {
self.latency_ms = latency;
self
}
pub fn worker_id(mut self, id: usize) -> Self {
self.worker_id = Some(id);
self
}
pub fn error(mut self, error: impl Into<String>) -> Self {
self.error = Some(error.into());
self
}
pub fn is_success(&self) -> bool {
self.error.is_none() && !self.response.is_empty()
}
}