Enumerate candidate spans before asking which one belongs to the target field.
Input and workflow
Resolve the returned ID against the exact candidate map. This preserves punctuation, capitalization and original offsets.
Request
{
"model": "ngila-judge",
"state": {
"note": "Send invoices to [email protected]. For delivery contact [email protected].",
"candidates": {
"a": "[email protected]",
"b": "[email protected]"
}
},
"questions": {
"address": {
"type": "choice",
"instructions": "Which candidate receives invoices?",
"criteria": {
"a": "",
"b": "",
"neither": ""
}
}
}
}Run locally
Save ngila.py alongside your script and set NGILA_API_KEY. Save any linked input images in the same directory.
import json
from ngila import NgilaClient
state = {'note': 'Send invoices to [email protected]. For delivery contact '
'[email protected].',
'candidates': {'a': '[email protected]', 'b': '[email protected]'}}
questions = {'address': {'type': 'choice',
'instructions': 'Which candidate receives invoices?',
'criteria': {'a': '', 'b': '', 'neither': ''}}}
response = NgilaClient().system_one(state, questions)
a = response["answers"]
print(json.dumps(a, indent=2, ensure_ascii=False))Use the answers
The following application fragment uses a = response["answers"]. Supply any thresholds, lookup tables, or previous results from your workflow before applying it.
key = a["address"]["choice"]
address = state["candidates"].get(key)