mirror of
https://github.com/open-webui/open-webui
synced 2025-05-17 12:03:41 +00:00
refac: base models endpoint
This commit is contained in:
parent
7e78889e33
commit
19c98b74fa
@ -915,8 +915,7 @@ app.mount("/api/v1", webui_app)
|
|||||||
webui_app.state.EMBEDDING_FUNCTION = retrieval_app.state.EMBEDDING_FUNCTION
|
webui_app.state.EMBEDDING_FUNCTION = retrieval_app.state.EMBEDDING_FUNCTION
|
||||||
|
|
||||||
|
|
||||||
async def get_all_models():
|
async def get_all_base_models():
|
||||||
# TODO: Optimize this function
|
|
||||||
open_webui_models = []
|
open_webui_models = []
|
||||||
openai_models = []
|
openai_models = []
|
||||||
ollama_models = []
|
ollama_models = []
|
||||||
@ -942,6 +941,11 @@ async def get_all_models():
|
|||||||
open_webui_models = await get_open_webui_models()
|
open_webui_models = await get_open_webui_models()
|
||||||
|
|
||||||
models = open_webui_models + openai_models + ollama_models
|
models = open_webui_models + openai_models + ollama_models
|
||||||
|
return models
|
||||||
|
|
||||||
|
|
||||||
|
async def get_all_models():
|
||||||
|
models = await get_all_base_models()
|
||||||
|
|
||||||
# If there are no models, return an empty list
|
# If there are no models, return an empty list
|
||||||
if len([model for model in models if model["owned_by"] != "arena"]) == 0:
|
if len([model for model in models if model["owned_by"] != "arena"]) == 0:
|
||||||
@ -1084,6 +1088,12 @@ async def get_models(user=Depends(get_verified_user)):
|
|||||||
return {"data": models}
|
return {"data": models}
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/api/models/base")
|
||||||
|
async def get_base_models(user=Depends(get_admin_user)):
|
||||||
|
models = await get_all_base_models()
|
||||||
|
return {"data": models}
|
||||||
|
|
||||||
|
|
||||||
@app.post("/api/chat/completions")
|
@app.post("/api/chat/completions")
|
||||||
async def generate_chat_completions(
|
async def generate_chat_completions(
|
||||||
form_data: dict, user=Depends(get_verified_user), bypass_filter: bool = False
|
form_data: dict, user=Depends(get_verified_user), bypass_filter: bool = False
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
import { WEBUI_API_BASE_URL, WEBUI_BASE_URL } from '$lib/constants';
|
import { WEBUI_API_BASE_URL, WEBUI_BASE_URL } from '$lib/constants';
|
||||||
|
|
||||||
export const getModels = async (token: string = '') => {
|
export const getModels = async (token: string = '', base: boolean = false) => {
|
||||||
let error = null;
|
let error = null;
|
||||||
|
const res = await fetch(`${WEBUI_BASE_URL}/api/models${
|
||||||
const res = await fetch(`${WEBUI_BASE_URL}/api/models`, {
|
base ? '/base' : ''
|
||||||
|
}`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
Accept: 'application/json',
|
Accept: 'application/json',
|
||||||
@ -16,17 +17,17 @@ export const getModels = async (token: string = '') => {
|
|||||||
return res.json();
|
return res.json();
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.log(err);
|
|
||||||
error = err;
|
error = err;
|
||||||
|
console.log(err);
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
let models = res?.data ?? [];
|
let models = res?.data ?? [];
|
||||||
|
|
||||||
models = models
|
models = models
|
||||||
.filter((models) => models)
|
.filter((models) => models)
|
||||||
// Sort the models
|
// Sort the models
|
||||||
|
@ -43,7 +43,7 @@
|
|||||||
|
|
||||||
const init = async () => {
|
const init = async () => {
|
||||||
const workspaceModels = await getBaseModels(localStorage.token);
|
const workspaceModels = await getBaseModels(localStorage.token);
|
||||||
const allModels = await getModels(localStorage.token);
|
const allModels = await getModels(localStorage.token, true);
|
||||||
|
|
||||||
models = allModels
|
models = allModels
|
||||||
.filter((m) => !(m?.preset ?? false))
|
.filter((m) => !(m?.preset ?? false))
|
||||||
|
Loading…
Reference in New Issue
Block a user