Module: Ask::LLM::ProviderConfig
- Included in:
- Providers::Anthropic, Providers::Bedrock, Providers::Cloudflare, Providers::Google, Providers::Mistral, Providers::Ollama, Providers::OpenAI
- Defined in:
- lib/ask/llm/provider_config.rb
Overview
Shared contract for provider request/response transformation.
Every provider includes this module and implements the core methods that define its wire format. The provider's #chat method orchestrates between building requests, making HTTP calls, and parsing responses.
This separation makes each wire-format concern testable in isolation and adding a new provider mechanical — you implement four methods and the provider works.
Instance Method Summary collapse
-
#build_request(messages, model:, tools: nil, temperature: nil, stream: nil, schema: nil, **params) ⇒ Hash
Build a provider-native request payload from internal message format.
-
#format_message(msg) ⇒ Hash
Format a single message for this provider's wire format.
-
#format_tools(tools) ⇒ Array
Format tool definitions for this provider's wire format.
-
#parse_response(body, model) ⇒ Ask::Message
Parse a non-streaming response into an Ask::Message.
-
#parse_stream(raw, stream, model) {|Ask::Chunk| ... } ⇒ Object
Parse raw stream data and yield Ask::Chunks.
Instance Method Details
#build_request(messages, model:, tools: nil, temperature: nil, stream: nil, schema: nil, **params) ⇒ Hash
Build a provider-native request payload from internal message format.
25 26 27 |
# File 'lib/ask/llm/provider_config.rb', line 25 def build_request(, model:, tools: nil, temperature: nil, stream: nil, schema: nil, **params) raise NotImplementedError, "#{self.class} must implement #build_request" end |
#format_message(msg) ⇒ Hash
Format a single message for this provider's wire format.
60 61 62 |
# File 'lib/ask/llm/provider_config.rb', line 60 def (msg) msg end |
#format_tools(tools) ⇒ Array
Format tool definitions for this provider's wire format.
52 53 54 |
# File 'lib/ask/llm/provider_config.rb', line 52 def format_tools(tools) tools end |
#parse_response(body, model) ⇒ Ask::Message
Parse a non-streaming response into an Ask::Message.
34 35 36 |
# File 'lib/ask/llm/provider_config.rb', line 34 def parse_response(body, model) raise NotImplementedError, "#{self.class} must implement #parse_response" end |
#parse_stream(raw, stream, model) {|Ask::Chunk| ... } ⇒ Object
Parse raw stream data and yield Ask::Chunks.
44 45 46 |
# File 'lib/ask/llm/provider_config.rb', line 44 def parse_stream(raw, stream, model, &block) raise NotImplementedError, "#{self.class} must implement #parse_stream" end |