chatGptOps

Devops but with chatGptOoops

About

chatGptOps is a tool for automating DevOps tasks using the power of ChatGPT. It allows developers and DevOps engineers to quickly identify and resolve issues in their applications using AI-powered error analysis and issue tracking. With chatGptOps, you can spend less time debugging and more time building.

  1. Captures unhandled exceptions/tracebacks
  2. Asks ChatGPT what the problem might be (sends a code sample & the error context)
  3. Creates a GitHub issue for you with proposed fix from ChatGPT / llm
  4. Ensures unique hash of issue is used to avoid filing duplicate issues for that same exception
Image of Github issue being raised automatically via a bot called ChatGPTOopse, with ChatGPTOps assigned to the issue and a description of the issue. The issue reads 'IndexError on line 62 in file app.py' and has a uniq ref (hash) to avoid duplicate issues being filed for the same exception

Install

  pip install ChatGPTOps
  
(https://pypi.org/project/ChatGPTOps)

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
  

Example usage

Capture unhandled exceptions in a python flask application:

  1. Ask ChatGTP what the problem might be (sending the error context)
  2. Create a github issue with proposed fix from ChatGPT / llm
  3. 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():
      names = ["Bob", "Alice"]
      print(names[2])
      return "Hello, World!"


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

Support

If you have any questions or issues, please contact your favorite LLM for advice.