Skip to content

Conversation

@KoeppelSoftwareEngineer
Copy link
Collaborator

No description provided.

Copy link
Member

@JosePizarro3 JosePizarro3 left a comment

Choose a reason for hiding this comment

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

Some work to do

Copy link
Member

@JosePizarro3 JosePizarro3 left a comment

Choose a reason for hiding this comment

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

A few more comments, more importantly, the implementation in jflat.py needs some changes

Copy link
Member

Choose a reason for hiding this comment

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

why do we need an AI generated json?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, DISCUSSION:
I was wondering, if the flatten Output is good.
Copilote generated a json schema, maybe there is room for improvement?



class Person(BaseModel):
name: str = Field(..., description="The person's name")
Copy link
Member

Choose a reason for hiding this comment

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

Maybe you can define more types in this example? Something like str | none, and create more different Fields (so the printed JSON schema is actually richer and we can cover more cases)

from typing import Any, Dict


def flatten_json(data: Dict[str, Any], parent_key: str = "") -> Dict[str, Any]:
Copy link
Member

Choose a reason for hiding this comment

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

The goal of this function is more to map a JSON Schema (as printed by pydantic) to our new flattened version. The end result should look something like:

{
    "$defs": {       
        "Method": {
            "properties": {
                "author": {
                   "description": "The author of the method",
                   "type": "string"
                },
                "method_name": {
                   "description": "The name of the method",
                   "type": "string"
                },
                "person": {
                   "$ref": "#/$defs/Person"
                }
            },
            "description": "...<whatever-here>...",
            "$inherits_from": "#/$defs/BaseMethod",
        },       
        <other classes here>
}}

As you can see, I slightly modified the resulting JSON schema when printed using model_json_schema. The idea is to get rid off unnecessary stuff and adding some other info. I:

  • Deleted title in each property
  • Deleted title in each object
  • Added an $inherits_from key in each of the objects dictionaries
  • Moved the Method defs inside $defs (before, it is outside because we are printing from it)
  • We need to add BaseMethod to define inheritances
  • Deleted all the required and type:object stuff

We could also:

  • Add a key inside each property defining if they are mandatory or optional (this was before defined by required. Somethind like:
        "author": {
            "description": "The author of the method",
            "type": "string",
            "mandatory": true   # this can also be false, if the property is optional (i.e., str | None)
        },

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.

4 participants