async_llm/response/chat.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
use serde::{Deserialize, Serialize};
use crate::{
types::{ChatChoice, CompletionUsage, CompletionUsageStream},
Error, Printable,
};
use super::Respondable;
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ChatResponse {
/// A unique identifier for the chat completion.
pub id: Option<String>,
/// A list of chat completion choices. Can be more than one if n is greater than 1.
pub choices: Vec<ChatChoice>,
/// The Unix timestamp (in seconds) of when the chat completion was created.
pub created: Option<u32>,
/// The model used for the chat completion.
pub model: Option<String>,
/// The service tier used for processing the request.
pub service_tier: Option<String>,
/// This fingerprint represents the backend configuration that the model runs with.
///
/// Can be used in conjunction with the seed request parameter to understand when backend changes have been made that might impact determinism.
pub system_fingerprint: Option<String>,
/// The object type, which is always `chat.completion`.
pub object: Option<String>,
/// Usage statistics for the completion request.
pub usage: Option<CompletionUsage>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ChatResponseStream {
/// A unique identifier for the chat completion.
pub id: Option<String>,
/// A list of chat completion choices. Can be more than one if n is greater than 1.
pub choices: Vec<ChatChoice>,
/// The Unix timestamp (in seconds) of when the chat completion was created.
pub created: Option<u32>,
/// The model used for the chat completion.
pub model: Option<String>,
/// The service tier used for processing the request.
pub service_tier: Option<String>,
/// This fingerprint represents the backend configuration that the model runs with.
///
/// Can be used in conjunction with the seed request parameter to understand when backend changes have been made that might impact determinism.
pub system_fingerprint: Option<String>,
/// The object type, which is always `chat.completion.chunk`.
pub object: Option<String>,
/// Usage statistics for the completion request.
pub usage: Option<CompletionUsageStream>,
}
impl Respondable for ChatResponse {
fn is_success(&self) -> bool {
true
}
}
impl Printable for ChatResponse {
fn to_string_pretty(&self) -> Result<String, Error> {
Ok(serde_json::to_string_pretty(self)?)
}
}
impl Respondable for ChatResponseStream {
fn is_success(&self) -> bool {
true
}
}
impl Printable for ChatResponseStream {
fn to_string_pretty(&self) -> Result<String, Error> {
Ok(serde_json::to_string_pretty(self)?)
}
}