Class: GroqRuby::Resources::Audio::Transcriptions

Inherits:
Base
  • Object
show all
Defined in:
lib/groq_ruby/resources/audio/transcriptions.rb

Overview

‘client.audio.transcriptions.create(…)` — speech to text. Either an in-memory `file:` IO or a remote `url:` must be supplied.

Constant Summary collapse

PATH =
"/openai/v1/audio/transcriptions".freeze
SCHEMA =
Dry::Schema.define do
  required(:model).filled(:string)
  optional(:language).filled(:string)
  optional(:prompt).filled(:string)
  optional(:response_format).filled(:string, included_in?: %w[json text srt verbose_json vtt])
  optional(:temperature).filled(:float, gteq?: 0.0, lteq?: 1.0)
  optional(:timestamp_granularities).value(:array)
end

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from GroqRuby::Resources::Base

Instance Method Details

#create(file: nil, filename: nil, url: nil, **params) ⇒ GroqRuby::Models::Transcription

Parameters:

  • file (IO, nil) (defaults to: nil)

    readable IO or nil if ‘url:` is given.

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

    filename for the multipart upload.

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

    URL the API can fetch instead of an upload.

  • params (Hash)

    required: ‘:model`. Optional: `:language`, `:prompt`, `:response_format`, `:temperature`, `:timestamp_granularities`.

Returns:

Raises:

  • (ParameterError)

    when neither ‘file:` nor `url:` is given, or when other params fail validation.



29
30
31
32
33
34
35
# File 'lib/groq_ruby/resources/audio/transcriptions.rb', line 29

def create(file: nil, filename: nil, url: nil, **params)
  raise ParameterError, {file: ["either file or url is required"]} if file.nil? && url.nil?
  body = validate!(SCHEMA, params)
  multipart = build_multipart(file: file, filename: filename, url: url, body: body)
  request = Request.new(method: :post, path: PATH, body: multipart.body, content_type: multipart.content_type)
  GroqRuby::Models::Transcription.from_hash(perform(request))
end