Move files
This commit is contained in:
parent
3cf28379e8
commit
00cc8225c5
159 changed files with 31 additions and 49 deletions
11
great_ai/views/__init__.py
Normal file
11
great_ai/views/__init__.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
from .api_metadata import ApiMetadata
|
||||
from .cache_statistics import CacheStatistics
|
||||
from .evaluation_feedback_request import EvaluationFeedbackRequest
|
||||
from .filter import Filter
|
||||
from .function_metadata import FunctionMetadata
|
||||
from .health_check_response import HealthCheckResponse
|
||||
from .model import Model
|
||||
from .operators import operators
|
||||
from .query import Query
|
||||
from .sort_by import SortBy
|
||||
from .trace import Trace
|
||||
10
great_ai/views/api_metadata.py
Normal file
10
great_ai/views/api_metadata.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
from typing import Any
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class ApiMetadata(BaseModel):
|
||||
name: str
|
||||
version: str
|
||||
documentation: str
|
||||
configuration: Any
|
||||
8
great_ai/views/cache_statistics.py
Normal file
8
great_ai/views/cache_statistics.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class CacheStatistics(BaseModel):
|
||||
hits: int
|
||||
misses: int
|
||||
size: int
|
||||
max_size: int
|
||||
7
great_ai/views/evaluation_feedback_request.py
Normal file
7
great_ai/views/evaluation_feedback_request.py
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
from typing import Any
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class EvaluationFeedbackRequest(BaseModel):
|
||||
feedback: Any
|
||||
11
great_ai/views/filter.py
Normal file
11
great_ai/views/filter.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
from typing import Union
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from .operators import Operator
|
||||
|
||||
|
||||
class Filter(BaseModel):
|
||||
property: str
|
||||
operator: Operator
|
||||
value: Union[float, str]
|
||||
9
great_ai/views/function_metadata.py
Normal file
9
great_ai/views/function_metadata.py
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
from typing import List
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class FunctionMetadata(BaseModel):
|
||||
input_parameter_names: List[str] = []
|
||||
model_parameter_names: List[str] = []
|
||||
is_finalised: bool = False
|
||||
8
great_ai/views/health_check_response.py
Normal file
8
great_ai/views/health_check_response.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
from pydantic import BaseModel
|
||||
|
||||
from .cache_statistics import CacheStatistics
|
||||
|
||||
|
||||
class HealthCheckResponse(BaseModel):
|
||||
is_healthy: bool
|
||||
cache_statistics: CacheStatistics
|
||||
6
great_ai/views/model.py
Normal file
6
great_ai/views/model.py
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class Model(BaseModel):
|
||||
key: str
|
||||
version: int
|
||||
5
great_ai/views/operators.py
Normal file
5
great_ai/views/operators.py
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
from typing import List, Literal
|
||||
|
||||
Operator = Literal[">=", "<=", "<", ">", "!=", "=", "contains"]
|
||||
|
||||
operators: List[Operator] = [">=", "<=", "<", ">", "!=", "=", "contains"]
|
||||
35
great_ai/views/query.py
Normal file
35
great_ai/views/query.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
from datetime import datetime
|
||||
from typing import List, Optional, Sequence
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from .filter import Filter
|
||||
from .sort_by import SortBy
|
||||
|
||||
|
||||
class Query(BaseModel):
|
||||
filter: List[Filter] = []
|
||||
sort: List[SortBy] = []
|
||||
conjunctive_tags: Sequence[str] = []
|
||||
since: Optional[datetime] = None
|
||||
until: Optional[datetime] = None
|
||||
has_feedback: Optional[bool] = None
|
||||
|
||||
class Config:
|
||||
schema_extra = {
|
||||
"example": {
|
||||
"filter": [
|
||||
{
|
||||
"property": "original_execution_time_ms",
|
||||
"operator": ">",
|
||||
"value": 100,
|
||||
}
|
||||
],
|
||||
"sort": [
|
||||
{"column_id": "original_execution_time_ms", "direction": "asc"},
|
||||
{"column_id": "id", "direction": "desc"},
|
||||
],
|
||||
"conjunctive_tags": ["online"],
|
||||
"has_feedback": False,
|
||||
}
|
||||
}
|
||||
8
great_ai/views/sort_by.py
Normal file
8
great_ai/views/sort_by.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
from typing import Literal
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class SortBy(BaseModel):
|
||||
column_id: str
|
||||
direction: Literal["asc", "desc"]
|
||||
89
great_ai/views/trace.py
Normal file
89
great_ai/views/trace.py
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
from pprint import pformat
|
||||
from typing import Any, Dict, Generic, List, Optional, TypeVar
|
||||
from uuid import uuid4
|
||||
|
||||
from pydantic import BaseModel, Extra, validator
|
||||
|
||||
from ..helper import HashableBaseModel
|
||||
from .model import Model
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
|
||||
class Trace(Generic[T], HashableBaseModel):
|
||||
trace_id: Optional[str]
|
||||
created: str
|
||||
original_execution_time_ms: float
|
||||
logged_values: Dict[str, Any]
|
||||
models: List[Model]
|
||||
exception: Optional[str]
|
||||
output: T
|
||||
feedback: Any = None
|
||||
tags: List[str]
|
||||
|
||||
class Config:
|
||||
extra = Extra.ignore
|
||||
|
||||
@validator("trace_id", always=True)
|
||||
def generate_id(cls, v: Optional[str], values: Dict[str, Any]) -> Optional[str]:
|
||||
if not v:
|
||||
return str(uuid4())
|
||||
return v
|
||||
|
||||
@property
|
||||
def input(self) -> Any:
|
||||
return (
|
||||
self.logged_values["input"]
|
||||
if list(self.logged_values.keys()) == ["input"]
|
||||
else self.logged_values
|
||||
)
|
||||
|
||||
@property
|
||||
def models_flat(self) -> str:
|
||||
return ", ".join(f"{m.key}:{m.version}" for m in self.models)
|
||||
|
||||
@property
|
||||
def output_flat(self) -> str:
|
||||
return pformat(self.output, indent=2, compact=True)
|
||||
|
||||
@property
|
||||
def exception_flat(self) -> str:
|
||||
return (
|
||||
"null"
|
||||
if self.exception is None
|
||||
else pformat(self.exception, indent=2, compact=True)
|
||||
)
|
||||
|
||||
@property
|
||||
def feedback_flat(self) -> str:
|
||||
return (
|
||||
"null"
|
||||
if self.feedback is None
|
||||
else pformat(self.feedback, indent=2, compact=True)
|
||||
)
|
||||
|
||||
@property
|
||||
def tags_flat(self) -> str:
|
||||
return ",\n".join(self.tags)
|
||||
|
||||
def to_flat_dict(self, include_original: bool = True) -> Dict[str, Any]:
|
||||
return {
|
||||
**(
|
||||
self.dict()
|
||||
if include_original
|
||||
else {
|
||||
"trace_id": self.trace_id,
|
||||
"created": self.created,
|
||||
"original_execution_time_ms": self.original_execution_time_ms,
|
||||
}
|
||||
),
|
||||
**{
|
||||
k: v.dict() if isinstance(v, BaseModel) else v
|
||||
for k, v in self.logged_values.items()
|
||||
},
|
||||
"models_flat": self.models_flat,
|
||||
"exception_flat": self.exception_flat,
|
||||
"output_flat": self.output_flat,
|
||||
"feedback_flat": self.feedback_flat,
|
||||
"tags_flat": self.tags_flat,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue