ai-forever / ai-forever/langchain-gigachat

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

Aperta
#45 0 commenti 1 reazione 0 assegnatari Vedi su GitHub
Lingua principale
Python
Stelle
50
Fork
13
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

В продолжение 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)
```

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.