Class: OmniAI::Transcribe

Inherits:
Object
  • Object
show all
Defined in:
lib/omniai/transcribe.rb,
lib/omniai/transcribe/transcription.rb

Overview

An abstract class that provides a consistent interface for processing transcribe requests.

Usage:

class OmniAI::OpenAI::Transcribe < OmniAI::Transcribe
  module Model
    WHISPER_1 = "whisper-1"
  end

  protected

  # @return [Hash]
  def payload
    raise NotImplementedError, "#{self.class.name}#payload undefined"
  end

  # @return [String]
  def path
    raise NotImplementedError, "#{self.class.name}#path undefined"
  end
end

client.transcribe(File.open("..."), model: "...", format: :json)

Defined Under Namespace

Modules: Format, Language Classes: Transcription

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io, client:, model:, language: nil, prompt: nil, temperature: nil, format: Format::JSON) ⇒ Transcribe

Returns a new instance of Transcribe.

Parameters:

  • io (String, Pathname, IO)

    required

  • client (OmniAI::Client)

    the client

  • model (String)

    required

  • language (String, nil) (defaults to: nil)

    optional

  • prompt (String, nil) (defaults to: nil)

    optional

  • temperature (Float, nil) (defaults to: nil)

    optional

  • format (String, nil) (defaults to: Format::JSON)

    optional



106
107
108
109
110
111
112
113
114
# File 'lib/omniai/transcribe.rb', line 106

def initialize(io, client:, model:, language: nil, prompt: nil, temperature: nil, format: Format::JSON)
  @io = io
  @model = model
  @language = language
  @prompt = prompt
  @temperature = temperature
  @format = format
  @client = client
end

Class Method Details

.process!Object



95
96
97
# File 'lib/omniai/transcribe.rb', line 95

def self.process!(...)
  new(...).process!
end

Instance Method Details

#process!OmniAI::Transcribe::Transcription



118
119
120
121
122
123
124
125
# File 'lib/omniai/transcribe.rb', line 118

def process!
  response = request!

  raise HTTPError, response.flush unless response.status.ok?

  text = @format.nil? || @format.eql?(Format::JSON) ? response.parse['text'] : String(response.body)
  Transcription.new(text:, model: @model, format: @format)
end