Skip to content

Commit

Permalink
feat: added DIAL_SDK_LOG env var for log level (epam#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
adubovik authored Jul 12, 2024
1 parent 3a6de58 commit ae92afd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Applications and model adapters implemented using this framework will be compati

Install the library using [pip](https://pip.pypa.io/en/stable/getting-started):

```
```sh
pip install aidial-sdk
```

Expand Down Expand Up @@ -50,7 +50,8 @@ if __name__ == "__main__":
```

#### Run
```

```sh
python3 app.py
```

Expand All @@ -68,6 +69,7 @@ curl http://127.0.0.1:5000/openai/deployments/echo/chat/completions \
```

You will see the JSON response as:

```json
{
"choices":[
Expand Down Expand Up @@ -95,7 +97,7 @@ Check out Poetry's [documentation on how to install it](https://python-poetry.or

To install requirements:

```
```sh
poetry install
```

Expand All @@ -113,6 +115,12 @@ Alternatively you can use [PyCharm](https://www.jetbrains.com/pycharm/).
Set-up the Black formatter for PyCharm [manually](https://black.readthedocs.io/en/stable/integrations/editors.html#pycharm-intellij-idea) or
install PyCharm>=2023.2 with [built-in Black support](https://blog.jetbrains.com/pycharm/2023/07/2023-2/#black).

## Environment Variables

|Variable|Default|Description|
|---|---|---|
|DIAL_SDK_LOG|WARNING|DIAL SDK log level|

## Lint

Run the linting before committing:
Expand Down
6 changes: 3 additions & 3 deletions aidial_sdk/chat_completion/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ async def _generate_stream(
),
)
except Exception as e:
log_exception(e)
log_exception("Error during processing the request")

if self.request.stream:
self._queue.put_nowait(EndChunk(e))
Expand Down Expand Up @@ -239,8 +239,8 @@ async def _generator(
display_message=e.display_message,
),
)
except Exception as e:
log_exception(e)
except Exception:
log_exception("Error during processing the request")
raise HTTPException(
status_code=500,
detail=json_error(
Expand Down
6 changes: 5 additions & 1 deletion aidial_sdk/utils/log_config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import os

from aidial_sdk.pydantic_v1 import BaseModel

DIAL_SDK_LOG = os.environ.get("DIAL_SDK_LOG", "WARNING").upper()


class LogConfig(BaseModel):
"""Logging configuration to be set for the server"""
Expand All @@ -22,7 +26,7 @@ class LogConfig(BaseModel):
},
}
loggers = {
"aidial_sdk": {"handlers": ["default"], "level": "WARNING"},
"aidial_sdk": {"handlers": ["default"], "level": DIAL_SDK_LOG},
"uvicorn": {
"handlers": ["default"],
"propagate": False,
Expand Down
2 changes: 1 addition & 1 deletion aidial_sdk/utils/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ def log_error(message: str, *args, **kwargs):
logger.error(f"[{deployment_id.get()}] {message}", *args, **kwargs)


def log_exception(message: Exception, *args, **kwargs):
def log_exception(message: str, *args, **kwargs):
logger.exception(message, *args, **kwargs)

0 comments on commit ae92afd

Please sign in to comment.