Class: LLM::DeepInfra::Audio

Inherits:
Object
  • Object
show all
Defined in:
lib/llm/providers/deepinfra/audio.rb

Instance Method Summary collapse

Constructor Details

#initialize(provider) ⇒ LLM::DeepInfra::Audio

Parameters:



9
10
11
# File 'lib/llm/providers/deepinfra/audio.rb', line 9

def initialize(provider)
  @provider = provider
end

Instance Method Details

#create_speech(input:, model: "hexgrad/Kokoro-82M", **params) ⇒ LLM::Response

Parameters:

  • input (String)

    A string of text

  • model (String) (defaults to: "hexgrad/Kokoro-82M")

    A text-to-speech model. Defaults to hexgrad/Kokoro-82M.

  • params (Hash)

    Any other model-specific parameters

Returns:



22
23
24
25
26
27
28
29
30
# File 'lib/llm/providers/deepinfra/audio.rb', line 22

def create_speech(input:, model: "hexgrad/Kokoro-82M", **params)
  path = path("/v1/inference/#{model}", base_path: false)
  req = LLM::Transport::Request.post(path, headers)
  req.body = JSON.dump(params.merge(text: input))
  res, span, tracer = execute(request: req, operation: "request")
  res = ResponseAdapter.adapt LLM::Response.new(res), type: :audio
  tracer.on_request_finish(operation: "request", model:, res:, span:)
  res
end

#create_transcription(file:, model: "openai/whisper-large-v3", **params) ⇒ LLM::Response

Parameters:

  • file (String, LLM::File)

    An audio file

  • model (String) (defaults to: "openai/whisper-large-v3")

    A speech-to-text model.

  • params (Hash)

    Any other model-specific parameters

Returns:

See Also:



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/llm/providers/deepinfra/audio.rb', line 42

def create_transcription(file:, model: "openai/whisper-large-v3", **params)
  path = path("/v1/inference/#{model}", base_path: false)
  multi = LLM::Multipart.new(params.merge!(audio: LLM.File(file)))
  req = LLM::Transport::Request.post(path, headers)
  req["content-type"] = multi.content_type
  transport.set_body_stream(req, multi.body)
  res, span, tracer = execute(request: req, operation: "request")
  res = LLM::Response.new(res)
  tracer.on_request_finish(operation: "request", model:, res:, span:)
  res
end

#create_translationObject

Raises:

  • (NotImplementedError)


56
57
58
# File 'lib/llm/providers/deepinfra/audio.rb', line 56

def create_translation(...)
  raise NotImplementedError
end