api_openai/components/completions_legacy.rs
1//! Structures related to the legacy Completions API.
2
3/// Define a private namespace for all its items.
4mod private
5{
6 // Use full paths from crate root for components
7 use crate::components::common::CompletionUsage;
8 // Serde imports
9 use serde::{ Serialize, Deserialize };
10 // Std imports
11 use std::collections::HashMap;
12
13 /// Log probability information for the choice.
14 ///
15 /// # Used By
16 /// - `CompletionChoice`
17 #[ derive( Debug, Serialize, Deserialize, Clone, PartialEq ) ] // Added Serialize
18 pub struct CompletionLogProbs
19 {
20 /// The character offset from the start of the prompt for each token.
21 #[ serde( skip_serializing_if = "Option::is_none" ) ]
22 pub text_offset : Option< Vec< i32 > >,
23 /// The log probability of each token chosen.
24 #[ serde( skip_serializing_if = "Option::is_none" ) ]
25 pub token_logprobs : Option< Vec< f64 > >,
26 /// The tokens chosen by the model.
27 #[ serde( skip_serializing_if = "Option::is_none" ) ]
28 pub tokens : Option< Vec< String > >,
29 /// A map of the most likely tokens and their log probability, at each token position.
30 #[ serde( skip_serializing_if = "Option::is_none" ) ]
31 pub top_logprobs : Option< Vec< HashMap< String, f64 > > >,
32 }
33
34 /// Represents one possible completion choice.
35 ///
36 /// # Used By
37 /// - `CreateCompletionResponse`
38 #[ derive( Debug, Serialize, Deserialize, Clone, PartialEq ) ] // Added Serialize
39 pub struct CompletionChoice
40 {
41 /// The reason the model stopped generating tokens.
42 pub finish_reason : String, // Enum : stop, length, content_filter
43 /// The index of the choice in the list of choices.
44 pub index : i32,
45 /// Log probability information for the choice.
46 pub logprobs : Option< CompletionLogProbs >,
47 /// The generated completion text.
48 pub text : String,
49 }
50
51 /// Represents a completion response from the legacy API.
52 /// Note : both the streamed and non-streamed response objects share the same shape.
53 ///
54 /// # Used By
55 /// - `/completions` (POST)
56 #[ derive( Debug, Serialize, Deserialize, Clone, PartialEq ) ] // Added Serialize
57 pub struct CreateCompletionResponse
58 {
59 /// A unique identifier for the completion.
60 pub id : String,
61 /// The list of completion choices the model generated for the input prompt.
62 pub choices : Vec< CompletionChoice >,
63 /// The Unix timestamp (in seconds) of when the completion was created.
64 pub created : i64,
65 /// The model used for completion.
66 pub model : String,
67 /// This fingerprint represents the backend configuration that the model runs with.
68 #[ serde( skip_serializing_if = "Option::is_none" ) ]
69 pub system_fingerprint : Option< String >,
70 /// The object type, which is always "`text_completion`".
71 pub object : String,
72 /// Usage statistics for the completion request.
73 #[ serde( skip_serializing_if = "Option::is_none" ) ]
74 pub usage : Option< CompletionUsage >,
75 }
76} // end mod private
77
78crate ::mod_interface!
79{
80 exposed use
81 {
82 CompletionLogProbs,
83 CompletionChoice,
84 CreateCompletionResponse
85 };
86}