Module: RubyTodo::AIAssistant::TaskCreator

Included in:
TaskCreatorCombined
Defined in:
lib/ruby_todo/ai_assistant/task_creator.rb

Overview

Module for natural language task creation

Instance Method Summary collapse

Instance Method Details

#build_task_query(task_description) ⇒ Object

Build the query to send to OpenAI



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/ruby_todo/ai_assistant/task_creator.rb', line 57

def build_task_query(task_description)
  "Generate a professional task with the following information:\n" \
    "Task description: #{task_description}\n" \
    "Please generate a JSON response with these fields:\n" \
    "- title: A concise, professional title for the task. Transform basic descriptions into more professional, " \
    "action-oriented titles. For example, 'add new relic infra to questions-engine' should become " \
    "'Integrate New Relic Infrastructure with Questions Engine'\n" \
    "- description: A detailed description of what the task involves\n" \
    "- priority: Suggested priority (must be exactly one of: 'high', 'medium', or 'low')\n" \
    "- tags: Relevant tags as a comma-separated string"
end

#default_notebook_nameObject

Get the default notebook name or fallback to “default”



28
29
30
31
# File 'lib/ruby_todo/ai_assistant/task_creator.rb', line 28

def default_notebook_name
  default_notebook = RubyTodo::Notebook.default_notebook
  default_notebook ? default_notebook.name : "default"
end

#extract_task_description(prompt) ⇒ Object

Extract task description from the prompt



34
35
36
37
38
39
40
41
# File 'lib/ruby_todo/ai_assistant/task_creator.rb', line 34

def extract_task_description(prompt)
  # Match common task creation patterns
  if prompt =~ /(?:create|add|make|set\s+up)(?:\s+a)?\s+(?:new\s+)?task\s+(?:to|for|about|:)\s+(.+)/i
    Regexp.last_match(1).strip
  else
    prompt.strip
  end
end

#generate_task_details(task_description, api_key) ⇒ Object

Generate task details using AI



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ruby_todo/ai_assistant/task_creator.rb', line 44

def generate_task_details(task_description, api_key)
  # Build the query for AI
  task_query = build_task_query(task_description)

  # Query OpenAI for task details
  say "Enhancing task title and generating details..." if @options && @options[:verbose]
  content = query_openai_for_task_details(task_query, api_key)

  # Parse the response
  parse_task_details_response(content, task_description)
end

#handle_natural_language_task_creation(prompt, api_key) ⇒ Object

Handle natural language task creation



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ruby_todo/ai_assistant/task_creator.rb', line 13

def handle_natural_language_task_creation(prompt, api_key)
  # Get the default notebook
  notebook_name = default_notebook_name

  # Extract task description from prompt
  task_description = extract_task_description(prompt)

  # Generate task details using AI
  task_details = generate_task_details(task_description, api_key)

  # Create the task
  create_task_from_details(notebook_name, task_details)
end