mirror of
https://github.com/katanemo/plano.git
synced 2026-05-09 07:42:43 +02:00
add support for openwebui (#487)
This commit is contained in:
parent
4899117876
commit
9c4733590f
8 changed files with 150 additions and 24 deletions
40
crates/brightstaff/src/handlers/models.rs
Normal file
40
crates/brightstaff/src/handlers/models.rs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
use bytes::Bytes;
|
||||
use common::api::open_ai::Models;
|
||||
use common::configuration::LlmProvider;
|
||||
use http_body_util::{combinators::BoxBody, BodyExt, Full};
|
||||
use hyper::{Response, StatusCode};
|
||||
use serde_json;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub async fn list_models(
|
||||
llm_providers: Arc<Vec<LlmProvider>>,
|
||||
) -> Response<BoxBody<Bytes, hyper::Error>> {
|
||||
let prov = llm_providers.clone();
|
||||
let providers = (*prov).clone();
|
||||
let openai_models = Models::from(providers);
|
||||
|
||||
match serde_json::to_string(&openai_models) {
|
||||
Ok(json) => {
|
||||
let body = Full::new(Bytes::from(json))
|
||||
.map_err(|never| match never {})
|
||||
.boxed();
|
||||
Response::builder()
|
||||
.status(StatusCode::OK)
|
||||
.header("Content-Type", "application/json")
|
||||
.body(body)
|
||||
.unwrap()
|
||||
}
|
||||
Err(_) => {
|
||||
let body = Full::new(Bytes::from_static(
|
||||
b"{\"error\":\"Failed to serialize models\"}",
|
||||
))
|
||||
.map_err(|never| match never {})
|
||||
.boxed();
|
||||
Response::builder()
|
||||
.status(StatusCode::INTERNAL_SERVER_ERROR)
|
||||
.header("Content-Type", "application/json")
|
||||
.body(body)
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue