open_routerer/types/
completion.rs

1use serde::{Deserialize, Serialize};
2
3/// Represents a text completion request. It minimally contains:
4/// - `model`: The model ID to use.
5/// - `prompt`: The text prompt to be completed.
6///
7/// Any extra parameters (e.g., `temperature`, `top_p`, etc.) can also be provided and will be flattened
8/// into the resulting JSON.
9#[derive(Debug, Serialize)]
10pub struct CompletionRequest {
11    pub model: String,
12    pub prompt: String,
13    #[serde(flatten)]
14    pub extra_params: serde_jsonc2::Value,
15}
16
17/// Represents a choice returned by the completions endpoint.
18#[derive(Debug, Deserialize)]
19pub struct CompletionChoice {
20    pub text: String,
21    pub index: Option<u32>,
22    #[serde(rename = "finish_reason")]
23    pub finish_reason: Option<String>,
24}
25
26/// Represents the text completion response. It includes:
27/// - an optional `id` for the request
28/// - a list of choices with the completed text
29#[derive(Debug, Deserialize)]
30pub struct CompletionResponse {
31    pub id: Option<String>,
32    pub choices: Vec<CompletionChoice>,
33}