Skip to content

feat: Re-use core models in SDK #104

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

csurfer
Copy link
Contributor

@csurfer csurfer commented Apr 15, 2025

Summary

Proposed solution and thought process documentation : Link

Copy link

codecov bot commented Apr 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 75.94%. Comparing base (5814c90) to head (ca8deb7).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #104      +/-   ##
==========================================
- Coverage   75.95%   75.94%   -0.01%     
==========================================
  Files          32       32              
  Lines        2429     2428       -1     
==========================================
- Hits         1845     1844       -1     
  Misses        584      584              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment on lines +76 to +98
for f in class_files:
mod_path = str(f.with_suffix("")).removeprefix(str(root.parent))
mod = get_module(mod_path)
if mod.startswith("galileo_core.testing"):
continue
module = importlib.import_module(mod)

print(">>", mod)
for item in dir(module):
ic = getattr(module, item)
if not item.startswith("__") and inspect.isclass(ic) and ic.__module__.startswith("galileo"):
print(" >>", item, camel_to_snake(item))
with open(f"{MODEL_LOCATION_PREFIX}/{camel_to_snake(item)}.py", "w") as f:
f.write(basemodel_dict_template.render({"unified_file_name": unified_file_name, "item": item}))
mod_import_list.append((mod, item))
elif (
not item.startswith("__")
and "__class__" in dir(ic)
and ic.__class__ == typing._AnnotatedAlias
and item not in {"UUID4"}
):
mod_other_list.append((mod, item))
print()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Core module iteration + class creation + linkage

Comment on lines +2071 to +2098
if issubclass(GalileoCoreMessageClass, BaseModel):

class Message(GalileoCoreMessageClass):
def to_dict(self) -> dict[str, Any]:
return self.model_dump(exclude_none=True)

@classmethod
def from_dict(cls, src_dict: dict[str, Any]) -> "Message":
return cls.model_validate(src_dict)

Message.model_rebuild()
else:
Message = GalileoCoreMessageClass


if issubclass(GalileoCoreMessageRoleClass, BaseModel):

class MessageRole(GalileoCoreMessageRoleClass):
def to_dict(self) -> dict[str, Any]:
return self.model_dump(exclude_none=True)

@classmethod
def from_dict(cls, src_dict: dict[str, Any]) -> "MessageRole":
return cls.model_validate(src_dict)

MessageRole.model_rebuild()
else:
MessageRole = GalileoCoreMessageRoleClass
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generated class wrappers with model rebuilds.

return str(self.value)
# flake: noqa: F401
# ruff: noqa: F401
from ..models.all_galileo_core_models import MessageRole
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Link individual model file to import the right definition from all model file to ensure generated clients can still use these models.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant