Sha256: bad99e75bad76707c75ad27e887b3f4822f7d575e5ea15b92208d9252724dcbc

Contents?: true

Size: 686 Bytes

Versions: 12

Compression:

Stored size: 686 Bytes

Contents

# frozen_string_literal: true

module GenAI
  class Base
    include GenAI::Dependency

    private

    attr_reader :client

    def handle_errors
      response = yield
      return if !response || response.empty?

      raise GenAI::ApiError, "#{api_provider_name} API error: #{response.dig('error', 'message')}" if response['error']

      response
    end

    def provider_name
      api_provider_name.gsub(/(.)([A-Z])/, '\1_\2').downcase
    end

    def api_provider_name
      self.class.name.split('::').last
    end

    def build_result(model:, raw:, parsed:)
      GenAI::Result.new(provider: provider_name.to_sym, model: model, raw: raw, values: parsed)
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
gen-ai-0.4.1 lib/gen_ai/base.rb
gen-ai-0.4.0 lib/gen_ai/base.rb
gen-ai-0.4.0.alpha.3 lib/gen_ai/base.rb
gen-ai-0.4.0.alpha.2 lib/gen_ai/base.rb
gen-ai-0.4.0.alpha.1 lib/gen_ai/base.rb
gen-ai-0.3.2 lib/gen_ai/base.rb
gen-ai-0.3.1 lib/gen_ai/base.rb
gen-ai-0.3.0 lib/gen_ai/base.rb
gen-ai-0.2.3 lib/gen_ai/base.rb
gen-ai-0.2.2 lib/gen_ai/base.rb
gen-ai-0.2.1 lib/gen_ai/base.rb
gen-ai-0.2.0 lib/gen_ai/base.rb