Skip to content

Conversation

@ilnurgit
Copy link
Owner

No description provided.

merged = {**self.default_headers, **(headers or {})}
try:
resp = self._client.request(method, url, headers=merged, json=json)
except httpx.HTTPError as e:
Copy link

@LilChichaaa LilChichaaa Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лучше исключения перехватывать через fastapi exception handler снаружи приложения

url,
(resp.text or "")[:300],
)
resp.raise_for_status()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

можно не проверять код и просто вызывать raise_for_status(), т.к. при успешном коде просто ничего не произойдет

class JsonBinClient(BaseHTTPClient):
def __init__(self):
self._api_key = os.environ.get("JSONBIN_API_KEY")
self._bin_id = os.environ.get("JSONBIN_BIN_ID")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

переменные окружения тянутся в отдельном файле config.py и импортируются сюда. Лучше импортировать их как класс pydantic.base_settings (https://docs.pydantic.dev/latest/concepts/pydantic_settings/), а сами переменные тянуть не через OS, а через starlette (https://www.starlette.dev/config/)

@@ -0,0 +1,64 @@
import logging

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

можно loguru использовать, щас его юзают часто

explanation = await llm.explain_task(task.title)
task = repo.update(task.id, {"description": explanation})
logger.info("Task %s enriched by LLM", task.id)
except Exception:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тут тоже try except не нужен. просто прокидывай исключение наверз и лови exception handler fastapi

return TaskRepository()


repo = get_repo()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

почитай про Depends в Fastapi, по хорошему такие вещи через него лучше делать

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants