Sha256: e503cfc5fd00e418b3d65e47d43728ce82bd88bc0f7bfcecd7b113201d5cc91f

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

module OmniAI
  # An abstract class that provides an interface for chatting for various vendors (e.g. OpenAI’s ChatGPT).
  #
  # Usage:
  #
  #   class OmniAI::OpenAI::Chat < OmniAI::Chat
  #     def completion(messages, model:, temperature: 0.0, format: :text)
  #       # TODO: implement
  #     end
  #   end
  #
  # Once defined, it can be used to interface with the vendor's chat API as follows:
  #
  #   client.chat.completion("...", model: "...", temperature: 0.0, format: :text)
  #
  # @param client [OmniAI::Client] the client
  class Chat
    JSON_PROMPT = 'Respond with valid JSON. Do not include any non-JSON in the response.'

    module Role
      ASSISTANT = 'assistant'
      USER = 'user'
      SYSTEM = 'system'
    end

    def initialize(client:)
      @client = client
    end

    # @raise [OmniAI::Error]
    #
    # @param messages [String, Array, Hash, OmnniAI::Chat::Message]
    # @param model [String] optional
    # @param format [Symbol] optional :text or :json
    # @param temperature [Float, nil] optional
    # @param stream [Proc, nil] optional
    #
    # @return [OmniAI::Chat::Request]
    def completion(messages, model:, temperature: nil, format: nil, stream: nil)
      raise NotImplementedError, "#{self.class.name}#completion undefined"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
omniai-1.0.0 lib/omniai/chat.rb