Skip to content
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

Adds modular SERDE approach #175

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Adds modular SERDE approach #175

wants to merge 2 commits into from

Conversation

skrawcz
Copy link
Contributor

@skrawcz skrawcz commented May 11, 2024

This PR introduces a modular SERDE approach.

  1. Singledispatch to register type serializers.
  2. Any complex object deserialization, needs to be accompanied with a "type field" that will map to the name
    of a "string dispatcher function". i.e. like single dispatch, but you register a string value for it. This approach
    means that most people will get around the need for field level deserialization / having to tell Burr about state types explicitly.

TODOs:

  • decide on module structure and where it should live
  • wire changes through to tracker serialization
  • wire changes through to persister serialization
  • wire changes through to UI reading local tracker logs
  • update LC examples
  • write tests

Changes

How I tested this

Notes

Checklist

  • PR has an informative and human-readable title (this will be pulled into the release notes)
  • Changes are limited to a single goal (no scope creep)
  • Code passed the pre-commit check & code is left cleaner/nicer than when first encountered.
  • Any change in functionality is tested
  • New functions are documented (with a description, list of inputs, and expected output)
  • Placeholder code is flagged / future TODOs are captured in comments
  • Project documentation has been updated if adding/changing functionality.

LC documents can now be serialized properly.
Note: LC produces things that can look like documents
that aren't. E.g. _DocumentWithState

Should add tests here eventually.
skrawcz added a commit to skrawcz/Scrapegraph-ai that referenced this pull request May 11, 2024
skrawcz added a commit to skrawcz/Scrapegraph-ai that referenced this pull request May 11, 2024
@@ -20,9 +20,13 @@

try:
Copy link
Contributor

Choose a reason for hiding this comment

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

So, we'll want to put this in a plugin and have a registry. Specifically for default serializers. But this OK as a temporary fix -- the "common" models aren't throw-away code, so let's do the following:

  1. Comment on TODO
  2. Open an issue on ser/deser (if we don't have one already) + plugins and document this out
  3. Link to that issue

I know we already have one in this, but having anything referring lanchain in the core code feels icky, even though its in a guarded setting.

if isinstance(d, list):
return [_serialize_object(x) for x in d]
elif isinstance(d, dict):
return {k: _serialize_object(v) for k, v in d.items()}
elif lc_messages is not None and isinstance(d, lc_messages.BaseMessage):
return lc_messages.message_to_dict(d)
elif lc_documents is not None and isinstance(d, lc_documents.Document):
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto with the above. Blech custom serde is ugly...

Singledispatch for type serialization. For non-primitive types, make them return a dict with a serde key.

Then use a string value based mechanism to deserialize. This way we can be "field agnostic" during deserialization.

Otherwise deserialization without knowing what it is, is a challenge.
Thus the idea to include a key in a dict for it.

Otherwise the only other way for deserialization is to field
registries...

TODO:
- determine module naming and location
- actually wire in
- proper tests
- how to override these
- think about any other edge/error cases
@skrawcz skrawcz changed the title Adds support for lc documents & similar Adds modular SERDE approach May 13, 2024
@skrawcz skrawcz marked this pull request as draft May 13, 2024 05:56
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.

None yet

2 participants