Skip to content

Commit d6c227e

Browse files
Update docs (#1422)
- lib.rs: clean up example var names and match logging change from 201d6be - server_builder: fix typo - READMEs: link to crate docs
1 parent ecb6907 commit d6c227e

File tree

4 files changed

+24
-18
lines changed

4 files changed

+24
-18
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ OpenAI API compatible API server
182182
- [API Docs](docs/HTTP.md).
183183
- [Launching the server or use the CLI](README.md#run-with-the-cli)
184184
- [Example](examples/server/chat.py)
185+
- [Use or extend the server in other axum projects](https://ericlbuehler.github.io/mistral.rs/mistralrs_server_core/)
185186
186187
187188
### Llama Index integration

mistralrs-server-core/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
Core crate that powers `mistral.rs server`.
44

5-
Documentation: TBD
5+
Documentation: https://ericlbuehler.github.io/mistral.rs/mistralrs_server_core/

mistralrs-server-core/src/lib.rs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
//! use utoipa::OpenApi;
2222
//! use utoipa_swagger_ui::SwaggerUi;
2323
//!
24-
//! use mistralrs::{AutoDeviceMapParams, ChatCompletionChunkResponse, ModelDType, ModelSelected};
24+
//! use mistralrs::{
25+
//! AutoDeviceMapParams, ChatCompletionChunkResponse, ModelDType, ModelSelected, initialize_logging,
26+
//! };
2527
//! use mistralrs_server_core::{
2628
//! chat_completion::{
2729
//! ChatCompletionResponder, OnChunkCallback, OnDoneCallback, create_chat_streamer,
@@ -51,12 +53,14 @@
5153
//!
5254
//! #[derive(Clone)]
5355
//! pub struct AppState {
54-
//! pub mistral_state: SharedMistralRsState,
56+
//! pub mistralrs_state: SharedMistralRsState,
5557
//! pub db_create: fn(),
5658
//! }
5759
//!
5860
//! #[tokio::main]
5961
//! async fn main() {
62+
//! initialize_logging();
63+
//!
6064
//! let plain_model_id = String::from("meta-llama/Llama-3.2-1B-Instruct");
6165
//! let tokenizer_json = None;
6266
//! let arch = None;
@@ -96,30 +100,30 @@
96100
//! .await
97101
//! .unwrap();
98102
//!
99-
//! let mistral_base_path = "/api/mistral";
103+
//! let mistralrs_base_path = "/api/mistral";
100104
//!
101-
//! let mistral_routes = MistralRsServerRouterBuilder::new()
105+
//! let mistralrs_routes = MistralRsServerRouterBuilder::new()
102106
//! .with_mistralrs(shared_mistralrs.clone())
103107
//! .with_include_swagger_routes(false)
104-
//! .with_base_path(mistral_base_path)
108+
//! .with_base_path(mistralrs_base_path)
105109
//! .build()
106110
//! .await
107111
//! .unwrap();
108112
//!
109-
//! let mistral_doc = get_openapi_doc(Some(mistral_base_path));
113+
//! let mistralrs_doc = get_openapi_doc(Some(mistralrs_base_path));
110114
//! let mut api_docs = ApiDoc::openapi();
111-
//! api_docs.merge(mistral_doc);
115+
//! api_docs.merge(mistralrs_doc);
112116
//!
113117
//! let app_state = Arc::new(AppState {
114-
//! mistral_state: shared_mistralrs,
118+
//! mistralrs_state: shared_mistralrs,
115119
//! db_create: mock_db_call,
116120
//! });
117121
//!
118122
//! let app = Router::new()
119123
//! .route("/", get(root))
120124
//! .route("/chat", post(custom_chat))
121125
//! .with_state(app_state.clone())
122-
//! .nest(mistral_base_path, mistral_routes)
126+
//! .nest(mistralrs_base_path, mistralrs_routes)
123127
//! .merge(SwaggerUi::new("/api-docs").url("/api-docs/openapi.json", api_docs));
124128
//!
125129
//! let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
@@ -151,19 +155,19 @@
151155
//! State(state): State<Arc<AppState>>,
152156
//! Json(oai_request): Json<ChatCompletionRequest>,
153157
//! ) -> ChatCompletionResponder {
154-
//! let mistral_state = state.mistral_state.clone();
158+
//! let mistralrs_state = state.mistralrs_state.clone();
155159
//! let (tx, mut rx) = create_response_channel(None);
156160
//!
157-
//! let (request, is_streaming) = match parse_request(oai_request, mistral_state.clone(), tx).await
161+
//! let (request, is_streaming) = match parse_request(oai_request, mistralrs_state.clone(), tx).await
158162
//! {
159163
//! Ok(x) => x,
160-
//! Err(e) => return handle_chat_completion_error(mistral_state, e.into()),
164+
//! Err(e) => return handle_chat_completion_error(mistralrs_state, e.into()),
161165
//! };
162166
//!
163167
//! dbg!(request.clone());
164168
//!
165-
//! if let Err(e) = send_request(&mistral_state, request).await {
166-
//! return handle_chat_completion_error(mistral_state, e.into());
169+
//! if let Err(e) = send_request(&mistralrs_state, request).await {
170+
//! return handle_chat_completion_error(mistralrs_state, e.into());
167171
//! }
168172
//!
169173
//! if is_streaming {
@@ -185,15 +189,16 @@
185189
//! });
186190
//!
187191
//! let streamer =
188-
//! create_chat_streamer(rx, mistral_state.clone(), Some(on_chunk), Some(on_done));
192+
//! create_chat_streamer(rx, mistralrs_state.clone(), Some(on_chunk), Some(on_done));
189193
//!
190194
//! ChatCompletionResponder::Sse(streamer)
191195
//! } else {
192-
//! let response = process_non_streaming_chat_response(&mut rx, mistral_state.clone()).await;
196+
//! let response = process_non_streaming_chat_response(&mut rx, mistralrs_state.clone()).await;
193197
//!
194198
//! match &response {
195199
//! ChatCompletionResponder::Json(json_response) => {
196200
//! dbg!(json_response);
201+
//! (state.db_create)();
197202
//! }
198203
//! _ => {
199204
//! //

mistralrs-server-core/src/mistralrs_for_server_builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub mod defaults {
4444
pub const TOKEN_SOURCE: mistralrs_core::TokenSource = mistralrs_core::TokenSource::CacheToken;
4545
}
4646

47-
/// A builder for creating a the mistral.rs instance with configured options used for the mistral.rs server.
47+
/// A builder for creating a mistral.rs instance with configured options for the mistral.rs server.
4848
///
4949
/// ### Examples
5050
///

0 commit comments

Comments
 (0)