Sha256: 3792a2b686de684fb4011eeb9f8ef02cc59fd55807494ccf8dfac24eddc63558

Contents?: true

Size: 1.64 KB

Versions: 1

Compression:

Stored size: 1.64 KB

Contents

# frozen_string_literal: true

module AI21
  class Client
    include AI21::Helper
    extend AI21::HTTP

    DEFALUT_COMPLETE_MODEL = "j2-grande"
    DEFAULT_INSTRUCT_MODEL = "j2-grande-instruct"

    def initialize(access_token)
      AI21.configuration.access_token = access_token if access_token
    end

    def complete(prompt, options = {})
      model = options.delete(:model) || DEFALUT_COMPLETE_MODEL

      AI21::Client.post("/#{model}/complete", {prompt: prompt}.merge(snake_to_camel(options)))
    end

    def instruct(prompt, options = {})
      model = options.delete(:model) || DEFAULT_INSTRUCT_MODEL

      AI21::Client.post("/#{model}/complete", {prompt: prompt}.merge(snake_to_camel(options)))
    end

    def paraphrase(prompt, options = {})
      AI21::Client.post("/paraphrase", {text: prompt}.merge(snake_to_camel(options)))
    end

    def correct(prompt)
      AI21::Client.post("/gec", {text: prompt})
    end

    def improvements(prompt, types = ["fluency"])
      AI21::Client.post("/improvements", {text: prompt, types: types})
    end

    def summarize(prompt, source_type = "TEXT", options = {})
      AI21::Client.post("/summarize", {source: prompt, sourceType: source_type}.merge(snake_to_camel(options)))
    end

    def segmentation(prompt, source_type = "TEXT")
      AI21::Client.post("/segmentation", {source: prompt, sourceType: source_type})
    end

    def answer(question, context)
      AI21::Client.post("/experimental/answer", {question: question, context: context})
    end

    def dataset
      @dataset ||= AI21::Dataset.new
    end

    def custom_model
      @custom_model ||= AI21::CustomModel.new
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ai21-0.2.0 lib/ai21/client.rb