-
Notifications
You must be signed in to change notification settings - Fork 0
Домашка по ООП (simple_backend) #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| merged = {**self.default_headers, **(headers or {})} | ||
| try: | ||
| resp = self._client.request(method, url, headers=merged, json=json) | ||
| except httpx.HTTPError as e: |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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 | |||
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
почитай про Depends в Fastapi, по хорошему такие вещи через него лучше делать
No description provided.