I don't know if this is of interest. But I have created a valid Response Format object for the OpenAI API client, that (almost) ensures that the generated edges can be parsed afterwards.
Simply put, it limits the LLMs generation possibilities to valid JSON. Obviously we might loose a little freedom in the edge/node content, but I haven't noticed so far.
I will leave it here for others to use, or to be implemented in the library itself.
RESPONSE_FORMAT = {
"type": "json_schema",
"json_schema": {
"name": "test_schema",
"strict": True,
"schema": {
"items": {
"properties": {
"node_1": {
"title": "Node 1",
"type": "object",
"properties": {
"label": {"title": "Label", "type": "string"},
"name": {"title": "Name", "type": "string"},
},
"required": ["label", "name"],
"additionalProperties": False,
},
"node_2": {
"title": "Node 2",
"type": "object",
"properties": {
"label": {"title": "Label", "type": "string"},
"name": {"title": "Name", "type": "string"},
},
"required": ["label", "name"],
"additionalProperties": False,
},
"relationship": {
"title": "Relationship",
"type": "string",
},
},
"required": ["node_1", "node_2", "relationship"],
"title": "TribeType",
"type": "object",
"additionalProperties": False,
},
"title": "Edges",
"type": "array",
"minItems": 1,
},
},
}
I don't know if this is of interest. But I have created a valid Response Format object for the OpenAI API client, that (almost) ensures that the generated edges can be parsed afterwards.
Simply put, it limits the LLMs generation possibilities to valid JSON. Obviously we might loose a little freedom in the edge/node content, but I haven't noticed so far.
I will leave it here for others to use, or to be implemented in the library itself.