ParthSadaria commited on
Commit
a68045e
·
verified ·
1 Parent(s): 7e00dd6

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +4 -9
main.py CHANGED
@@ -4,7 +4,6 @@ from fastapi import FastAPI, HTTPException, Request
4
  from fastapi.responses import StreamingResponse, HTMLResponse
5
  from pydantic import BaseModel
6
  import httpx
7
- from functools import lru_cache
8
 
9
  # Load environment variables from .env file
10
  load_dotenv()
@@ -51,9 +50,9 @@ async def root():
51
  """
52
  return HTMLResponse(content=html_content)
53
 
54
- # Cache function with lru_cache
55
- @lru_cache(maxsize=1)
56
- async def get_cached_models():
57
  async with httpx.AsyncClient() as client:
58
  try:
59
  response = await client.get(f"{secret_api_endpoint}/v1/models", timeout=3)
@@ -62,10 +61,6 @@ async def get_cached_models():
62
  except httpx.RequestError as e:
63
  raise HTTPException(status_code=500, detail=f"Request failed: {e}")
64
 
65
- @app.get("/v1/models")
66
- async def get_models():
67
- return await get_cached_models()
68
-
69
  @app.post("/v1/chat/completions")
70
  async def get_completion(payload: Payload, request: Request):
71
  api_key = request.headers.get("Authorization")
@@ -103,4 +98,4 @@ async def startup_event():
103
  # Run the server with Uvicorn using the 'main' module
104
  if __name__ == "__main__":
105
  import uvicorn
106
- uvicorn.run(app, host="0.0.0.0", port=8000)
 
4
  from fastapi.responses import StreamingResponse, HTMLResponse
5
  from pydantic import BaseModel
6
  import httpx
 
7
 
8
  # Load environment variables from .env file
9
  load_dotenv()
 
50
  """
51
  return HTMLResponse(content=html_content)
52
 
53
+ # Remove cache from get_models
54
+ @app.get("/v1/models")
55
+ async def get_models():
56
  async with httpx.AsyncClient() as client:
57
  try:
58
  response = await client.get(f"{secret_api_endpoint}/v1/models", timeout=3)
 
61
  except httpx.RequestError as e:
62
  raise HTTPException(status_code=500, detail=f"Request failed: {e}")
63
 
 
 
 
 
64
  @app.post("/v1/chat/completions")
65
  async def get_completion(payload: Payload, request: Request):
66
  api_key = request.headers.get("Authorization")
 
98
  # Run the server with Uvicorn using the 'main' module
99
  if __name__ == "__main__":
100
  import uvicorn
101
+ uvicorn.run(app, host="0.0.0.0", port=8000)