xTHExBEASTx commited on
Commit
784bc56
·
verified ·
1 Parent(s): b24c137

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -11
app.py CHANGED
@@ -17,22 +17,17 @@ subprocess.Popen(["ollama", "serve"])
17
 
18
  @app.api_route("/{path:path}", methods=["GET", "POST", "PUT", "DELETE"])
19
  async def proxy_to_ollama(request: Request, path: str):
20
- # Reverse Proxy: Forwards Claude CLI requests to the internal Ollama engine
21
- url = httpx.URL(f"http://127.0.0.1:11434/{path}", query=request.url.query.encode("utf-8"))
 
 
22
 
23
  async with httpx.AsyncClient(timeout=None) as client:
24
  req = client.build_request(
25
- request.method,
26
- url,
27
- headers=request.headers.raw,
28
- content=request.stream(),
29
  )
30
  resp = await client.send(req, stream=True)
31
- return StreamingResponse(
32
- resp.aiter_raw(),
33
- status_code=resp.status_code,
34
- headers=dict(resp.headers)
35
- )
36
 
37
  @app.get("/")
38
  def health_check():
 
17
 
18
  @app.api_route("/{path:path}", methods=["GET", "POST", "PUT", "DELETE"])
19
  async def proxy_to_ollama(request: Request, path: str):
20
+ # This captures the '/v1/messages' and sends it to Ollama
21
+ # Ensure no extra '/v1' is added by the CLI
22
+ target_path = path if not path.startswith("v1/v1") else path.replace("v1/v1", "v1")
23
+ url = httpx.URL(f"http://127.0.0.1:11434/{target_path}", query=request.url.query.encode("utf-8"))
24
 
25
  async with httpx.AsyncClient(timeout=None) as client:
26
  req = client.build_request(
27
+ request.method, url, headers=request.headers.raw, content=request.stream()
 
 
 
28
  )
29
  resp = await client.send(req, stream=True)
30
+ return StreamingResponse(resp.aiter_raw(), status_code=resp.status_code, headers=dict(resp.headers))
 
 
 
 
31
 
32
  @app.get("/")
33
  def health_check():