instructor
149 строк · 4.5 Кб
1import instructor2from openai import OpenAI3
4from typing import Optional5from pydantic import BaseModel, Field6from enum import Enum7
8client = instructor.from_openai(OpenAI())9
10
11class PriorityEnum(str, Enum):12high = "High"13medium = "Medium"14low = "Low"15
16
17class Subtask(BaseModel):18"""19Correctly resolved subtask from the given transcript
20"""
21
22id: int = Field(..., description="Unique identifier for the subtask")23name: str = Field(..., description="Informative title of the subtask")24
25
26class Ticket(BaseModel):27"""28Correctly resolved ticket from the given transcript
29"""
30
31id: int = Field(..., description="Unique identifier for the ticket")32name: str = Field(..., description="Title of the task")33description: str = Field(..., description="Detailed description of the task")34priority: PriorityEnum = Field(..., description="Priority level")35assignees: list[str] = Field(..., description="List of users assigned to the task")36subtasks: Optional[list[Subtask]] = Field(37None, description="List of subtasks associated with the main task"38)39dependencies: Optional[list[int]] = Field(40None, description="List of ticket IDs that this ticket depends on"41)42
43
44class ActionItems(BaseModel):45"""46Correctly resolved set of action items from the given transcript
47"""
48
49items: list[Ticket]50
51
52def generate(data: str):53return client.chat.completions.create(54model="gpt-3.5-turbo-0613",55response_model=ActionItems,56messages=[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
69prediction = generate(70"""71Alice: 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
73Bob: Got it, Alice. I can take the lead on the authentication improvements. Are there any specific areas you want me to focus on?
74
75Alice: Good question, Bob. We need both a front-end revamp and back-end optimization. So basically, two sub-tasks.
76
77Carol: I can help with the front-end part of the authentication system.
78
79Bob: Great, Carol. I'll handle the back-end optimization then.
80
81Alice: 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
83Carol: Is the new billing system already in place?
84
85Alice: No, it's actually another task. So it's a dependency for the integration task. Bob, can you also handle the billing system?
86
87Bob: Sure, but I'll need to complete the back-end optimization of the authentication system first, so it's dependent on that.
88
89Alice: 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
91Carol: I can take that on once the front-end changes for the authentication system are done. So, it would be dependent on that.
92
93Alice: Sounds like a plan. Let's get these tasks modeled out and get started."""
94)
95
96print(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": [
1311
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": [
1442
145]
146}
147]
148}
149"""
150