Skip to main content

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

  1. Install code-sage with a package manager, eg.:
    • pip install code-sage
    • poetry add code-sage
    • pipenv install pipenv
  2. Add the following to either django settings or environment variables:
OPEN_AI_API_KEY = "your-api-key"
CODE_SAGE_ENABLED = True
  1. 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. datadog_example.png

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

code_sage-0.1.2.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

code_sage-0.1.2-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file code_sage-0.1.2.tar.gz.

File metadata

  • Download URL: code_sage-0.1.2.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

Hashes for code_sage-0.1.2.tar.gz
Algorithm Hash digest
SHA256 ef5411c7b18c4de65dd4e1ba0ef7111f2968acdb9f2598d5487936b8ad18f093
MD5 e5ebfd74dfe956d81e13d024f943bcdb
BLAKE2b-256 52351705cbdbab1f007dba9a5294972ff4d9c051bcdf38602c3b8edf5cef819b

See more details on using hashes here.

File details

Details for the file code_sage-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: code_sage-0.1.2-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

Hashes for code_sage-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b69bbe698c40df9b37bae1f6d53f675fd364c0c22313919fd75bc022db51269d
MD5 2a730576d0f9c59a4e3eb3b0d5802704
BLAKE2b-256 19bd7626ca2608c59699ea9ff4e22c7f96b87f7f975b76e81e2a25be0b66dd06

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page