Объяснение
В настоящее время я работаю над игровым проектом, используя openapi и python. Один из вызовов функций, которые я написал, приведен ниже.
getCaseFile
{
"name": "getCaseFile",
"description": "Generate a hard to solve, self-contained detective game scenario including a brief introduction, setting, key characters, and initial evidence or clues. The scenario should be structured to allow for interactive investigation through text commands such as 'Inspect the area', 'Talk to [character name]', or 'Examine [object]'. Ask user whats their next move but don't display choices of what to do. Provide a clear mystery or objective for the player to solve, ensuring the narrative includes enough detail for engaging gameplay without prior knowledge of this conversation. Avoid making your message seem like a ",
"parameters": {
"type": "object",
"required": ["case_name", "intro", "setting", "key_characters", "initial_clues", "solution", "objective"],
"properties": {
"case_name": {
"type": "string",
"description": "The name of the case file. Eg: The Vanishing Vintner"
},
"intro": {
"type": "string",
"description": "A brief introduction to the story. Eg: As a seasoned detective, you were just briefed on a new case by your partner, who looked specifically concerned about this one. 'It's baffling,' they said, handing over a file. 'An esteemed winemaker, Paulo Rossetti, vanished without a trace from his locked winery. Here's the kicker: no one was seen entering or leaving the place around the time he disappeared. We need your expertise.' You open the dossier and begin unraveling the case details."
},
"setting": {
"type": "string",
"description": "A brief explanation of the setting. Eg: The case is set at the Rossetti Vineyard, a sprawling estate known for its exquisite wines and its owner's exceptional taste. The majestic villa and adjacent winery are surrounded by acres of grapevines. Paulo Rossetti was last seen in his private study inside the winery, a room known to have one solid locked door and no windows."
},
"key_characters": {
"type": "array",
"description": "A list of suspects with their name, maybe title or position, and their relationship to the crime",
"items": {
"type": "string"
}
},
"initial_clues": {
"type": "array",
"description": "A list of initial clues. Eg: A vintage bottle of wine, with its seal intact, was left on Paulo's desk.",
"items": {
"type": "string"
}
},
"solution": {
"type": "object",
"additionalProperties": {
"type": "object",
"required" : ["culprit", "motive", "key_evidence"],
"properties": {
"culprit": {
"type": "string",
"description": "Name and last name of the culprit."
},
"motive" : {
"type": "string",
"description": "Motive of the culprit."
},
"key_evidence": {
"type": "string",
"description": "The key evidence for the crime commited by the culprit."
}
}
}
},
"objective": {
"type": "string",
"description": "A simple objective to let player know that its time to act. Eg: Determine who is responsible for Paulo Rossetti's disappearance and uncover the motive behind their actions."
}
}
}
}
Как видите, эта функция принимает 7 параметров, один из которых — solution — словарь, внутри которого находятся 3 ключа.
Когда я использую эту функцию при вызове OpenApi Playground, она не предоставляет мне solution.
Пример приведен ниже:
getCaseFile(
{
"case_name": "The Mysterious Machinations at Merriweather Mansion",
"intro": "Just as you settle into your office with a steamy cup of coffee, your partner slides a bulky folder across the desk toward you. 'Here's something that will put that caffeine to good use,' they quip. The file contains details about the passing of a reclusive millionaire, Bernard Blackwood, found motionless at his estate. 'Bernard was a hermit, hardly seen outside his study. The doors were locked from the inside. No signs of forced entry, no obvious cause of death. This case is a real head-scratcher.'",
"setting": "The sprawling and enigmatic Merriweather Mansion, a remote abode located just outside the sleepy town of Galeshire. The mansion is known for its eccentric design and assortment of automatons and contraptions. Bernard was discovered in his personal study, a place brimming with oddities and inventions.",
"key_characters": [
"Bernard Blackwood - The deceased millionaire and inventor.",
"Cecil Hawthorne - The estate's caretaker and Bernard's old friend.",
"Agatha Christie - The suspiciously named and ambitious niece.",
"Dr. Edward Bellamy - The family doctor last to visit Bernard.",
"Sofia Marlowe - The reclusive author living as a guest on the property."
],
"initial_clues": [
"An unusual mechanical device on Bernard's desk, unfinished and whirring silently.",
"A will, freshly revised, with significant changes to beneficiaries.",
"A torn piece of fabric caught on a bramble outside a study window that doesn't quite close.",
"Bernard's journal, open to a page expressing his growing paranoia over someone betraying him."
],
"objective": "Unravel the cause of Bernard's death, decipher who could have engineered such an elaborate act, and determine their motive."
}
)
В чем причина такого явления и как это исправить?






Я не могу объяснить, почему в инструменте отсутствует свойство solution, но схема выглядит неправильно.
В вашем понимании это объект, который может принимать любое количество свойств с любым именем, причем каждое значение само по себе должно быть объектом со свойствами culprit, motive и key_evidence. Судя по вашему описанию, это звучит слишком глубоко вложенным уровнем.
Я предлагаю решить эту проблему — извлечь внутреннюю схему и выбросить внешнюю (с помощью type и additionalProperties).
Я решил свою проблему после долгих часов поиска в Интернете.
Очевидно, ключевое слово additionalProperties используется для управления обработкой дополнительных элементов, то есть свойств, имена которых не указаны в ключевом слове properties или не соответствуют ни одному из регулярных выражений в ключевом слове patternProperties.
Правильное использование было:
...
"solution": {
"type": "object",
"properties": {
"culprit": {
"type": "string",
"description": "Name and last name of the culprit."
},
"motive" : {
"type": "string",
"description": "Motive of the culprit."
},
"key_evidence": {
"type": "string",
"description": "The key evidence for the crime commited by the culprit."
}
}
}
...
Вместо additionalProperties я использовал properties, что позволило мне иметь свойства, имена которых указаны в схеме.
Это буквально тот же ответ, который я дал. Почему бы просто не принять мой ответ?
@gregsdennis, ну, тебе не хватило той части, где ты опубликовал реальный ответ, чтобы показать решение, и просто дал мне краткое представление. Без практических знаний JSON Schema это совсем не помогло. Также у вас не должно быть повода отрицать мой ответ.
спасибо за идею, но я решил вопрос, как писал здесь.