-
Notifications
You must be signed in to change notification settings - Fork 984
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core, webserver): add /v1/models api (#3164)
* draft: feat(core, webserver): add /v1/models api * seperate models file * update model api * embedding model pattern match * polish * fix comments * rename return structure * [autofix.ci] apply automated fixes * fix comments except pass state * [autofix.ci] apply automated fixes * pass config to model api through state * [autofix.ci] apply automated fixes * draft: to be fix shared reference * fix config pass through state * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
dab77d0
commit 906e2c2
Showing
4 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use std::sync::Arc; | ||
|
||
use axum::{extract::State, Json}; | ||
use serde::{Deserialize, Serialize}; | ||
use utoipa::ToSchema; | ||
|
||
#[derive(Serialize, Deserialize, ToSchema, Clone, Debug)] | ||
pub struct ModelInfo { | ||
completion: Option<Vec<String>>, | ||
chat: Option<Vec<String>>, | ||
} | ||
|
||
impl From<tabby_common::config::Config> for ModelInfo { | ||
fn from(value: tabby_common::config::Config) -> Self { | ||
let models = value.model; | ||
let mut http_model_configs: ModelInfo = ModelInfo { | ||
completion: None, | ||
chat: None, | ||
}; | ||
|
||
if let Some(tabby_common::config::ModelConfig::Http(completion_http_config)) = | ||
models.completion | ||
{ | ||
if let Some(models) = completion_http_config.supported_models { | ||
http_model_configs.completion = Some(models.clone()); | ||
} | ||
} | ||
|
||
if let Some(tabby_common::config::ModelConfig::Http(chat_http_config)) = models.chat { | ||
if let Some(models) = chat_http_config.supported_models { | ||
http_model_configs.chat = Some(models.clone()); | ||
} | ||
} | ||
|
||
http_model_configs | ||
} | ||
} | ||
|
||
#[utoipa::path( | ||
get, | ||
path = "/v1beta/models", | ||
tag = "v1beta", | ||
operation_id = "config", | ||
responses( | ||
(status = 200, description = "Success", body = ServerSetting, content_type = "application/json"), | ||
), | ||
security( | ||
("token" = []) | ||
) | ||
)] | ||
pub async fn models(State(state): State<Arc<ModelInfo>>) -> Json<ModelInfo> { | ||
Json(state.as_ref().clone()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters