ai-forever / ai-forever/langchain-gigachat

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

Open
#45 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Python
Stars
50
Forks
13
PR merge metrics
No merged PRs in 30d

Description

В продолжение issue - https://github.com/ai-forever/langchain-gigachat/issues/40

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

Из схемы, генерации подсказки по формату выполняется так (PydanticOutputParser.get_format_instructions):
```python
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)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.