-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor task model and params #1066
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,23 +3,19 @@ | |
from enum import Enum | ||
from typing import Any, Dict, Iterator, List, Optional, Union | ||
|
||
from camel_converter import to_snake | ||
from camel_converter.pydantic_base import CamelBase | ||
from pydantic import ConfigDict, field_validator | ||
|
||
|
||
class IndexStats: | ||
class FieldDistribution: | ||
__dict: Dict | ||
|
||
def __init__(self, doc: Dict[str, Any]) -> None: | ||
self.__dict = doc | ||
for key, val in doc.items(): | ||
key = to_snake(key) | ||
if isinstance(val, dict): | ||
setattr(self, key, IndexStats(val)) | ||
else: | ||
setattr(self, key, val) | ||
def __init__(self, dist: Dict[str, int]) -> None: | ||
self.__dict = dist | ||
for key in dist: | ||
setattr(self, key, dist[key]) | ||
|
||
def __getattr__(self, attr: str) -> Any: | ||
def __getattr__(self, attr: str) -> str: | ||
if attr in self.__dict.keys(): | ||
return attr | ||
raise AttributeError(f"{self.__class__.__name__} object has no attribute {attr}") | ||
|
@@ -28,6 +24,22 @@ def __iter__(self) -> Iterator: | |
return iter(self.__dict__.items()) | ||
|
||
|
||
class IndexStats(CamelBase): | ||
model_config = ConfigDict(arbitrary_types_allowed=True) | ||
|
||
number_of_documents: int | ||
is_indexing: bool | ||
field_distribution: FieldDistribution | ||
|
||
@field_validator("field_distribution", mode="before") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I saw that there was an Annotated pattern and a functional pattern. The functional pattern made more sense to me, it looked more descriptive and everything was gonna stay in class anyway. |
||
@classmethod | ||
def build_field_distribution(cls, v: Any) -> FieldDistribution: | ||
if not isinstance(v, dict): | ||
raise TypeError('"field_distribution" in IndexStats must be a dict') | ||
Comment on lines
+37
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I made a test to see what happens if field_distribution was an int and without this line you get the mysterious:
versus the new
|
||
|
||
return FieldDistribution(v) | ||
|
||
|
||
class Faceting(CamelBase): | ||
max_values_per_facet: int | ||
sort_facet_values_by: Optional[Dict[str, str]] = None | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm understanding the documentation correctly, this is necessary.