Sha256: ebc646ff9ee9ce68b92c3f85855db36fb5c4f60a18fea2909e3319dc6b0c2451

Contents?: true

Size: 882 Bytes

Versions: 6

Compression:

Stored size: 882 Bytes

Contents

# frozen_string_literal: true

module OmniAI
  class Chat
    # A chunk returned by the API.
    class Chunk
      attr_accessor :data

      # @param data [Hash]
      def initialize(data:)
        @data = data
      end

      # @return [String]
      def id
        @data['id']
      end

      # @return [Time]
      def created
        Time.at(@data['created']) if @data['created']
      end

      # @return [Time]
      def updated
        Time.at(@data['updated']) if @data['updated']
      end

      # @return [String]
      def model
        @data['model']
      end

      # @return [Array<OmniAI::Chat::DeltaChoice>]
      def choices
        @choices ||= @data['choices'].map { |data| DeltaChoice.for(data:) }
      end

      # @param index [Integer]
      # @return [OmniAI::Chat::Delta]
      def choice(index: 0)
        choices[index]
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
omniai-1.4.2 lib/omniai/chat/chunk.rb
omniai-1.4.1 lib/omniai/chat/chunk.rb
omniai-1.4.0 lib/omniai/chat/chunk.rb
omniai-1.3.1 lib/omniai/chat/chunk.rb
omniai-1.3.0 lib/omniai/chat/chunk.rb
omniai-1.2.3 lib/omniai/chat/chunk.rb