main.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. from fastapi import FastAPI, Depends
  2. from fastapi.routing import APIRoute
  3. from fastapi.middleware.cors import CORSMiddleware
  4. from apps.web.routers import (
  5. auths,
  6. users,
  7. chats,
  8. documents,
  9. modelfiles,
  10. prompts,
  11. configs,
  12. utils,
  13. )
  14. from config import (
  15. WEBUI_VERSION,
  16. WEBUI_AUTH,
  17. DEFAULT_MODELS,
  18. DEFAULT_PROMPT_SUGGESTIONS,
  19. DEFAULT_USER_ROLE,
  20. ENABLE_SIGNUP,
  21. USER_PERMISSIONS,
  22. WEBHOOK_URL,
  23. )
  24. app = FastAPI()
  25. origins = ["*"]
  26. app.state.ENABLE_SIGNUP = ENABLE_SIGNUP
  27. app.state.JWT_EXPIRES_IN = "-1"
  28. app.state.DEFAULT_MODELS = DEFAULT_MODELS
  29. app.state.DEFAULT_PROMPT_SUGGESTIONS = DEFAULT_PROMPT_SUGGESTIONS
  30. app.state.DEFAULT_USER_ROLE = DEFAULT_USER_ROLE
  31. app.state.USER_PERMISSIONS = USER_PERMISSIONS
  32. app.state.WEBHOOK_URL = WEBHOOK_URL
  33. app.add_middleware(
  34. CORSMiddleware,
  35. allow_origins=origins,
  36. allow_credentials=True,
  37. allow_methods=["*"],
  38. allow_headers=["*"],
  39. )
  40. app.include_router(auths.router, prefix="/auths", tags=["auths"])
  41. app.include_router(users.router, prefix="/users", tags=["users"])
  42. app.include_router(chats.router, prefix="/chats", tags=["chats"])
  43. app.include_router(documents.router, prefix="/documents", tags=["documents"])
  44. app.include_router(modelfiles.router, prefix="/modelfiles", tags=["modelfiles"])
  45. app.include_router(prompts.router, prefix="/prompts", tags=["prompts"])
  46. app.include_router(configs.router, prefix="/configs", tags=["configs"])
  47. app.include_router(utils.router, prefix="/utils", tags=["utils"])
  48. @app.get("/")
  49. async def get_status():
  50. return {
  51. "status": True,
  52. "auth": WEBUI_AUTH,
  53. "default_models": app.state.DEFAULT_MODELS,
  54. "default_prompt_suggestions": app.state.DEFAULT_PROMPT_SUGGESTIONS,
  55. }