lib/gen_ai/base.rb in gen-ai-0.4.1 vs lib/gen_ai/base.rb in gen-ai-0.4.2
- old
+ new
@@ -13,10 +13,12 @@
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
@@ -25,8 +27,12 @@
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