asp-chef-cli 0.5.1__tar.gz → 0.5.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,13 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: asp-chef-cli
3
- Version: 0.5.1
3
+ Version: 0.5.3
4
4
  Summary: A simple CLI to run ASP Chef recipes
5
5
  Author: Mario Alviano
6
6
  Author-email: mario.alviano@gmail.com
7
7
  Requires-Python: >=3.13,<4.0
8
8
  Classifier: Programming Language :: Python :: 3
9
9
  Classifier: Programming Language :: Python :: 3.13
10
- Requires-Dist: dumbo-asp (>=0.4.0,<0.5.0)
10
+ Requires-Dist: dumbo-asp (>=0.4.2,<0.5.0)
11
11
  Requires-Dist: fastapi (>=0.129.0,<0.130.0)
12
12
  Requires-Dist: httpx (>=0.28.1,<0.29.0)
13
13
  Requires-Dist: opa-python (>=0.0.9,<0.0.10)
@@ -1,15 +1,17 @@
1
- import httpx
2
1
  import json as json_module
3
2
  import os
4
3
  import shutil
5
4
  import subprocess
6
5
  from collections import defaultdict
6
+ from typing import Optional, Dict, Final
7
+
8
+ import httpx
7
9
  from dumbo_asp.primitives.models import Model
8
10
  from dumbo_asp.primitives.rules import SymbolicRule
9
11
  from dumbo_asp.primitives.templates import Template
10
12
  from dumbo_asp.queries import explanation_graph, pack_xasp_navigator_url
11
- from fastapi import APIRouter, Request, Response
12
- from typing import Optional, Dict, Final
13
+ from fastapi import APIRouter, Response
14
+ from fastapi.responses import StreamingResponse
13
15
 
14
16
  from ..dependencies import *
15
17
 
@@ -274,33 +276,31 @@ OLLAMA_URL = os.getenv("ASP_CHEF_CLI__OLLAMA_URL", "http://127.0.0.1:11434")
274
276
 
275
277
  @router.api_route("/ollama/{path:path}", methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"])
276
278
  async def ollama_proxy(path: str, request: Request):
277
-
278
- async with httpx.AsyncClient() as client:
279
- # 1. Prepare the forwarded request
280
- url = f"{OLLAMA_URL}/{path}"
281
-
282
- # 2. Get body and headers (excluding Host)
283
- body = await request.body()
284
- headers = dict(request.headers)
285
- headers.pop("host", None)
286
-
287
- # 3. Forward the request to Ollama
288
- try:
289
- rp_resp = await client.request(
290
- method=request.method,
291
- url=url,
292
- params=request.query_params,
293
- headers=headers,
294
- content=body,
295
- timeout=None # Important for long LLM generations
296
- )
297
- except httpx.ConnectError:
298
- return Response(content="Ollama not running", status_code=503)
299
-
300
- # 4. Return the response with proper headers
301
- # Your FastAPI CORS middleware will handle the "Access-Control" headers automatically
302
- return Response(
303
- content=rp_resp.content,
304
- status_code=rp_resp.status_code,
305
- headers=dict(rp_resp.headers)
306
- )
279
+ url = f"{OLLAMA_URL}/{path.lstrip('/')}"
280
+ method = request.method
281
+ params = request.query_params
282
+
283
+ body = await request.body()
284
+ headers = dict(request.headers)
285
+ headers.pop("host", None)
286
+ headers.pop("content-length", None) # Let httpx recalculate it
287
+
288
+ async def generate_stream():
289
+ async with httpx.AsyncClient(timeout=None) as client:
290
+ async with client.stream(
291
+ method=method,
292
+ url=url,
293
+ params=params,
294
+ headers=headers,
295
+ content=body,
296
+ ) as rp_resp:
297
+ async for chunk in rp_resp.aiter_bytes():
298
+ yield chunk
299
+
300
+ try:
301
+ return StreamingResponse(
302
+ generate_stream(),
303
+ media_type="application/octet-stream"
304
+ )
305
+ except httpx.ConnectError:
306
+ return Response(content="Ollama not running", status_code=503)
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "asp-chef-cli"
3
- version = "0.5.1"
3
+ version = "0.5.3"
4
4
  description = "A simple CLI to run ASP Chef recipes"
5
5
  authors = ["Mario Alviano <mario.alviano@gmail.com>"]
6
6
  readme = "README.md"
@@ -8,7 +8,7 @@ readme = "README.md"
8
8
  [tool.poetry.dependencies]
9
9
  python = ">=3.13,<4.0"
10
10
  pytest-playwright = "^0.7.2"
11
- dumbo-asp = "^0.4.0"
11
+ dumbo-asp = "^0.4.2"
12
12
  uvicorn = "^0.40.0"
13
13
  fastapi = "^0.129.0"
14
14
  opa-python = "^0.0.9"
File without changes
File without changes