Class: Assistant::TechnicalSupport::CaseReplayEvidence
- Inherits:
-
Object
- Object
- Assistant::TechnicalSupport::CaseReplayEvidence
- Defined in:
- app/services/assistant/technical_support/case_replay_evidence.rb
Overview
Verifies citation provenance and identifies Technical Articles from the
persisted tool trace of one holdout replay. Only explicit citation fields
from successful canonical-content tools are trusted.
Defined Under Namespace
Classes: ArticleEvidence, ProductEvidence, PublicationEvidence, ToolPayload
Constant Summary collapse
- URL_PATTERN =
Stop before Markdown delimiters. A common valid response shape uses the
canonical URL as both label and target:[https://…](https://…). The
broad scanner previously merged both URLs into one invented value. %r{https?://[^\s<>"'\])]+}
Instance Method Summary collapse
- #citations_grounded?(citation_urls) ⇒ Boolean
-
#initialize(tool_trace:) ⇒ CaseReplayEvidence
constructor
A new instance of CaseReplayEvidence.
- #technical_article_ids(citation_urls:, limit:) ⇒ Object
- #urls_in(text) ⇒ Object
Constructor Details
#initialize(tool_trace:) ⇒ CaseReplayEvidence
Returns a new instance of CaseReplayEvidence.
14 15 16 17 18 19 |
# File 'app/services/assistant/technical_support/case_replay_evidence.rb', line 14 def initialize(tool_trace:) trace = Array(tool_trace) @articles = ArticleEvidence.new(trace, normalize_url: method(:normalize_url)) @publications = PublicationEvidence.new(trace, normalize_url: method(:normalize_url)) @products = ProductEvidence.new(trace) end |
Instance Method Details
#citations_grounded?(citation_urls) ⇒ Boolean
25 26 27 28 29 30 |
# File 'app/services/assistant/technical_support/case_replay_evidence.rb', line 25 def citations_grounded?(citation_urls) return false if citation_urls.empty? allowed_urls = (articles.citation_urls + publications.citation_urls + products.citation_urls).uniq (citation_urls - allowed_urls).empty? end |
#technical_article_ids(citation_urls:, limit:) ⇒ Object
32 33 34 35 36 37 38 |
# File 'app/services/assistant/technical_support/case_replay_evidence.rb', line 32 def technical_article_ids(citation_urls:, limit:) normalized_citations = Array(citation_urls).filter_map { |url| normalize_url(url) }.to_set articles.canonical_urls_by_id.filter_map do |id, url| id if normalized_citations.include?(url) end.first(limit) end |
#urls_in(text) ⇒ Object
21 22 23 |
# File 'app/services/assistant/technical_support/case_replay_evidence.rb', line 21 def urls_in(text) text.to_s.scan(URL_PATTERN).filter_map { |url| normalize_url(url) }.uniq end |