跳到内容

示例:从会议记录中提取行动项

在本指南中,我们将详细介绍如何使用 OpenAI 的 API 从会议记录中提取行动项。此用例是自动化项目管理任务(例如任务分配和优先级设置)的良好示例。

动机

会议花费了大量时间,其中行动项作为这些讨论的可执行成果而产生。自动化行动项的提取可以节省时间,并确保不会遗漏任何关键任务。

定义结构

我们将会议记录建模为 Ticket 对象的集合,每个对象代表一个行动项。每个 Ticket 可以有多个 Subtask 对象,代表主任务的更小、更易于管理的部分。

  class Subtask
    include EasyTalk::Model

    define_schema do
      property :id, Integer, description: 'Unique identifier for the subtask'
      property :name, String, description: 'Informative title of the subtask'
    end
  end

  class Ticket
    include EasyTalk::Model

    PRIORITY = %w[low medium high].freeze

    define_schema do
      property :id, Integer, description: 'Unique identifier for the ticket'
      property :name, String, description: 'Title of the ticket'
      property :description, String, description: 'Detailed description of the ticket'
      property :priority, String, description: 'Priority level'
      property :assignees, T::Array[String], description: 'List of users assigned to the ticket'
      property :subtasks, T.nilable(T::Array[Subtask]), description: 'List of subtasks associated with the ticket'
      property :dependencies, T.nilable(T::Array[Integer]),
               description: 'List of ticket IDs that this ticket depends on'
    end
  end

  class ActionItems
    include EasyTalk::Model

    define_schema do
      property :items, T::Array[Ticket]
    end
  end

提取行动项

要从会议记录中提取行动项,我们使用 extract_action_items() 方法。它调用 OpenAI 的 API,处理文本,并返回一组建模为 ActionItems 的行动项。

  def extract_action_items(data)
    client = Instructor.from_openai(OpenAI::Client).new

    client.chat(
      parameters: {
        model: 'gpt-3.5-turbo',
        messages: [
          {
            role: 'system',
            "content": 'The following is a transcript of a meeting between a manager and their team. The manager is assigning tasks to their team members and creating action items for them to complete.'
          },
          {
            "role": 'user',
            "content": "Create the action items for the following transcript: #{data}"
          }
        ]
      },
      response_model: ActionItems
    )
  end

评估与测试

为了测试 extract_action_items 方法,我们为其提供示例记录,然后打印提取的行动项的 JSON 表示。

   data = <<~DATA
      Alice: Hey team, we have several critical tasks we need to tackle for the upcoming release. First, we need to work on improving the authentication system. It's a top priority.

      Bob: Got it, Alice. I can take the lead on the authentication improvements. Are there any specific areas you want me to focus on?

      Alice: Good question, Bob. We need both a front-end revamp and back-end optimization. So basically, two sub-tasks.

      Carol: I can help with the front-end part of the authentication system.

      Bob: Great, Carol. I'll handle the back-end optimization then.

      Alice: Perfect. Now, after the authentication system is improved, we have to integrate it with our new billing system. That's a medium priority task.

      Carol: Is the new billing system already in place?

      Alice: No, it's actually another task. So it's a dependency for the integration task. Bob, can you also handle the billing system?

      Bob: Sure, but I'll need to complete the back-end optimization of the authentication system first, so it's dependent on that.

      Alice: Understood. Lastly, we also need to update our user documentation to reflect all these changes. It's a low-priority task but still important.

      Carol: I can take that on once the front-end changes for the authentication system are done. So, it would be dependent on that.

      Alice: Sounds like a plan. Let's get these tasks modeled out and get started.
    DATA

    result = generate(data)
    puts(result.as_json)

任务可视化

为了快速可视化数据,我们使用代码解释器创建了 ActionItems 数组 JSON 版本的 graphviz 导出。

action items

{
  "items": [
    {
      "id": 1,
      "name": "Improve Authentication System",
      "description": "Revamp the front-end and optimize the back-end of the authentication system",
      "priority": "High",
      "assignees": ["Bob", "Carol"],
      "subtasks": [
        {
          "id": 2,
          "name": "Front-end Revamp"
        },
        {
          "id": 3,
          "name": "Back-end Optimization"
        }
      ],
      "dependencies": []
    },
    {
      "id": 4,
      "name": "Integrate Authentication System with Billing System",
      "description": "Integrate the improved authentication system with the new billing system",
      "priority": "Medium",
      "assignees": ["Bob"],
      "subtasks": [],
      "dependencies": [1]
    },
    {
      "id": 5,
      "name": "Update User Documentation",
      "description": "Update the user documentation to reflect the changes in the authentication system",
      "priority": "Low",
      "assignees": ["Carol"],
      "subtasks": [],
      "dependencies": [2]
    }
  ]
}

在此示例中,extract_action_items 方法成功识别并分割了行动项,并按照会议讨论的情况为其分配了优先级、负责人、子任务和依赖项。

通过自动化此过程,您可以确保重要任务和细节不会在会议记录的海洋中丢失,从而使项目管理更加高效和有效。