Top Level Namespace

Defined Under Namespace

Modules: Durable

Instance Method Summary collapse

Instance Method Details

#DLLM(provider, **options) ⇒ Durable::Llm::Client

Shorter alias for DurableLlm

Parameters:

  • provider (Symbol, String)

    The provider name

  • options (Hash)

    Configuration options

Returns:

See Also:



34
35
36
# File 'lib/durable/llm/convenience.rb', line 34

def DLLM(provider, **options)
  Durable::Llm.new(provider, options)
end

#DurableLlm(provider, **options) ⇒ Durable::Llm::Client

Creates a new Durable LLM client with the specified provider and options.

This is a global convenience function that provides quick access to client creation without requiring the full Durable::Llm module path. It's equivalent to calling Durable::Llm.new(provider, options).

Examples:

Create an OpenAI client

client = DurableLlm(:openai, model: 'gpt-4', api_key: 'sk-...')
response = client.complete('Hello!')

Create an Anthropic client

client = DurableLlm(:anthropic, model: 'claude-3-opus-20240229')

Parameters:

  • provider (Symbol, String)

    The provider name (e.g., :openai, :anthropic)

  • options (Hash)

    Configuration options for the client

Options Hash (**options):

  • :model (String)

    The default model to use

  • :api_key (String)

    API key for authentication

Returns:



24
25
26
# File 'lib/durable/llm/convenience.rb', line 24

def DurableLlm(provider, **options)
  Durable::Llm.new(provider, options)
end

#LlmChat(messages, provider: :openai, model: nil, **options) ⇒ Object

Performs a chat completion with minimal setup

This global convenience function allows for quick chat interactions without explicit client creation.

Examples:

Simple chat

response = LlmChat([{ role: 'user', content: 'Hello!' }], model: 'gpt-4')
puts response.choices.first.message.content

Parameters:

  • messages (Array<Hash>)

    Array of message hashes with :role and :content

  • provider (Symbol) (defaults to: :openai)

    The provider to use (default: :openai)

  • model (String) (defaults to: nil)

    The model to use (required)

  • options (Hash)

    Additional options

Returns:

  • (Object)

    The chat response object



70
71
72
# File 'lib/durable/llm/convenience.rb', line 70

def LlmChat(messages, provider: :openai, model: nil, **options)
  Durable::Llm.chat(messages, provider: provider, model: model, **options)
end

#LlmComplete(text, provider: :openai, model: nil, **options) ⇒ String

Performs a quick text completion with minimal setup

This global convenience function allows for one-line LLM completions without explicit client creation. Perfect for scripts and REPL usage.

Examples:

Quick completion

result = LlmComplete('What is Ruby?', model: 'gpt-4')
puts result

With specific provider

result = LlmComplete('Explain AI', provider: :anthropic, model: 'claude-3-opus-20240229')

Parameters:

  • text (String)

    The input text to complete

  • provider (Symbol) (defaults to: :openai)

    The provider to use (default: :openai)

  • model (String) (defaults to: nil)

    The model to use (required)

  • options (Hash)

    Additional client options

Returns:

  • (String)

    The completion text



53
54
55
# File 'lib/durable/llm/convenience.rb', line 53

def LlmComplete(text, provider: :openai, model: nil, **options)
  Durable::Llm.complete(text, provider: provider, model: model, **options)
end

#LlmConfigure {|configuration| ... } ⇒ void

This method returns an undefined value.

Configures Durable LLM with a block

This global convenience function provides easy access to configuration.

Examples:

Configure API keys

LlmConfigure do |config|
  config.openai.api_key = 'sk-...'
  config.anthropic.api_key = 'sk-ant-...'
end

Yields:

  • (configuration)

    The configuration instance to modify

Yield Parameters:



98
99
100
# File 'lib/durable/llm/convenience.rb', line 98

def LlmConfigure(&block)
  Durable::Llm.configure(&block)
end

#LlmModels(provider = :openai, **options) ⇒ Array<String>

Lists available models for a provider

Examples:

List models

models = LlmModels(:openai)
puts models.inspect

Parameters:

  • provider (Symbol) (defaults to: :openai)

    The provider name (default: :openai)

  • options (Hash)

    Provider options

Returns:

  • (Array<String>)

    List of available model IDs



82
83
84
# File 'lib/durable/llm/convenience.rb', line 82

def LlmModels(provider = :openai, **options)
  Durable::Llm.models(provider, **options)
end