Sha256: 3c48ffd2d905b4ba191eb51dda0a67753cd90b301aa3cab09bc65db851fb95d8

Contents?: true

Size: 946 Bytes

Versions: 6

Compression:

Stored size: 946 Bytes

Contents

# frozen_string_literal: true

module Luo
  module ErrorHandle
    def raise(err, *args)
      Luo::ErrorHandle.gpt_error_analyze(err)
      super
    end

    def fail(*args)
      raise(*args)
    end

    def gpt_error_analyze(error)
      if error
        error_message = error.message
        backtrace = error.backtrace

        context = {
          message: error_message,
          backtrace: backtrace
        }
        Helpers.display_md(" **你的代码出错了!正在使用 ChatGPT 分析错误原因,请稍后 ... **")

        messages = Messages.create
                           .system(text: "你是一个ruby专家,根据用户的输入,你需要分析出错误的原因,然后给出解决方案。")
                           .user(prompt: Prompts.luo_error_analyze, context: context)
        response = OpenAI.new.chat(messages)

        Helpers.display_md(response)
        puts "\n"
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
luo-0.2.7 lib/luo/error_handle.rb
luo-0.2.6 lib/luo/error_handle.rb
luo-0.2.5 lib/luo/error_handle.rb
luo-0.2.4 lib/luo/error_handle.rb
luo-0.2.3 lib/luo/error_handle.rb
luo-0.2.2 lib/luo/error_handle.rb