No project description provided
Project description
Code Sage
A django middleware package that provides suggestions for unhandled errors/exceptions by using OpenAI.
Currently, the suggestions are added to the python loggers extra fields.
Features
- Provide suggestions to resolve unhandled errors using OpenAI
- Locally cached code sage suggestions
- Easily enable or disable code sage per environment
- Customize code sage's suggestion response word length
Requirements
An API key from OpenAPI, which can be found here.
Quickstart
- Install
code-sage
with a package manager, eg.:pip install code-sage
poetry add code-sage
pipenv install code-sage
- Add the following to either django settings or environment variables:
OPEN_AI_API_KEY = "your-api-key"
CODE_SAGE_ENABLED = True
- Update the django middleware to include
code-sage
MIDDLEWARE = [
# ...
"code-sage.middleware.ErrorHandlerMiddleware",
# ...
]
Example
This was tested with the code
for x in 100:
print(x)
which gave the suggestion
To fix this error, you need to replace the line "for x in 100:" with "for x in range(100):". This will create an iterable object from the integer 100, allowing the loop to execute correctly.
Testing showed that it can also reference variables names when suggesting a solution. This is thanks to the
traceback.format_exc()
that is provided to OpenAI when requesting a solution.
This also plays well with things like datadog, thanks to using the extra
field in pythons logging.
Configuration
A few things can be done to configure code sage. These can be set in either environment variables or through django settings files.
Setting | Type | Default |
---|---|---|
OPEN_AI_API_KEY | String | (None) |
CODE_SAGE_ENABLED | Boolean | False |
CODE_SAGE_SUGGESTION_WORD_LIMIT | Integer | 120 |
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file code_sage-0.1.3.tar.gz
.
File metadata
- Download URL: code_sage-0.1.3.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.0 CPython/3.10.9 Linux/5.4.0-135-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8f2f2731171adf2dae6c63d692e7b5209614a425083055bae0dd4a3965a8e19 |
|
MD5 | 8275fa6eb15e2b640e5c4f284c0c07ee |
|
BLAKE2b-256 | 6f1b07b268fdd757a11b476d7cd37edfe8efb4b4b819a5edda1188a649faea8c |
Provenance
File details
Details for the file code_sage-0.1.3-py3-none-any.whl
.
File metadata
- Download URL: code_sage-0.1.3-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.0 CPython/3.10.9 Linux/5.4.0-135-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52e552f9d6ffa2a95b63d019e0ba91719b2ee27caf89917db285cdfaff78fc16 |
|
MD5 | d1a7b76fe81f1a8b6165701188ab2406 |
|
BLAKE2b-256 | 048c89f46425d45b8e3834b49bbf3af15d3173849d8c608ac30f2d2b8f7663c9 |