File size: 7,709 Bytes
f3aae92
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e9fe174
f3aae92
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e9fe174
f3aae92
 
 
 
 
 
 
 
e9fe174
 
 
 
 
 
 
 
 
 
 
 
 
f3aae92
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
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
import uuid
from uuid import UUID 
from datetime import datetime, timezone
from typing import Any, Dict, Optional, List
from pydantic import BaseModel, Field




class DDRHEADER(BaseModel):
    """General Information about a Daily drilling report."""

    # ^ Doc-string for the entity DDRHEADER.
    # This doc-string is sent to the LLM as the description of the schema DDRHEADER,
    # and it can help to improve extraction results.

    # Note that:
    # 1. Each field is an `optional` -- this allows the model to decline to extract it!
    # 2. Each field has a `description` -- this description is used by the LLM.
    # Having a good description can help improve extraction results.
    well_name: Optional[str] = Field(
        default='', description="name of the well  tipical labels: well name , well:"
    )
    # add required float field maxdepth
    measure_depth: Optional[str] = Field(
        default='0', description="last measure depth or MD at the end of the day, usually comes as MD and in feet or meters'"
    )
    vertical_depth: Optional[float] = Field(
        default=0, description="true vertical depth or TVD, usually comes as TVD and in ft'"
    )
    rig_name: Optional[str] = Field(
        default='', description="name of the RIG  typical labels: RIG NO. , RIG NAME"
    )
    operator_name: Optional[str] = Field(
        default='', description="operator name or company name"
    )
    date_of_report: Optional[str] = Field(
        default='', description="date of report, common labeled as date or Report date"
    )
    days_from_spud: Optional[str] = Field(
        default='', description="Days from Spud,(DFS) is the number of days from the beginning of the drilling operation to the report date"
    )
    spud_date: Optional[str] = Field(
        default='', description="you can find it as spud date (SD) is the date when the drilling operation begin"
    )
    report_num:  Optional[str] = Field(
        default='', description="report number or report no. or rpt #"
    )
    state: Optional[str] = Field(
        default='', description="state name, usually county/state, for examples: Texas or California"
    )
    field_name: Optional[str] = Field(
        default='', description="Field name where the well is located typical label: Field"
    )
    wellbore: Optional[str] = Field(
        default='', description="branch name or wellbore name also could be trajectory Name"
    )
    hole_size: Optional[str] = Field(
        default='', description="size of the current open hole, also know as phase"
    )

    
class DAILYOPER(BaseModel):
        """
        extract a the daily summary operation .
        """
        time_from: Optional[str] = Field(
            default='', description=" Time from, usually in the format hh:mm or h:mm, typical labels: 'From' or  'start time'"
        )
        time_to: Optional[str] = Field(
            default='', description=" Time To , usually in the format hh:mm or h:mm, typical labels: 'to' or 'end Time'"
        )

        activity_code: Optional[str] = Field(
            default='', description="string that codify the code of the current activity"
        )
        description: Optional[str] = Field(
            default='', description="The description of the current operation or comments, which could take several lines"
        )
class DAILYOPERATIONS (BaseModel):
    """A list of daily summary operations"""
    operations: List[DAILYOPER]

class FLUID(BaseModel):
    """
    Extract Daily drilling fluid information.
    """
    density: Optional[float] = Field(
        default=0.0, description="Density of mud fluid, usually in g/cm³ or lb/gal or ppg"
    )
    fluid_name: Optional[str] = Field(
        default='', description="Name of the mud fluid"
    )
    fluid_type: Optional[str] = Field(
        default='', description="Type of the mud fluid, e.g., water-based, oil-based"
    )
    viscosity: Optional[float] = Field(
        default=0.0, description="Viscosity of the fluid (PV), usually in cP"
    )
    YP: Optional[float] = Field(
        default=0.0, description="Yield Point (YP) of the Mud"
    )
    temperature: Optional[float] = Field(
        default=0.0, description="Temperature of the Mud fluid, usually in °C or °F"
    )
    fluid_depth: Optional[float] = Field(
        default=0.0, description="Depth at which the mud fluid is measured, usually in ft or m"
    )

class DDR(BaseModel):
    """
    A class representing a Daily Drilling Report (DDR).
    """
    fluid: FLUID = Field(
        ..., description="Daily drilling fluid information."
    )
    ddr_header: DDRHEADER = Field(
        ..., description="Header information for the Daily Drilling Report."
    )
    daily_operations: List[DAILYOPER] = Field(
        ..., description="List of daily summary operations."
    )

        
         
class TimestampedModel(BaseModel):
    """An abstract base model that includes the timestamp fields."""
    __abstract__ = True
    created_at: datetime = Field(
        default_factory=lambda: datetime.now(timezone.utc),
        description="The time the record was created (UTC)."
    )
    updated_at: datetime = Field(
        default_factory=lambda: datetime.now(timezone.utc),
        description="The time the record was updated (UTC)."
    )

    # This is our own uuid assigned to the artifact.
    # By construction guaranteed to be unique no matter what.
    uuid: UUID = Field(
        default_factory=uuid.uuid4,
        description="Unique identifier for this example."
    )


class Example(TimestampedModel):
    """A representation of an example.

    Examples consist of content together with the expected output.

    The output is a JSON object that is expected to be extracted from the content.

    The JSON object should be valid according to the schema of the associated Report extractor.

    The JSON object is defined by the schema of the associated Report  extractor, so
    it's perfectly fine for a given example to represent the extraction
    of multiple instances of some object from the content since
    the JSON schema can represent a list of objects.
    """

    __tablename__ = "examples"

    text: str = Field(
        ...,
        description="The input portion of the example."
    )
    output: List[Dict[str, Any]] = Field(
        ..., description="The expected output of the example. A list of objects."
    )

    report_type: str = Field(
        ...,
        description="type od report associated with the example."
    )

    def __repr__(self) -> str:
        return f"<Example(report_type={self.report_type}, content={self.text[:20]}>"


class ReportExtractor(TimestampedModel):
    __tablename__ = "reportextractors"

    name: str = Field(
        ...,
        max_length=100,
        description="The name of the extractor."
    )
    owner_id: str = Field(
        ...,
        description="Owner uuid."
    )
    output_schema: dict = Field(
        ...,
        description="JSON Schema that describes what content will be extracted from the document."
    )
    description: str = Field(
        ...,
        max_length=100,
        description="Surfaced via UI to the users."
    )
    instruction: str = Field(
        ...,
        description="The prompt to the language model."
    )  # TODO: This will need to evolve

    examples: List[Example] = Field(
        default_factory=list,
        description="List of examples associated with this  Reportextractor."
    )
    report_type: str = Field(
        ...,
        description="type of report ."
    )
    
    def __repr__(self) -> str:
        return f"<ReportExtractor(id={self.report_type}, description={self.description})>"