Class: Senior::Brains::OpenAI Private

Inherits:
Object
  • Object
show all
Defined in:
lib/senior/brains/open_ai.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Interface to OpenAI's API

Constant Summary collapse

CHAT_MODELS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

%w[gpt-4 gpt-4-0314 gpt-4-32k gpt-4-32k-0314 gpt-3.5-turbo gpt-3.5-turbo-0301].freeze
COMPLETION_MODELS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

%w[text-davinci-003 text-davinci-002 text-curie-001 text-babbage-001 text-ada-001
davinci curie babbage ada].freeze
CHAT_SYSTEM_PROMPT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"You're a Ruby dev. Only reply with plain code, no explanations."

Instance Method Summary collapse

Instance Method Details

#suggest_fix(erroneous_source:, exception_backtrace:) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Suggests a fix for a broken method



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/senior/brains/open_ai.rb', line 27

def suggest_fix(erroneous_source:, exception_backtrace:)
  prompt = "    This is a method's source and the error. Fix the method:\n\n    ## Source:\n    \#{erroneous_source}\n\n    ## Error:\n    \#{exception_backtrace}\n\n    ## Updated source:\n  PROMPT\n\n  if CHAT_MODELS.include?(defaults.model)\n    request_chat_completion(prompt)\n  elsif COMPLETION_MODELS.include?(defaults.model)\n    request_completion(prompt)\n  else\n    raise \"Unknown model '\#{defaults.model}'. If this is a mistake, open a PR in github.com/wilsonsilva/senior\"\n  end\nend\n"