Sha256: 88a0f990141c0138044b00401ed0702c7eb917c64b462f85ea5d5344cdf298f5
Contents?: true
Size: 939 Bytes
Versions: 2
Compression:
Stored size: 939 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 rescue Faraday::BadRequestError => e raise GenAI::ApiError, "#{api_provider_name} API error: #{e.response[:body].dig('error', 'message')}" 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 def build_chunk(options) GenAI::Chunk.new(provider: provider_name.to_sym, **options) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
gen-ai-0.4.3 | lib/gen_ai/base.rb |
gen-ai-0.4.2 | lib/gen_ai/base.rb |