Skip to main content

Ask chatGPT llm to investigate your unhandled exceptions & file github issues with proposed fixes without filing duplicate issues

Project description

chatGptOps

Devops but with chatGptOoops

Install

Setup

In your application, set the following configuration values:

  • OPENAI_API_KEY
  • GITHUB_FINE_GRAINED_ACCESS_TOKEN with access to your repo 'issues'
  • GITHUB_ORG_NAME_OR_USERNAME
  • GIT_REPO_NAME

Hint python-dotenv is an excellent package for reading key-value pairs from a .env file (or envrionment) and set them as environment variables.

Example usage

Capture unhandled exceptions in a python flask application:

  • Ask ChatGTP what the problem might be (sending the error context)
  • Create a github issue with proposed fix from ChatGPT / llm
  • Ensure unique hash of issue is used to avoid filing duplicate issues for that exception
import sys
import logging
import os
from ChatGPTHandler import ChatGPTHandler
from flask import Flask
from dotenv import load_dotenv
from unhandled_exception_logger import (
    unhandled_exception_setup,
    handle_exception,
)

load_dotenv()

PYTHON_LOG_LEVEL = os.getenv("PYTHON_LOG_LEVEL", "DEBUG")


# Register chatGPTHandler log handler
chatGPTHandler = ChatGPTHandler()
chatGPTHandler.setLevel("CRITICAL")

unhandled_exception_setup(handler=chatGPTHandler)


logger = logging.getLogger()
logger.setLevel(PYTHON_LOG_LEVEL)
logger.addHandler(chatGPTHandler)


# # Direct all uncaught exceptions to handle_exception
sys.excepthook = handle_exception


# Minimal python app example with example unhandled exception
app = Flask(__name__)
logging.getLogger("werkzeug").disabled = True
app.logger.disabled = True


@app.errorhandler(Exception)
def flask_handle_exception(e):
    handle_exception(
        sys.exc_info()[0],
        sys.exc_info()[1],
        sys.exc_info()[2],
        handler=chatGPTHandler,  # noqa: E501
    )


@app.errorhandler(500)
def error_page(e):
    return "An error occurred"


@app.route("/")
def index():
    return "index"


@app.route("/error")
def error():
    colors = ["Red", "Blue"]
    print(colors[3])
    names = ["Bob", "Alice"]
    print(names[2])
    return "<p>Hello, World!</p>"


if __name__ == "__main__":
    app.run(threaded=True)

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

ChatGPTOps-0.0.1.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

ChatGPTOps-0.0.1-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file ChatGPTOps-0.0.1.tar.gz.

File metadata

  • Download URL: ChatGPTOps-0.0.1.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for ChatGPTOps-0.0.1.tar.gz
Algorithm Hash digest
SHA256 f65081f75e717e82ee34ef72aaa40a71e1d79b3f8d838af92fae083e92a4f3bf
MD5 70bdd7426855af3ff7d38dec8a705099
BLAKE2b-256 fcf417aea0f51bb763329281246aa67e016c9b73086af6046d2a352dd486a648

See more details on using hashes here.

File details

Details for the file ChatGPTOps-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: ChatGPTOps-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for ChatGPTOps-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 baf95aedfc7ba73ae3dc2deb4d598a83480b0c31f978d774ddee7848162391ff
MD5 593f62030e306c3a815002e7079f49fd
BLAKE2b-256 6a3a25b794d8667d23589b23c21fa70dcf880e7e4dbabab0332e553a01dfe893

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