instructor

Форк
0
149 строк · 4.5 Кб
1
import instructor
2
from openai import OpenAI
3

4
from typing import Optional
5
from pydantic import BaseModel, Field
6
from enum import Enum
7

8
client = instructor.from_openai(OpenAI())
9

10

11
class PriorityEnum(str, Enum):
12
    high = "High"
13
    medium = "Medium"
14
    low = "Low"
15

16

17
class Subtask(BaseModel):
18
    """
19
    Correctly resolved subtask from the given transcript
20
    """
21

22
    id: int = Field(..., description="Unique identifier for the subtask")
23
    name: str = Field(..., description="Informative title of the subtask")
24

25

26
class Ticket(BaseModel):
27
    """
28
    Correctly resolved ticket from the given transcript
29
    """
30

31
    id: int = Field(..., description="Unique identifier for the ticket")
32
    name: str = Field(..., description="Title of the task")
33
    description: str = Field(..., description="Detailed description of the task")
34
    priority: PriorityEnum = Field(..., description="Priority level")
35
    assignees: list[str] = Field(..., description="List of users assigned to the task")
36
    subtasks: Optional[list[Subtask]] = Field(
37
        None, description="List of subtasks associated with the main task"
38
    )
39
    dependencies: Optional[list[int]] = Field(
40
        None, description="List of ticket IDs that this ticket depends on"
41
    )
42

43

44
class ActionItems(BaseModel):
45
    """
46
    Correctly resolved set of action items from the given transcript
47
    """
48

49
    items: list[Ticket]
50

51

52
def generate(data: str):
53
    return client.chat.completions.create(
54
        model="gpt-3.5-turbo-0613",
55
        response_model=ActionItems,
56
        messages=[
57
            {
58
                "role": "system",
59
                "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.",
60
            },
61
            {
62
                "role": "user",
63
                "content": f"Create the action items for the following transcript: {data}",
64
            },
65
        ],
66
    )
67

68

69
prediction = generate(
70
    """
71
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.
72

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

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

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

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

81
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.
82

83
Carol: Is the new billing system already in place?
84

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

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

89
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.
90

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

93
Alice: Sounds like a plan. Let's get these tasks modeled out and get started."""
94
)
95

96
print(prediction.model_dump_json(indent=2))
97
"""
98
{
99
  "items": [
100
    {
101
      "id": 1,
102
      "name": "Improve Authentication System",
103
      "description": "Revamp the front-end and optimize the back-end of the authentication system",
104
      "priority": "High",
105
      "assignees": [
106
        "Bob",
107
        "Carol"
108
      ],
109
      "subtasks": [
110
        {
111
          "id": 2,
112
          "name": "Front-end Revamp"
113
        },
114
        {
115
          "id": 3,
116
          "name": "Back-end Optimization"
117
        }
118
      ],
119
      "dependencies": []
120
    },
121
    {
122
      "id": 4,
123
      "name": "Integrate Authentication System with Billing System",
124
      "description": "Integrate the improved authentication system with the new billing system",
125
      "priority": "Medium",
126
      "assignees": [
127
        "Bob"
128
      ],
129
      "subtasks": [],
130
      "dependencies": [
131
        1
132
      ]
133
    },
134
    {
135
      "id": 5,
136
      "name": "Update User Documentation",
137
      "description": "Update the user documentation to reflect the changes in the authentication system",
138
      "priority": "Low",
139
      "assignees": [
140
        "Carol"
141
      ],
142
      "subtasks": [],
143
      "dependencies": [
144
        2
145
      ]
146
    }
147
  ]
148
}
149
"""
150

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.