open-webui/backend/apps/web/routers/configs.py

61 lines
1.5 KiB
Python
Raw Normal View History

2024-01-03 00:48:10 +00:00
from fastapi import Response, Request
from fastapi import Depends, FastAPI, HTTPException, status
from datetime import datetime, timedelta
from typing import List, Union
from fastapi import APIRouter
from pydantic import BaseModel
import time
import uuid
from apps.web.models.users import Users
from config import config_set, config_get
2024-01-03 00:48:10 +00:00
2024-03-31 08:13:39 +00:00
from utils.utils import (
get_password_hash,
get_current_user,
get_admin_user,
create_token,
)
2024-01-03 00:48:10 +00:00
from utils.misc import get_gravatar_url, validate_email_format
from constants import ERROR_MESSAGES
router = APIRouter()
class SetDefaultModelsForm(BaseModel):
models: str
2024-01-23 05:07:40 +00:00
class PromptSuggestion(BaseModel):
title: List[str]
content: str
class SetDefaultSuggestionsForm(BaseModel):
suggestions: List[PromptSuggestion]
2024-01-03 00:48:10 +00:00
############################
# SetDefaultModels
############################
@router.post("/default/models", response_model=str)
2024-01-23 05:07:40 +00:00
async def set_global_default_models(
request: Request, form_data: SetDefaultModelsForm, user=Depends(get_admin_user)
2024-01-23 05:07:40 +00:00
):
config_set(request.app.state.DEFAULT_MODELS, form_data.models)
return config_get(request.app.state.DEFAULT_MODELS)
2024-01-23 05:07:40 +00:00
@router.post("/default/suggestions", response_model=List[PromptSuggestion])
2024-01-23 05:07:40 +00:00
async def set_global_default_suggestions(
request: Request,
form_data: SetDefaultSuggestionsForm,
user=Depends(get_admin_user),
2024-01-23 05:07:40 +00:00
):
data = form_data.model_dump()
config_set(request.app.state.DEFAULT_PROMPT_SUGGESTIONS, data["suggestions"])
return config_get(request.app.state.DEFAULT_PROMPT_SUGGESTIONS)