Module: Raif::Concerns::ProviderManagedToolCalls
- Extended by:
- ActiveSupport::Concern
- Included in:
- ModelCompletion
- Defined in:
- app/models/raif/concerns/provider_managed_tool_calls.rb
Instance Method Summary collapse
-
#provider_managed_tool_calls ⇒ Object
Provider-managed tool data is not normalized by the provider SDKs the same way developer-managed tool calls are.
-
#sanitized_citations ⇒ Object
Returns citations with URLs sanitized to only allow http/https schemes.
Instance Method Details
#provider_managed_tool_calls ⇒ Object
Provider-managed tool data is not normalized by the provider SDKs the same way developer-managed tool calls are. This method smooths those differences into one admin-friendly structure for the model completion page.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/models/raif/concerns/provider_managed_tool_calls.rb', line 9 def provider_managed_tool_calls # Memoized for repeated reads during a request/render. This assumes the # completion's response payload is not mutated after first access. @provider_managed_tool_calls ||= begin tool_calls = extract_provider_managed_tool_calls tool_calls = inferred_provider_managed_tool_calls if tool_calls.empty? tool_calls.map do |tool_call| next tool_call unless tool_call["tool_name"] == "web_search" # Search sources can come from explicit provider result blocks # (Anthropic) or from top-level citations (OpenAI / Google), so we # merge both. tool_call.merge("sources" => merge_provider_managed_sources(tool_call["sources"], citations)) end end end |
#sanitized_citations ⇒ Object
Returns citations with URLs sanitized to only allow http/https schemes.
28 29 30 31 32 33 34 |
# File 'app/models/raif/concerns/provider_managed_tool_calls.rb', line 28 def sanitized_citations @sanitized_citations ||= Array(citations).map do |citation| url = citation["url"] safe_url = url.present? && url.match?(%r{\Ahttps?://}i) ? url : nil citation.merge("url" => safe_url) end end |