Class: Girb::Providers::Base::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/girb/providers/base.rb

Overview

Response object returned by chat method

Constant Summary collapse

ERROR_KINDS =

Normalized error categories. Providers SHOULD set error_kind explicitly; when omitted, a conservative fallback classification is applied.

:malformed_tool_call - the model emitted an invalid/unparseable tool call
:rate_limit          - provider rate limited the request
:transient           - temporary provider/network failure, safe to retry
:timeout             - request timed out
:fatal               - non-recoverable (auth, bad request, unknown)
%i[malformed_tool_call rate_limit transient timeout fatal].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text: nil, function_calls: nil, error: nil, raw_response: nil, error_kind: nil) ⇒ Response

Returns a new instance of Response.



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/girb/providers/base.rb', line 46

def initialize(text: nil, function_calls: nil, error: nil, raw_response: nil, error_kind: nil)
  if error_kind && !ERROR_KINDS.include?(error_kind)
    raise ArgumentError, "unknown error_kind: #{error_kind.inspect} (expected one of #{ERROR_KINDS.inspect})"
  end

  @text = text
  @function_calls = function_calls || []
  @error = error
  @raw_response = raw_response
  @error_kind = error_kind
  @error_kind ||= classify_error(error) if error
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



44
45
46
# File 'lib/girb/providers/base.rb', line 44

def error
  @error
end

#error_kindObject (readonly)

Returns the value of attribute error_kind.



44
45
46
# File 'lib/girb/providers/base.rb', line 44

def error_kind
  @error_kind
end

#function_callsObject (readonly)

Returns the value of attribute function_calls.



44
45
46
# File 'lib/girb/providers/base.rb', line 44

def function_calls
  @function_calls
end

#raw_responseObject (readonly)

Returns the value of attribute raw_response.



44
45
46
# File 'lib/girb/providers/base.rb', line 44

def raw_response
  @raw_response
end

#textObject (readonly)

Returns the value of attribute text.



44
45
46
# File 'lib/girb/providers/base.rb', line 44

def text
  @text
end

Instance Method Details

#function_call?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/girb/providers/base.rb', line 59

def function_call?
  @function_calls.any?
end

#self_correctable?Boolean

The model can fix this itself by re-emitting a valid tool call. Drives provider-agnostic self-correction in the tool loop.

Returns:

  • (Boolean)


65
66
67
# File 'lib/girb/providers/base.rb', line 65

def self_correctable?
  @error_kind == :malformed_tool_call
end

#transport_retryable?Boolean

The request can be retried at the transport layer without involving the model (no conversation-history change). Not wired into the loop yet; exposed for providers and a future transport-retry milestone.

Returns:

  • (Boolean)


72
73
74
# File 'lib/girb/providers/base.rb', line 72

def transport_retryable?
  %i[rate_limit transient timeout].include?(@error_kind)
end