I am trying to get output in JSON using functions, using GPT 3.5
I have defined a multilevel function.
The JSON output returned by the functions have unnecessary whitespaces, which I assume is to indent the json. Now these white spaces are counted as a token. Creating unnecessary bill and reducing available context size.
Is there a way to force function to return a minified json?
The output from API. Here in the arguments you will see a lot of whitespaces
[
{
"index": 0,
"message": {
"role": "assistant",
"content": null,
"function_call": {
"name": "print_grammatical_error",
"arguments": "{\n \"gramatical_errors\": [\n {\n \"errorLocation\": {\n \"start\": 0,\n \"end\": 7\n },\n \"mistakeText\": \"Although some\",\n \"mistakeReason\": \"Missing comma after introductory phrase\",\n \"mistakeCorrection\": \"Although, some\"\n },\n {\n \"errorLocation\": {\n \"start\": 9,\n \"end\": 17\n },\n \"mistakeText\": \"indivuduals\",\n \"mistakeReason\": \"Spelling mistake\",\n \"mistakeCorrection\": \"individuals\"\n },\n {\n \"errorLocation\": {\n \"start\": 19,\n \"end\": 27\n },\n \"mistakeText\": \"shoud\",\n \"mistakeReason\": \"Spelling mistake\",\n \"mistakeCorrection\": \"should\"\n },\n {\n \"errorLocation\": {\n \"start\": 29,\n \"end\": 38\n },\n \"mistakeText\": \"recieve\",\n \"mistakeReason\": \"Spelling mistake\",\n \"mistakeCorrection\": \"receive\"\n },\n {\n \"errorLocation\": {\n \"start\": 40,\n \"end\": 46\n },\n \"mistakeText\": \"\\\"abuse anymore\\\"\",\n \"mistakeReason\": \"\\\"Anymore\\\" should be placed before \\\"abuse\\\"\",\n \"mistakeCorrection\": \"\\\"anymore abuse\\\"\"\n },\n {\n \"errorLocation\": {\n \"start\": 56,\n \"end\": 62\n },\n \"mistakeText\": \"\\\"agreeded\\\"\",\n \"mistakeReason\": \"\\\"Agreeded\\\" should be \\\"agreed\\\"\",\n \"mistakeCorrection\": \"\\\"agreed\\\"\"\n },\n {\n \"errorLocation\": {\n \"start\": 64,\n \"end\": 72\n },\n \"mistakeText\": \"recente\",\n \"mistakeReason\": \"Spelling mistake\",\n \"mistakeCorrection\": \"recent\"\n },\n {\n \"errorLocation\": {\n \"start\": 74,\n \"end\": 82\n },\n \"mistakeText\": \"\\\"similars emotions\\\"\",\n \"mistakeReason\": \"\\\"Similars\\\" should be \\\"similar\\\"\",\n \"mistakeCorrection\": \"\\\"similar emotions\\\"\"\n },\n {\n \"errorLocation\": {\n \"start\": 84,\n \"end\": 91\n },\n \"mistakeText\": \"\\\"anymore to use animals\\\"\",\n \"mistakeReason\": \"\\\"Anymore\\\" should be placed before \\\"to use animals\\\"\",\n \"mistakeCorrection\": \"\\\"to use animals anymore\\\"\"\n },\n {\n \"errorLocation\": {\n \"start\": 128,\n \"end\": 137\n },\n \"mistakeText\": \"\\\"recognize worldwide\\\"\",\n \"mistakeReason\": \"\\\"Recognize\\\" should be \\\"recognized\\\"\",\n \"mistakeCorrection\": \"\\\"recognized worldwide\\\"\"\n }\n ]\n}"
}
},
"finish_reason": "stop"
}
]```