Module: Luo::ErrorHandle

Defined in:
lib/luo/error_handle.rb

Instance Method Summary collapse

Instance Method Details

#fail(*args) ⇒ Object



10
11
12
# File 'lib/luo/error_handle.rb', line 10

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

#gpt_error_analyze(error) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/luo/error_handle.rb', line 14

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

#raise(err, *args) ⇒ Object



5
6
7
8
# File 'lib/luo/error_handle.rb', line 5

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