ai-forever / ai-forever/langchain-gigachat
Корректная работа format_instructions с json_schema
- 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
Assessment
This issue has not been assessed yet.