class Riffer::Providers::Base
Base class for all LLM providers in the Riffer framework.
Provides a template-method flow for text generation and streaming. Subclasses implement five hook methods; the base class orchestrates them.
Hook methods
- build_request_params
-
convert messages, tools, and options into SDK params
- execute_generate
-
call the SDK and return the raw response
- execute_stream
-
call the streaming SDK, mapping events to the yielder
- extract_token_usage
-
pull token counts from the SDK response
- extract_content
-
extract text content from the SDK response
- extract_tool_calls
-
extract tool calls from the SDK response
Constants
- WIRE_SEPARATOR
Public Class Methods
Source
# File lib/riffer/providers/base.rb, line 31 def self.skills_adapter Riffer::Skills::MarkdownAdapter end
Returns the preferred skill adapter for this provider.
Override in subclasses for provider-specific formats.
Public Instance Methods
Source
# File lib/riffer/providers/base.rb, line 39 def generate_text(prompt: nil, system: nil, messages: nil, model: nil, files: nil, **options) validate_input!(prompt: prompt, system: system, messages: messages) @current_tools = options[:tools] || [] messages = normalize_messages(prompt: prompt, system: system, messages: messages, files: files) validate_normalized_messages!(messages) messages = merge_consecutive_messages(messages) params = build_request_params(messages, model, options) response = execute_generate(params) content = extract_content(response) tool_calls = extract_tool_calls(response) token_usage = extract_token_usage(response) structured_output = parse_structured_output(content) if options[:structured_output] && tool_calls.empty? Riffer::Messages::Assistant.new( content, tool_calls: tool_calls, token_usage: token_usage, structured_output: structured_output ) end
Generates text using the provider.
Source
# File lib/riffer/providers/base.rb, line 65 def stream_text(prompt: nil, system: nil, messages: nil, model: nil, files: nil, **options) validate_input!(prompt: prompt, system: system, messages: messages) @current_tools = options[:tools] || [] messages = normalize_messages(prompt: prompt, system: system, messages: messages, files: files) validate_normalized_messages!(messages) messages = merge_consecutive_messages(messages) params = build_request_params(messages, model, options) Enumerator.new do |yielder| execute_stream(params, yielder) end end
Streams text from the provider.