-
Notifications
You must be signed in to change notification settings - Fork 35
feat: bump jsonschema-pydantic-converter to 0.4.1, add datamodel-code-generator backend #1055
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
Open
vldcmp-uipath
wants to merge
1
commit into
main
Choose a base branch
from
claude/pc-4965-schema-codegen-backend
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/uipath_langchain/agent/react/_datamodel_code_generator_base.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| """Base model for every runtime-generated schema class. | ||
|
|
||
| `datamodel-code-generator` emits classes deriving from a configurable base. Every | ||
| model generated from a tool or agent schema derives from | ||
| :class:`UiPathDatamodelCodeGeneratorBaseModel`, which supplies the two | ||
| configuration options the runtime depends on: | ||
|
|
||
| * ``serialize_by_alias`` -- properties whose JSON names are not valid Python | ||
| identifiers are generated as sanitized fields carrying an alias. Serializing by | ||
| alias is what puts the original JSON names back on the wire, so a tool call | ||
| reaches Integration Service with the property names its schema declared. | ||
| * ``extra="allow"`` -- the default for a schema that does not say otherwise. A | ||
| schema with ``additionalProperties: false`` generates its own | ||
| ``model_config``, and Pydantic merges that over this one, so ``extra`` still | ||
| ends up ``"forbid"`` there. | ||
|
|
||
| The base also makes a declared JSON property name usable as an attribute, which | ||
| is the half of that contract sanitizing the field name would otherwise break. | ||
| See :meth:`UiPathDatamodelCodeGeneratorBaseModel.__getattr__`. | ||
| """ | ||
|
|
||
| from typing import Any | ||
|
|
||
| from pydantic import BaseModel, ConfigDict | ||
|
|
||
|
|
||
| class UiPathDatamodelCodeGeneratorBaseModel(BaseModel): | ||
| """Base class for models generated from JSON Schema at runtime.""" | ||
|
|
||
| model_config = ConfigDict(serialize_by_alias=True, extra="allow") | ||
|
vldcmp-uipath marked this conversation as resolved.
|
||
|
|
||
| def __getattr__(self, name: str) -> Any: | ||
| """Resolve a declared JSON property name to its sanitized field. | ||
|
|
||
| Serializing by alias makes ``model_dump()`` alias-keyed, and consumers read | ||
| the dumped keys straight back off the instance: LangChain's | ||
| ``BaseTool._parse_input`` builds its kwargs with ``getattr(result, key)`` | ||
| for every dumped key. Under the legacy backend the JSON name *was* the | ||
| field name, so that resolved; here the field is sanitized, so a property | ||
| declared ``Content-Type`` would raise ``AttributeError`` mid-tool-call. | ||
|
|
||
| Accepting the alias restores what callers already relied on -- the name the | ||
| schema declared works as an attribute -- so alias-unaware consumers behave | ||
| as they did before. | ||
|
|
||
| Only reached when normal lookup fails, so real fields, methods and extras | ||
| are untouched. | ||
| """ | ||
| try: | ||
| return super().__getattr__(name) # type: ignore[misc] | ||
| except AttributeError: | ||
| pass | ||
|
|
||
| for field_name, field in type(self).model_fields.items(): | ||
| if field.alias == name and field_name != name: | ||
| return getattr(self, field_name) | ||
|
|
||
| raise AttributeError( | ||
| f"{type(self).__name__!r} object has no attribute {name!r}" | ||
| ) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.