fix: async version check

This commit is contained in:
Timothy J. Baek 2024-04-09 23:03:05 -07:00
parent 2f6e683163
commit cbb21a148d

View file

@ -5,6 +5,7 @@ import time
import os import os
import sys import sys
import logging import logging
import aiohttp
import requests import requests
from fastapi import FastAPI, Request, Depends, status from fastapi import FastAPI, Request, Depends, status
@ -18,6 +19,7 @@ from starlette.middleware.base import BaseHTTPMiddleware
from apps.ollama.main import app as ollama_app from apps.ollama.main import app as ollama_app
from apps.openai.main import app as openai_app from apps.openai.main import app as openai_app
from apps.litellm.main import app as litellm_app, startup as litellm_app_startup from apps.litellm.main import app as litellm_app, startup as litellm_app_startup
from apps.audio.main import app as audio_app from apps.audio.main import app as audio_app
from apps.images.main import app as images_app from apps.images.main import app as images_app
@ -271,14 +273,16 @@ async def get_app_changelog():
@app.get("/api/version/updates") @app.get("/api/version/updates")
async def get_app_latest_release_version(): async def get_app_latest_release_version():
try: try:
response = requests.get( async with aiohttp.ClientSession() as session:
f"https://api.github.com/repos/open-webui/open-webui/releases/latest" async with session.get(
) "https://api.github.com/repos/open-webui/open-webui/releases/latest"
) as response:
response.raise_for_status() response.raise_for_status()
latest_version = response.json()["tag_name"] data = await response.json()
latest_version = data["tag_name"]
return {"current": VERSION, "latest": latest_version[1:]} return {"current": VERSION, "latest": latest_version[1:]}
except Exception as e: except aiohttp.ClientError as e:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_503_SERVICE_UNAVAILABLE, status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
detail=ERROR_MESSAGES.RATE_LIMIT_EXCEEDED, detail=ERROR_MESSAGES.RATE_LIMIT_EXCEEDED,