Class: Assistant::GscToolBuilder
- Inherits:
-
Object
- Object
- Assistant::GscToolBuilder
- Defined in:
- app/services/assistant/gsc_tool_builder.rb
Overview
Service object: gsc tool builder.
Constant Summary collapse
- TOOL_DEFINITIONS =
Tool definitions.
[ { tool_name: 'gsc_page_metrics', description: '[Search Console] Get aggregated search metrics for a specific page URL. ' \ 'Returns total clicks, impressions, average CTR, and average position.', params: { type: 'object', properties: { page_url: { type: 'string', description: 'Full URL of the page (e.g., "https://www.warmlyyours.com/en-US/posts/my-article")' }, start_date: { type: 'string', description: 'Start date (YYYY-MM-DD format)' }, end_date: { type: 'string', description: 'End date (YYYY-MM-DD format)' } }, required: %w[page_url start_date end_date] }, execute: lambda { |page_url:, start_date:, end_date:, **_| client = Seo::GscApiClient.new result = client.page_metrics(page_url: page_url, start_date: start_date, end_date: end_date) (result || { message: 'No data found for this URL' }).to_json } }, { tool_name: 'gsc_page_queries', description: '[Search Console] Get top search queries driving traffic to a specific page. ' \ 'Shows which keywords people search for that lead to this page, with clicks, impressions, CTR, and position.', params: { type: 'object', properties: { page_url: { type: 'string', description: 'Full URL of the page' }, start_date: { type: 'string', description: 'Start date (YYYY-MM-DD format)' }, end_date: { type: 'string', description: 'End date (YYYY-MM-DD format, defaults to today)' }, limit: { type: 'integer', description: 'Max queries to return (default: 50)' } }, required: %w[page_url start_date] }, execute: lambda { |page_url:, start_date:, end_date: Time.zone.today.to_s, limit: 50, **_| client = Seo::GscApiClient.new results = client.page_queries(page_url: page_url, start_date: start_date, end_date: end_date, limit: limit.to_i) Assistant::ChatToolBuilder.truncate_result(results.to_json) } } ].freeze
Class Method Summary collapse
Class Method Details
.tools ⇒ Object
46 47 48 49 50 51 |
# File 'app/services/assistant/gsc_tool_builder.rb', line 46 def tools @tools ||= build_tools rescue StandardError => e Rails.logger.warn("[GscToolBuilder] Failed to build GSC tools: #{e.}") [] end |