Class: Roseflow::OpenAI::EmbeddingApiResponse

Inherits:
ApiResponse
  • Object
show all
Defined in:
lib/roseflow/openai/response.rb

Overview

ImageApiResponse

Instance Method Summary collapse

Methods inherited from ApiResponse

#initialize, #status, #success?

Constructor Details

This class inherits a constructor from Roseflow::OpenAI::ApiResponse

Instance Method Details

#bodyObject



76
77
78
79
80
81
82
83
84
85
# File 'lib/roseflow/openai/response.rb', line 76

def body
  @body ||= begin
      case @response.status
      when 200
        EmbeddingApiResponseBody.new(JSON.parse(@response.body))
      else
        EmbeddingApiResponseErrorBody.new(JSON.parse(@response.body))
      end
    end
end

#embeddingObject



87
88
89
90
91
92
93
94
# File 'lib/roseflow/openai/response.rb', line 87

def embedding
  case @response.status
  when 200
    body.data.map { |embedding| Embedding.new(embedding) }.first
  else
    raise FailedToCreateEmbeddingError, body.error.message
  end
end