ParthSadaria commited on
Commit
3b6dbab
·
verified ·
1 Parent(s): dc7e7dc

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +23 -26
main.py CHANGED
@@ -1,36 +1,32 @@
1
  import os
2
  import re
 
 
 
 
 
 
 
 
3
  import json
4
- import time
5
  import datetime
 
6
  import asyncio
7
- import hashlib
8
- from pathlib import Path
9
- from functools import lru_cache
10
- from typing import List, Dict, Any, Optional, Union
11
-
12
- import httpx
13
- import requests
14
  import cloudscraper
15
  from concurrent.futures import ThreadPoolExecutor
16
-
17
- from dotenv import load_dotenv
18
- from fastapi import FastAPI, HTTPException, Request, Depends, Security, Query, APIRouter
19
- from fastapi.responses import (
20
- StreamingResponse,
21
- HTMLResponse,
22
- JSONResponse,
23
- FileResponse,
24
- PlainTextResponse,
25
- )
26
- from fastapi.security import APIKeyHeader
27
  from fastapi.middleware.gzip import GZipMiddleware
28
  from starlette.middleware.cors import CORSMiddleware
29
- from starlette.status import HTTP_403_FORBIDDEN
30
-
31
- import uvloop
32
  import contextlib
33
-
 
 
 
 
 
 
 
34
 
35
  asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
36
 
@@ -53,9 +49,6 @@ app.add_middleware(
53
  allow_methods=["*"],
54
  allow_headers=["*"],
55
  )
56
- @lru_cache(maxsize=256)
57
- def cached_url(url: str):
58
- return url
59
 
60
  @lru_cache(maxsize=1)
61
  def get_env_vars():
@@ -673,6 +666,10 @@ async def get_completion(payload: Payload, request: Request, authenticated: bool
673
  except Exception as e:
674
  print(f"An unexpected error occurred during non-streaming chat completion proxy: {e}")
675
  raise HTTPException(status_code=500, detail=f"An unexpected error occurred: {str(e)}")
 
 
 
 
676
  router = APIRouter()
677
 
678
  @router.get("/images/{prompt:path}")
 
1
  import os
2
  import re
3
+ from dotenv import load_dotenv
4
+ from fastapi import FastAPI, HTTPException, Request, Depends, Security, Query
5
+ from fastapi.responses import StreamingResponse, HTMLResponse, JSONResponse, FileResponse, PlainTextResponse
6
+ from fastapi.security import APIKeyHeader
7
+ from pydantic import BaseModel
8
+ import httpx
9
+ from functools import lru_cache
10
+ from pathlib import Path
11
  import json
 
12
  import datetime
13
+ import time
14
  import asyncio
15
+ from starlette.status import HTTP_403_FORBIDDEN
 
 
 
 
 
 
16
  import cloudscraper
17
  from concurrent.futures import ThreadPoolExecutor
18
+ import uvloop
 
 
 
 
 
 
 
 
 
 
19
  from fastapi.middleware.gzip import GZipMiddleware
20
  from starlette.middleware.cors import CORSMiddleware
 
 
 
21
  import contextlib
22
+ import requests
23
+ from typing import List, Dict, Any, Optional, Union # Import Optional and other typing helpers
24
+ from fastapi import APIRouter, Request, Depends, HTTPException
25
+ from fastapi.responses import StreamingResponse
26
+ import httpx
27
+ import hashlib
28
+ import asyncio
29
+ from functools import lru_cache
30
 
31
  asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
32
 
 
49
  allow_methods=["*"],
50
  allow_headers=["*"],
51
  )
 
 
 
52
 
53
  @lru_cache(maxsize=1)
54
  def get_env_vars():
 
666
  except Exception as e:
667
  print(f"An unexpected error occurred during non-streaming chat completion proxy: {e}")
668
  raise HTTPException(status_code=500, detail=f"An unexpected error occurred: {str(e)}")
669
+ @lru_cache(maxsize=256)
670
+ def cached_url(url: str):
671
+ return url
672
+
673
  router = APIRouter()
674
 
675
  @router.get("/images/{prompt:path}")