aaxaxax commited on
Commit
62782db
·
1 Parent(s): 5904245

Add traceback

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -1,11 +1,13 @@
1
  import os
2
  import httpx
 
3
  from fastapi import FastAPI, Request
4
  from fastapi.responses import JSONResponse, StreamingResponse, Response
5
 
6
  app = FastAPI()
7
 
8
  BASE_URL = os.getenv("BASE_URL", "https://ollama.com")
 
9
 
10
  @app.get("/")
11
  def root():
@@ -13,7 +15,7 @@ def root():
13
 
14
  @app.api_route("/v1/{path:path}", methods=["GET", "POST"])
15
  async def proxy(req: Request, path: str):
16
- print(f"[PROXY] request to {path}")
17
 
18
  target_url = f"{BASE_URL}/v1/{path}"
19
  body = await req.body()
@@ -23,9 +25,10 @@ async def proxy(req: Request, path: str):
23
  headers.pop("content-length", None)
24
 
25
  # Hardcoded key
26
- headers["Authorization"] = "Bearer 37e81a6be4104fbfbfbe2ecf557a2c10.GoIbzpHebdM9ZcHarQ9A12Cp"
27
 
28
- print(f"[PROXY] calling {target_url}")
 
29
 
30
  try:
31
  async with httpx.AsyncClient(timeout=60) as client:
@@ -36,7 +39,7 @@ async def proxy(req: Request, path: str):
36
  content=body,
37
  params=req.query_params
38
  )
39
- print(f"[PROXY] got {resp.status_code}")
40
 
41
  return Response(
42
  content=resp.content,
@@ -45,4 +48,5 @@ async def proxy(req: Request, path: str):
45
  )
46
  except Exception as e:
47
  print(f"[ERROR] {e}")
 
48
  return JSONResponse({"error": str(e)}, status_code=500)
 
1
  import os
2
  import httpx
3
+ import traceback
4
  from fastapi import FastAPI, Request
5
  from fastapi.responses import JSONResponse, StreamingResponse, Response
6
 
7
  app = FastAPI()
8
 
9
  BASE_URL = os.getenv("BASE_URL", "https://ollama.com")
10
+ TEST_KEY = "37e81a6be4104fbfbfbe2ecf557a2c10.GoIbzpHebdM9ZcHarQ9A12Cp"
11
 
12
  @app.get("/")
13
  def root():
 
15
 
16
  @app.api_route("/v1/{path:path}", methods=["GET", "POST"])
17
  async def proxy(req: Request, path: str):
18
+ print(f"[PROXY] path={path}")
19
 
20
  target_url = f"{BASE_URL}/v1/{path}"
21
  body = await req.body()
 
25
  headers.pop("content-length", None)
26
 
27
  # Hardcoded key
28
+ headers["Authorization"] = f"Bearer {TEST_KEY}"
29
 
30
+ print(f"[PROXY] target={target_url}")
31
+ print(f"[PROXY] key={TEST_KEY[:10]}...")
32
 
33
  try:
34
  async with httpx.AsyncClient(timeout=60) as client:
 
39
  content=body,
40
  params=req.query_params
41
  )
42
+ print(f"[PROXY] status={resp.status_code}")
43
 
44
  return Response(
45
  content=resp.content,
 
48
  )
49
  except Exception as e:
50
  print(f"[ERROR] {e}")
51
+ traceback.print_exc()
52
  return JSONResponse({"error": str(e)}, status_code=500)