Class: GroqRuby::Resources::Audio::Translations

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

Overview

‘client.audio.translations.create(…)` — translates speech in any supported language into English text.

Constant Summary collapse

PATH =
"/openai/v1/audio/translations".freeze
SCHEMA =
Dry::Schema.define do
  required(:model).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)
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::Translation

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: `:prompt`, `:response_format`, `:temperature`.

Returns:

Raises:

  • (ParameterError)

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



26
27
28
29
30
31
32
# File 'lib/groq_ruby/resources/audio/translations.rb', line 26

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::Translation.from_hash(perform(request))
end