mistralrs_server_core/
openapi_doc.rs1use utoipa::OpenApi;
4
5use crate::{
6 chat_completion::__path_chatcompletions,
7 completions::__path_completions,
8 handlers::{ReIsqRequest, __path_health, __path_models, __path_re_isq},
9 image_generation::__path_image_generation,
10 openai::{
11 AudioResponseFormat, ChatCompletionRequest, CompletionRequest, FunctionCalled, Grammar,
12 ImageGenerationRequest, JsonSchemaResponseFormat, Message, MessageContent,
13 MessageInnerContent, ModelObject, ModelObjects, ResponseFormat, SpeechGenerationRequest,
14 StopTokens, ToolCall,
15 },
16 speech_generation::__path_speech_generation,
17};
18use mistralrs_core::{
19 ApproximateUserLocation, Function, ImageGenerationResponseFormat, SearchContextSize, Tool,
20 ToolChoice, ToolType, WebSearchOptions, WebSearchUserLocation,
21};
22
23pub fn get_openapi_doc(base_path: Option<&str>) -> utoipa::openapi::OpenApi {
63 #[derive(OpenApi)]
64 #[openapi(
65 paths(models, health, chatcompletions, completions, re_isq, image_generation, speech_generation),
66 components(schemas(
67 ApproximateUserLocation,
68 AudioResponseFormat,
69 ChatCompletionRequest,
70 CompletionRequest,
71 Function,
72 FunctionCalled,
73 Grammar,
74 ImageGenerationRequest,
75 ImageGenerationResponseFormat,
76 JsonSchemaResponseFormat,
77 Message,
78 MessageContent,
79 MessageInnerContent,
80 ModelObject,
81 ModelObjects,
82 ReIsqRequest,
83 ResponseFormat,
84 SearchContextSize,
85 SpeechGenerationRequest,
86 StopTokens,
87 Tool,
88 ToolCall,
89 ToolChoice,
90 ToolType,
91 WebSearchOptions,
92 WebSearchUserLocation
93 )),
94 tags(
95 (name = "Mistral.rs", description = "Mistral.rs API")
96 ),
97 info(
98 title = "Mistral.rs",
99 license(
100 name = "MIT",
101 )
102 )
103 )]
104 struct ApiDoc;
105
106 let mut doc = ApiDoc::openapi();
107
108 if let Some(prefix) = base_path {
109 if !prefix.is_empty() {
110 let mut prefixed_paths = utoipa::openapi::Paths::default();
111
112 let original_paths = std::mem::take(&mut doc.paths.paths);
113
114 for (path, item) in original_paths {
115 let prefixed_path = format!("{}{}", prefix, path);
116 prefixed_paths.paths.insert(prefixed_path, item);
117 }
118
119 prefixed_paths.extensions = doc.paths.extensions.clone();
120
121 doc.paths = prefixed_paths;
122 }
123 }
124
125 doc
126}