Class: Assistant::TechnicalSupport::ResponseGroundingCitationUrls

Inherits:
Object
  • Object
show all
Defined in:
app/services/assistant/technical_support/response_grounding_citation_urls.rb

Overview

Normalizes URLs from an answer and, separately, extracts only explicit URL
or citation fields from a successful structured tool payload.

Constant Summary collapse

URL_PATTERN =
CaseReplayEvidence::URL_PATTERN
URL_FIELD_PATTERN =
/(?:\A|_)(?:url|uri|href)s?\z/
CITATION_FIELDS =
%w[citation citations].freeze

Class Method Summary collapse

Class Method Details

.from_payload(payload) ⇒ Array<String>

Extracts URLs only from explicit URL/citation payload fields.

Parameters:

  • payload (Hash, Array)

    successful structured tool payload

Returns:

  • (Array<String>)

    unique normalized citation URLs



27
28
29
# File 'app/services/assistant/technical_support/response_grounding_citation_urls.rb', line 27

def from_payload(payload)
  extract(payload).uniq
end

.in_text(text) ⇒ Array<String>

Extracts and normalizes every URL present in answer text.

Parameters:

  • text (String)

    answer or explicit citation-field text

Returns:

  • (Array<String>)

    unique normalized URLs



19
20
21
# File 'app/services/assistant/technical_support/response_grounding_citation_urls.rb', line 19

def in_text(text)
  text.to_s.scan(URL_PATTERN).filter_map { |url| normalize(url) }.uniq
end