Class: Assistant::TechnicalArticleManagementToolBuilder::ListTool
- Inherits:
-
ManagementTool
- Object
- RubyLLM::Tool
- ManagementTool
- Assistant::TechnicalArticleManagementToolBuilder::ListTool
- Defined in:
- app/services/assistant/technical_article_management_tool_builder.rb
Overview
Lists the Technical Article work queue.
Instance Method Summary collapse
-
#execute(state: nil, knowledge_role: nil, assigned_to_me: false, query: nil, limit: 25) ⇒ String
JSON work queue.
-
#name ⇒ String
Stable tool name.
Methods inherited from ManagementTool
Constructor Details
This class inherits a constructor from Assistant::TechnicalArticleManagementToolBuilder::ManagementTool
Instance Method Details
#execute(state: nil, knowledge_role: nil, assigned_to_me: false, query: nil, limit: 25) ⇒ String
Returns JSON work queue.
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'app/services/assistant/technical_article_management_tool_builder.rb', line 187 def execute(state: nil, knowledge_role: nil, assigned_to_me: false, query: nil, limit: 25, **) safely('list') do (:read, ArticleTechnical) scope = ArticleTechnical.all scope = scope.where(state: state) if state.present? scope = scope.where(knowledge_role: knowledge_role) if knowledge_role.present? if assigned_to_me actor_id = require_actor!.id scope = scope.where( 'articles.user_id = :actor_id OR ' \ '(articles.user_id IS NULL AND articles.original_author_id = :actor_id)', actor_id: ) end if query.present? term = ActiveRecord::Base.sanitize_sql_like(query.to_s.strip) scope = scope.where(ArticleTechnical[:subject].matches("%#{term}%")) end priority = Arel.sql( "CASE articles.state WHEN 'pending_review' THEN 0 WHEN 'draft' THEN 1 ELSE 2 END" ) total = scope.count articles = scope .includes(:original_author, :user, :precursor, :successor_article) .reorder(priority, updated_at: :desc) .limit(limit.to_i.clamp(1, 100)) .to_a active_replacement_drafts = ArticleTechnical.active_replacement_drafts_by_source_id(articles.map(&:id)) rows = articles.map do |article| TechnicalArticleManagementToolBuilder.queue_row(article, active_replacement_drafts:) end ChatToolBuilder.truncate_result( { total:, returned: rows.size, articles: rows }.to_json ) end end |
#name ⇒ String
Returns stable tool name.
179 |
# File 'app/services/assistant/technical_article_management_tool_builder.rb', line 179 def name = 'list_technical_articles' |