Skip to main content

sim_lib_openai_server/codec_openai/
shapes.rs

1use sim_codec_chat::validate_chat_transcript;
2use sim_kernel::{Expr, Result};
3
4/// Validated chat transcript expression accepted by `codec:openai`.
5#[derive(Clone, Debug, PartialEq)]
6pub struct ChatTranscript {
7    expr: Expr,
8}
9
10impl ChatTranscript {
11    /// Validates `expr` as a chat transcript and wraps it.
12    pub fn new(expr: Expr) -> Result<Self> {
13        validate_chat_transcript(&expr)?;
14        Ok(Self { expr })
15    }
16
17    /// Returns the wrapped transcript expression.
18    pub fn expr(&self) -> &Expr {
19        &self.expr
20    }
21
22    /// Consumes the wrapper and returns the transcript expression.
23    pub fn into_expr(self) -> Expr {
24        self.expr
25    }
26}
27
28/// Options for OpenAI-compatible provider request JSON generation.
29#[derive(Clone, Debug, PartialEq, Eq)]
30pub struct OpenAiCodecOptions {
31    /// Model identifier to place in the generated request.
32    pub model: String,
33    /// Whether to request a streamed (SSE) response.
34    pub stream: bool,
35    /// Whether to include the `tools` field in the generated request.
36    pub tools: bool,
37}
38
39impl OpenAiCodecOptions {
40    /// Builds codec options from a model id and the stream/tools flags.
41    pub fn new(model: impl Into<String>, stream: bool, tools: bool) -> Self {
42        Self {
43            model: model.into(),
44            stream,
45            tools,
46        }
47    }
48}
49
50/// Alias for [`OpenAiCodecOptions`] when used as request-generation options.
51pub type OpenAiRequestOptions = OpenAiCodecOptions;