Class: Verica::OpenAIWrapper::CompletionsProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/verica/openai_wrapper.rb

Instance Method Summary collapse

Constructor Details

#initialize(completions) ⇒ CompletionsProxy

Returns a new instance of CompletionsProxy.



45
# File 'lib/verica/openai_wrapper.rb', line 45

def initialize(completions) = @completions = completions

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object



64
65
66
# File 'lib/verica/openai_wrapper.rb', line 64

def method_missing(name, ...)
  @completions.public_send(name, ...)
end

Instance Method Details

#create(**params) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/verica/openai_wrapper.rb', line 47

def create(**params)
  span = safely do
    tracer = OpenTelemetry.tracer_provider.tracer('verica-observability', Verica::VERSION)
    tracer.start_span("chat #{params[:model]}", kind: :client)
  end
  begin
    response = @completions.create(**params)
    safely { annotate(span, params, response) } if span
    response
  rescue StandardError => e
    safely { span&.status = OpenTelemetry::Trace::Status.error(e.message) }
    raise
  ensure
    safely { span&.finish }
  end
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/verica/openai_wrapper.rb', line 68

def respond_to_missing?(name, include_private = false)
  @completions.respond_to?(name, include_private) || super
end