Skip to content

Commit 2f484d6

Browse files
committed
lint and format
1 parent e215876 commit 2f484d6

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ py-upgrade: ## Upgrade project py files with pyupgrade library for python versio
4343

4444
.PHONY: lint
4545
lint: ## Lint project code.
46-
poetry run ruff check --fix .
46+
uv run ruff check --fix .
4747

4848
.PHONY: slim-build
4949
slim-build: ## with power of docker-slim build smaller and safer images

app/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
from fastapi import Depends, FastAPI
88

99
from app.api.health import router as health_router
10+
from app.api.ml import router as ml_router
1011
from app.api.nonsense import router as nonsense_router
1112
from app.api.shakespeare import router as shakespeare_router
1213
from app.api.stuff import router as stuff_router
1314
from app.api.user import router as user_router
14-
from app.api.ml import router as ml_router
1515
from app.config import settings as global_settings
1616
from app.database import engine
1717
from app.redis import get_redis

app/services/llm.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1+
from collections.abc import AsyncGenerator
2+
13
import httpx
24
import orjson
3-
from typing import AsyncGenerator, Optional
45

56

67
class StreamLLMService:
78
def __init__(self, base_url: str = "http://localhost:11434/v1"):
89
self.base_url = base_url
910
self.model = "llama3.2"
1011

11-
async def stream_chat(self, prompt: str) -> AsyncGenerator[bytes, None]:
12+
async def stream_chat(self, prompt: str) -> AsyncGenerator[bytes]:
1213
"""Stream chat completion responses from LLM."""
1314
# Send the user a message first
1415
user_msg = {
@@ -47,5 +48,5 @@ async def stream_chat(self, prompt: str) -> AsyncGenerator[bytes, None]:
4748

4849

4950
# FastAPI dependency
50-
def get_llm_service(base_url: Optional[str] = None) -> StreamLLMService:
51+
def get_llm_service(base_url: str | None = None) -> StreamLLMService:
5152
return StreamLLMService(base_url=base_url or "http://localhost:11434/v1")

tests/chat.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import httpx
33
import orjson
44

5+
56
async def chat_with_endpoint():
67
async with httpx.AsyncClient() as client:
78
while True:
@@ -14,9 +15,9 @@ async def chat_with_endpoint():
1415
print("\nModel: ", end="", flush=True)
1516
async with client.stream(
1617
"POST",
17-
"http://localhost:8000/chat/",
18+
"http://0.0.0.0:8080/v1/ml/chat/",
1819
data={"prompt": prompt},
19-
timeout=60
20+
timeout=60,
2021
) as response:
2122
async for chunk in response.aiter_lines():
2223
if chunk:
@@ -26,5 +27,6 @@ async def chat_with_endpoint():
2627
except Exception as e:
2728
print(f"\nError parsing chunk: {e}")
2829

30+
2931
if __name__ == "__main__":
3032
anyio.run(chat_with_endpoint)

0 commit comments

Comments
 (0)