Spaces:
Sleeping
Sleeping
Download db/models.py from RigDataDynamics/cygnus_server: direct link, hf CLI and curl.
- Browser
- Download file 7.71 kB
-
https://huggingface.co/spaces/RigDataDynamics/cygnus_server/resolve/main/db/models.py
- Command line
-
hf download hf://spaces/RigDataDynamics/cygnus_server/db/models.py
-
curl -L -o models.py https://huggingface.co/spaces/RigDataDynamics/cygnus_server/resolve/main/db/models.py
7.71 kB
| 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})>" | |