Skip to content

Корректная работа format_instructions с json_schema #45

@NIK-TIGER-BILL

Description

@NIK-TIGER-BILL

В продолжение issue - #40

Сейчас при работе с json_schema при методе format_instructions, формат и описания из json_schema не берутся. Необходимо добавить функционал генерации инструкции по формату подобно pydantic модели.

Из схемы, генерации подсказки по формату выполняется так (PydanticOutputParser.get_format_instructions):

    def get_format_instructions(self) -> str:
        """Return the format instructions for the JSON output.

        Returns:
            The format instructions for the JSON output.
        """
        # Copy schema to avoid altering original Pydantic schema.
        schema = dict(self.pydantic_object.model_json_schema().items())

        # Remove extraneous fields.
        reduced_schema = schema
        if "title" in reduced_schema:
            del reduced_schema["title"]
        if "type" in reduced_schema:
            del reduced_schema["type"]
        # Ensure json in context is well-formed with double quotes.
        schema_str = json.dumps(reduced_schema, ensure_ascii=False)

        return _PYDANTIC_FORMAT_INSTRUCTIONS.format(schema=schema_str)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions