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

Parameters:

  • erroneous_source (String)

    Source code of a broken method

  • exception_backtrace (String)

    First line of a broken method’s backtrace

Returns:

  • (String)

    The suggested fix



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 = <<~PROMPT
    This is a method's source and the error. Fix the method:

    ## Source:
    #{erroneous_source}

    ## Error:
    #{exception_backtrace}

    ## Updated source:
  PROMPT

  if CHAT_MODELS.include?(defaults.model)
    request_chat_completion(prompt)
  elsif COMPLETION_MODELS.include?(defaults.model)
    request_completion(prompt)
  else
    raise "Unknown model '#{defaults.model}'. If this is a mistake, open a PR in github.com/wilsonsilva/senior"
  end
end