A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 16, 09:30 UTC
[Model] tool calling support for ibm-granite/granite-20b-functioncalling (#8339)
Signed-off-by: Max de Bayser <mbayser@br.ibm.com> Co-authored-by: Max de Bayser <mbayser@br.ibm.com> Co-authored-by: Maximilien de Bayser <maxdebayser@gmail.com>
Will Eaton committed
Oct 29, 2024 at 18:07 UTC
882a1ad0deb9fd26283db611e78e122ac19fb72f
7 files changed
+456
-28
docs/source/serving/openai_compatible_server.md
+20
-1
@@ -185,7 +185,9 @@ from HuggingFace; and you can find an example of this in a `tokenizer_config.jso
185
186
If your favorite tool-calling model is not supported, please feel free to contribute a parser & tool use chat template!
187
188
+
189
#### Hermes Models (`hermes`)
190
+
191
All Nous Research Hermes-series models newer than Hermes 2 Pro should be supported.
192
* `NousResearch/Hermes-2-Pro-*`
193
* `NousResearch/Hermes-2-Theta-*`
@@ -197,7 +199,9 @@ step in their creation_.
199
200
Flags: `--tool-call-parser hermes`
201
202
+
203
#### Mistral Models (`mistral`)
204
+
205
Supported models:
206
* `mistralai/Mistral-7B-Instruct-v0.3` (confirmed)
207
* Additional mistral function-calling models are compatible as well.
@@ -216,7 +220,9 @@ when tools are provided, that results in much better reliability when working wi
220
221
Recommended flags: `--tool-call-parser mistral --chat-template examples/tool_chat_template_mistral_parallel.jinja`
222
223
+
224
#### Llama Models (`llama3_json`)
225
+
226
Supported models:
227
* `meta-llama/Meta-Llama-3.1-8B-Instruct`
228
* `meta-llama/Meta-Llama-3.1-70B-Instruct`
@@ -236,7 +242,9 @@ it works better with vLLM.
242
243
Recommended flags: `--tool-call-parser llama3_json --chat-template examples/tool_chat_template_llama3_json.jinja`
244
245
+
246
#### InternLM Models (`internlm`)
247
+
248
Supported models:
249
* `internlm/internlm2_5-7b-chat` (confirmed)
250
* Additional internlm2.5 function-calling models are compatible as well
@@ -246,6 +254,7 @@ Known issues:
254
255
Recommended flags: `--tool-call-parser internlm --chat-template examples/tool_chat_template_internlm2_tool.jinja`
256
257
+
258
#### Jamba Models (`jamba`)
259
AI21's Jamba-1.5 models are supported.
260
* `ai21labs/AI21-Jamba-1.5-Mini`
@@ -255,6 +264,16 @@ AI21's Jamba-1.5 models are supported.
264
Flags: `--tool-call-parser jamba`
265
266
267
+#### IBM Granite (`granite-20b-fc`)
268
+
269
+Supported models:
270
+* `ibm-granite/granite-20b-functioncalling`
271
+
272
+Flags: `--tool-call-parser granite-20b-fc --chat-template examples/tool_chat_template_granite_20b_fc.jinja`
273
+
274
+The example chat template deviates slightly from the original on Huggingface, which is not vLLM compatible. It blends function description elements from the Hermes template and follows the same system prompt as "Response Generation" mode from [the paper](https://arxiv.org/abs/2407.00121). Parallel function calls are supported.
275
+
276
+
277
### How to write a tool parser plugin
278
279
A tool parser plugin is a Python file containing one or more ToolParser implementations. You can write a ToolParser similar to the `Hermes2ProToolParser` in vllm/entrypoints/openai/tool_parsers/hermes_tool_parser.py.
@@ -312,5 +331,5 @@ Then you can use this plugin in the command line like this.
331
--tool-parser-plugin <absolute path of the plugin file>
332
--tool-call-parser example \
333
--chat-template <your chat template> \
315
-```
334
+```
335
examples/tool_chat_template_granite_20b_fc.jinja
new
+130
@@ -0,0 +1,130 @@
1
+{%- macro json_to_python_type(json_spec) %}
2
+ {%- set basic_type_map = {
3
+ "string": "str",
4
+ "number": "float",
5
+ "integer": "int",
6
+ "boolean": "bool"
7
+} %}
8
+
9
+ {%- if basic_type_map[json_spec.type] is defined %}
10
+ {{- basic_type_map[json_spec.type] }}
11
+ {%- elif json_spec.type == "array" %}
12
+ {{- "list[" + json_to_python_type(json_spec|items) + "]" }}
13
+ {%- elif json_spec.type == "object" %}
14
+ {%- if json_spec.additionalProperties is defined %}
15
+ {{- "dict[str, " + json_to_python_type(json_spec.additionalProperties) + ']' }}
16
+ {%- else %}
17
+ {{- "dict" }}
18
+ {%- endif %}
19
+ {%- elif json_spec.type is iterable %}
20
+ {{- "Union[" }}
21
+ {%- for t in json_spec.type %}
22
+ {{- json_to_python_type({"type": t}) }}
23
+ {%- if not loop.last %}
24
+ {{- "," }}
25
+ {%- endif %}
26
+ {%- endfor %}
27
+ {{- "]" }}
28
+ {%- else %}
29
+ {{- "Any" }}
30
+ {%- endif %}
31
+{%- endmacro %}
32
+
33
+{%- if not full_function_description is defined %}
34
+ {%- set full_function_description = false %}
35
+{%- endif %}
36
+
37
+{%- macro full_description(tool) %}
38
+ {{- tool.name + '(' }}
39
+ {%- if tool.parameters is defined %}
40
+ {%- for param_name, param_fields in tool.parameters.properties|items %}
41
+ {{- param_name + ": " + json_to_python_type(param_fields) }}
42
+ {%- if not loop.last %}
43
+ {{- ", " }}
44
+ {%- endif %}
45
+ {%- endfor %}
46
+ {%- endif %}
47
+ {{- ")" }}
48
+ {%- if tool.return is defined %}
49
+ {{- " -> " + json_to_python_type(tool.return) }}
50
+ {%- endif %}
51
+ {{- " - " + tool.description + "\n\n" }}
52
+ {%- if tool.parameters is defined %}
53
+ {%- for param_name, param_fields in tool.parameters.properties|items %}
54
+ {%- if loop.first %}
55
+ {{- " Args:\n" }}
56
+ {%- endif %}
57
+ {{- " " + param_name + "(" + json_to_python_type(param_fields) + "): " + param_fields.description|trim }}
58
+ {%- endfor %}
59
+ {%- endif %}
60
+ {%- if tool.return is defined and tool.return.description is defined %}
61
+ {{- "\n Returns:\n " + tool.return.description }}
62
+ {%- endif %}
63
+ {{- '"' }}
64
+{%- endmacro %}
65
+
66
+{%- macro simple_description(tool) %}
67
+ {{- tool.description }}
68
+{%- endmacro %}
69
+
70
+{%- macro function_description(tool) %}
71
+ {%- if full_function_description %}
72
+ {{- full_description(tool) }}
73
+ {%- else %}
74
+ {{- simple_description(tool) }}
75
+ {%- endif %}
76
+{%- endmacro %}
77
+
78
+{%- if messages[0]["role"] == "system" %}
79
+ {%- set sys_prompt = messages[0]["content"] %}
80
+ {%- set loop_messages = messages[1:] %}
81
+{%- else %}
82
+ {%- set loop_messages = messages %}
83
+ {% set sys_prompt = 'You are a helpful assistant with access to the following function calls. Your task is to understand the given conversation with function calls and responses and generate natural language response as the ASSISTANT to continue the conversation. You may use the following function calls to understand how to respond to the user query.' %}
84
+{%- endif %}
85
+
86
+{{ 'SYSTEM: ' + sys_prompt }}
87
+{% if tools is iterable and tools | length > 0 %}
88
+<|function_call_library|>
89
+ {%- for tool in tools %}
90
+ {%- if tool.function is defined %}
91
+ {%- set tool = tool.function %}
92
+ {%- endif %}
93
+ {{- '{"name": "' + tool.name + '", ' }}
94
+ {{- '"description": "' + function_description(tool) }}
95
+ {{- ', "parameters": ' }}
96
+ {%- if not tool.parameters is defined or tool.parameters.properties | length == 0 %}
97
+ {{- "{}" }}
98
+ {%- else %}
99
+ {{- tool.parameters|tojson }}
100
+ {%- endif %}
101
+ {{- "}" }}
102
+ {%- if not loop.last %}
103
+ {{- "\n" }}
104
+ {%- endif %}
105
+ {%- endfor %}
106
+If none of the functions are relevant or the given question lacks the parameters required by the function, please output \"<function_call> {\"name\": \"no_function\", \"arguments\": {}}\".
107
+{%- endif %}
108
+
109
+
110
+
111
+{% for message in messages %}
112
+ {% if message['role'] == 'user' %}
113
+ {{- '\nUSER: ' + message['content'] }}
114
+ {% elif message['role'] == 'assistant' and message.tool_calls is defined %}
115
+ {{- '\nASSISTANT:' }}
116
+ {% for tc in message.tool_calls %}
117
+ {{- '<function_call> ' + {'name': tc.function.name, 'arguments': tc.function.arguments}|tojson }}
118
+ {% endfor %}
119
+ {{- '<|endoftext|>' }}
120
+ {% elif message['role'] == 'assistant' %}
121
+ {{- '\nASSISTANT: ' + message['content'] + ' <|endoftext|>' }}
122
+ {% elif message['role'] == 'tool' %}
123
+ {{- '<function_response> ' + message['content'] }}
124
+ {%- else %}
125
+ {{- raise_exception("Unexpected combination of role and message content") }}
126
+ {% endif %}
127
+ {% if loop.last and add_generation_prompt %}
128
+ {{- '\nASSISTANT: ' }}
129
+ {% endif %}
130
+{% endfor %}
tests/tool_use/utils.py
+12
@@ -88,6 +88,18 @@ CONFIGS: Dict[str, ServerConfig] = {
88
"without calling a tool. DO NOT CALL A TOOL THAT IS IRRELEVANT "
89
"to the user's question - just respond to it normally."
90
},
91
+ ## FIXME: temporary disabled due to lack of hardware specification
92
+ ## for individual runs
93
+ #"granite20b": {
94
+ # "model":
95
+ # "ibm-granite/granite-20b-functioncalling",
96
+ # "arguments": [
97
+ # "--tool-call-parser", "granite-20b-fc", "--chat-template",
98
+ # str(VLLM_PATH / "examples/tool_chat_template_granite_20b_fc.jinja")
99
+ # ],
100
+ # "supports_parallel":
101
+ # False,
102
+ #},
103
"internlm": {
104
"model":
105
"internlm/internlm2_5-7b-chat",
vllm/entrypoints/openai/tool_parsers/__init__.py
+4
-3
@@ -1,4 +1,5 @@
1
from .abstract_tool_parser import ToolParser, ToolParserManager
2
+from .granite_20b_fc_tool_parser import Granite20bFCToolParser
3
from .hermes_tool_parser import Hermes2ProToolParser
4
from .internlm2_tool_parser import Internlm2ToolParser
5
from .jamba_tool_parser import JambaToolParser
@@ -6,7 +7,7 @@ from .llama_tool_parser import Llama3JsonToolParser
7
from .mistral_tool_parser import MistralToolParser
8
9
__all__ = [
9
- "ToolParser", "ToolParserManager", "Hermes2ProToolParser",
10
- "MistralToolParser", "Internlm2ToolParser", "Llama3JsonToolParser",
11
- "JambaToolParser"
10
+ "ToolParser", "ToolParserManager", "Granite20bFCToolParser",
11
+ "Hermes2ProToolParser", "MistralToolParser", "Internlm2ToolParser",
12
+ "Llama3JsonToolParser", "JambaToolParser"
13
]
vllm/entrypoints/openai/tool_parsers/granite_20b_fc_tool_parser.py
new
+251
@@ -0,0 +1,251 @@
1
+import json
2
+import re
3
+from json import JSONDecoder
4
+from typing import Dict, Sequence, Union
5
+
6
+import partial_json_parser
7
+from partial_json_parser.core.options import Allow
8
+
9
+from vllm.entrypoints.openai.protocol import (ChatCompletionRequest,
10
+ DeltaFunctionCall, DeltaMessage,
11
+ DeltaToolCall,
12
+ ExtractedToolCallInformation,
13
+ FunctionCall, ToolCall)
14
+from vllm.entrypoints.openai.tool_parsers.abstract_tool_parser import (
15
+ ToolParser, ToolParserManager)
16
+from vllm.entrypoints.openai.tool_parsers.utils import (consume_space,
17
+ find_common_prefix,
18
+ is_complete_json,
19
+ partial_json_loads)
20
+from vllm.logger import init_logger
21
+from vllm.transformers_utils.tokenizer import AnyTokenizer
22
+from vllm.utils import random_uuid
23
+
24
+logger = init_logger(__name__)
25
+
26
+
27
+@ToolParserManager.register_module("granite-20b-fc")
28
+class Granite20bFCToolParser(ToolParser):
29
+ """
30
+ Tool call parser for the granite-20b-functioncalling model intended
31
+ for use with the examples/tool_chat_template_granite20b_fc.jinja
32
+ template.
33
+
34
+ Used when --enable-auto-tool-choice --tool-call-parser granite-20-fc
35
+ are all set
36
+ """
37
+
38
+ def __init__(self, tokenizer: AnyTokenizer):
39
+ super().__init__(tokenizer)
40
+
41
+ self.bot_token = "<function_call>"
42
+ self.tool_start_token = self.bot_token
43
+ self.tool_call_regex = re.compile(r"<function_call>\s*")
44
+
45
+ def extract_tool_calls(
46
+ self, model_output: str,
47
+ request: ChatCompletionRequest) -> ExtractedToolCallInformation:
48
+ if self.tool_start_token not in model_output:
49
+ return ExtractedToolCallInformation(tools_called=False,
50
+ tool_calls=[],
51
+ content=model_output)
52
+
53
+ dec = JSONDecoder()
54
+ try:
55
+ matches = list(self.tool_call_regex.finditer(model_output))
56
+ logger.debug("Found %d tool call matches", len(matches))
57
+
58
+ raw_function_calls = []
59
+
60
+ for i, match in enumerate(matches):
61
+ # position after the <function_call> tag
62
+ start_of_json = match.end()
63
+ # end_index == the start of the next function call
64
+ # (if exists)
65
+ next_function_call_start = (matches[i + 1].start()
66
+ if i + 1 < len(matches) else None)
67
+
68
+ raw_function_calls.append(
69
+ dec.raw_decode(
70
+ model_output[start_of_json:next_function_call_start])
71
+ [0])
72
+
73
+ logger.debug("Extracted %d tool calls", len(raw_function_calls))
74
+ tool_calls = [
75
+ ToolCall(
76
+ type="function",
77
+ function=FunctionCall(
78
+ name=function_call["name"],
79
+ # function call args are JSON but as a string
80
+ arguments=json.dumps(function_call["arguments"]),
81
+ ),
82
+ ) for function_call in raw_function_calls
83
+ ]
84
+
85
+ content = model_output[:model_output.find(self.bot_token)]
86
+ return ExtractedToolCallInformation(
87
+ tools_called=True,
88
+ tool_calls=tool_calls,
89
+ content=content if content else None,
90
+ )
91
+
92
+ except Exception as e:
93
+ logger.error("Error in extracting tool call from response %s", e)
94
+ return ExtractedToolCallInformation(tools_called=False,
95
+ tool_calls=[],
96
+ content=model_output)
97
+
98
+ def extract_tool_calls_streaming(
99
+ self,
100
+ previous_text: str,
101
+ current_text: str,
102
+ delta_text: str,
103
+ previous_token_ids: Sequence[int],
104
+ current_token_ids: Sequence[int],
105
+ delta_token_ids: Sequence[int],
106
+ request: ChatCompletionRequest,
107
+ ) -> Union[DeltaMessage, None]:
108
+
109
+ if len(current_text) < len(
110
+ self.bot_token) and self.bot_token.startswith(current_text):
111
+ return None
112
+
113
+ if not current_text.startswith(self.bot_token):
114
+ return DeltaMessage(content=delta_text)
115
+
116
+ # bit mask flags for partial JSON parsing. If the name hasn't been
117
+ # sent yet, don't allow sending
118
+ # an incomplete string since OpenAI only ever (as far as I have
119
+ # seen) allows sending the entire tool/ function name at once.
120
+ flags = Allow.ALL if self.current_tool_name_sent \
121
+ else Allow.ALL & ~Allow.STR
122
+ try:
123
+ tool_call_arr = []
124
+ is_complete = []
125
+ try:
126
+ start_idx = len(self.bot_token)
127
+ start_idx = consume_space(start_idx, current_text)
128
+
129
+ while start_idx < len(current_text):
130
+ (obj,
131
+ end_idx) = partial_json_loads(current_text[start_idx:],
132
+ flags)
133
+ is_complete.append(
134
+ is_complete_json(current_text[start_idx:start_idx +
135
+ end_idx]))
136
+ start_idx += end_idx
137
+ start_idx = consume_space(start_idx, current_text)
138
+ start_idx += len(self.bot_token)
139
+ start_idx = consume_space(start_idx, current_text)
140
+ tool_call_arr.append(obj)
141
+ except partial_json_parser.core.exceptions.MalformedJSON:
142
+ logger.debug('not enough tokens to parse into JSON yet')
143
+ return None
144
+
145
+ # select as the current tool call the one we're on the state at
146
+ current_tool_call: Dict = tool_call_arr[self.current_tool_id] \
147
+ if len(tool_call_arr) > 0 else {}
148
+
149
+ # case -- if no tokens have been streamed for the tool, e.g.
150
+ # only the array brackets, stream nothing
151
+ if len(tool_call_arr) == 0:
152
+ return None
153
+
154
+ # case: we are starting a new tool in the array
155
+ # -> array has > 0 length AND length has moved past cursor
156
+ elif (len(tool_call_arr) > 0
157
+ and len(tool_call_arr) > self.current_tool_id + 1):
158
+
159
+ # if we're moving on to a new call, first make sure we
160
+ # haven't missed anything in the previous one that was
161
+ # auto-generated due to JSON completions, but wasn't
162
+ # streamed to the client yet.
163
+ if self.current_tool_id >= 0:
164
+ cur_arguments = current_tool_call.get("arguments")
165
+ if cur_arguments:
166
+ cur_args_json = json.dumps(cur_arguments)
167
+ sent = len(
168
+ self.streamed_args_for_tool[self.current_tool_id])
169
+ argument_diff = cur_args_json[sent:]
170
+
171
+ logger.debug("got arguments diff: %s", argument_diff)
172
+ delta = DeltaMessage(tool_calls=[
173
+ DeltaToolCall(index=self.current_tool_id,
174
+ function=DeltaFunctionCall(
175
+ arguments=argument_diff).
176
+ model_dump(exclude_none=True))
177
+ ])
178
+ self.streamed_args_for_tool[
179
+ self.current_tool_id] += argument_diff
180
+ else:
181
+ delta = None
182
+ else:
183
+ delta = None
184
+ # re-set stuff pertaining to progress in the current tool
185
+ self.current_tool_id = len(tool_call_arr) - 1
186
+ self.current_tool_name_sent = False
187
+ self.streamed_args_for_tool.append("")
188
+ logger.debug("starting on new tool %d", self.current_tool_id)
189
+ return delta
190
+
191
+ # if the current tool name hasn't been sent, send if available
192
+ # - otherwise send nothing
193
+ elif not self.current_tool_name_sent:
194
+ function_name = current_tool_call.get("name")
195
+ if function_name:
196
+
197
+ delta = DeltaMessage(tool_calls=[
198
+ DeltaToolCall(index=self.current_tool_id,
199
+ type="function",
200
+ id=f"chatcmpl-tool-{random_uuid()}",
201
+ function=DeltaFunctionCall(
202
+ name=function_name).model_dump(
203
+ exclude_none=True))
204
+ ])
205
+ self.current_tool_name_sent = True
206
+ else:
207
+ delta = None
208
+
209
+ # now we know we're on the same tool call and we're streaming
210
+ # arguments
211
+ else:
212
+ cur_arguments = current_tool_call.get("arguments")
213
+ delta = None
214
+
215
+ if cur_arguments:
216
+ sent = len(
217
+ self.streamed_args_for_tool[self.current_tool_id])
218
+ cur_args_json = json.dumps(cur_arguments)
219
+ prev_arguments = self.prev_tool_call_arr[
220
+ self.current_tool_id].get("arguments")
221
+
222
+ argument_diff = None
223
+ if is_complete[self.current_tool_id]:
224
+ argument_diff = cur_args_json[sent:]
225
+ elif prev_arguments:
226
+ prev_args_json = json.dumps(prev_arguments)
227
+ if cur_args_json != prev_args_json:
228
+
229
+ prefix = find_common_prefix(
230
+ prev_args_json, cur_args_json)
231
+ argument_diff = prefix[sent:]
232
+
233
+ if argument_diff is not None:
234
+ delta = DeltaMessage(tool_calls=[
235
+ DeltaToolCall(index=self.current_tool_id,
236
+ function=DeltaFunctionCall(
237
+ arguments=argument_diff).
238
+ model_dump(exclude_none=True))
239
+ ])
240
+ self.streamed_args_for_tool[
241
+ self.current_tool_id] += argument_diff
242
+
243
+ self.prev_tool_call_arr = tool_call_arr
244
+ return delta
245
+
246
+ except Exception as e:
247
+ logger.error("Error trying to handle streaming tool call: %s", e)
248
+ logger.debug(
249
+ "Skipping chunk as a result of tool streaming extraction "
250
+ "error")
251
+ return None
vllm/entrypoints/openai/tool_parsers/llama_tool_parser.py
+4
-23
@@ -1,6 +1,6 @@
1
import json
2
import re
3
-from json import JSONDecodeError, JSONDecoder
3
+from json import JSONDecoder
4
from typing import Dict, List, Sequence, Union
5
6
import partial_json_parser
@@ -14,34 +14,15 @@ from vllm.entrypoints.openai.protocol import (ChatCompletionRequest,
14
FunctionCall, ToolCall)
15
from vllm.entrypoints.openai.tool_parsers.abstract_tool_parser import (
16
ToolParser, ToolParserManager)
17
-from vllm.entrypoints.openai.tool_parsers.utils import find_common_prefix
17
+from vllm.entrypoints.openai.tool_parsers.utils import (find_common_prefix,
18
+ is_complete_json,
19
+ partial_json_loads)
20
from vllm.logger import init_logger
21
from vllm.utils import random_uuid
22
23
logger = init_logger(__name__)
24
25
24
-# partial_json_parser doesn't support extra data and
25
-# JSONDecorder.raw_decode doesn't support partial JSON
26
-def partial_json_loads(input_str, flags):
27
- try:
28
- return (partial_json_parser.loads(input_str, flags), len(input_str))
29
- except JSONDecodeError as e:
30
- if "Extra data" in e.msg:
31
- dec = JSONDecoder()
32
- return dec.raw_decode(input_str)
33
- else:
34
- raise
35
-
36
-
37
-def is_complete_json(input_str):
38
- try:
39
- json.loads(input_str)
40
- return True
41
- except JSONDecodeError:
42
- return False
43
-
44
-
26
@ToolParserManager.register_module("llama3_json")
27
class Llama3JsonToolParser(ToolParser):
28
"""
vllm/entrypoints/openai/tool_parsers/utils.py
+35
-1
@@ -1,3 +1,11 @@
1
+import json
2
+from json import JSONDecodeError, JSONDecoder
3
+from typing import Any, List, Tuple
4
+
5
+import partial_json_parser
6
+from partial_json_parser.core.options import Allow
7
+
8
+
9
def find_common_prefix(s1: str, s2: str) -> str:
10
"""
11
Finds a common prefix that is shared between two strings, if there is one.
@@ -72,7 +80,7 @@ def extract_intermediate_diff(curr: str, old: str) -> str:
80
return diff
81
82
75
-def find_all_indices(string, substring):
83
+def find_all_indices(string: str, substring: str) -> List[int]:
84
"""
85
Find all (starting) indices of a substring in a given string. Useful for
86
tool call extraction
@@ -85,3 +93,29 @@ def find_all_indices(string, substring):
93
break
94
indices.append(index)
95
return indices
96
+
97
+
98
+# partial_json_parser doesn't support extra data and
99
+# JSONDecorder.raw_decode doesn't support partial JSON
100
+def partial_json_loads(input_str: str, flags: Allow) -> Tuple[Any, int]:
101
+ try:
102
+ return (partial_json_parser.loads(input_str, flags), len(input_str))
103
+ except JSONDecodeError as e:
104
+ if "Extra data" in e.msg:
105
+ dec = JSONDecoder()
106
+ return dec.raw_decode(input_str)
107
+ raise
108
+
109
+
110
+def is_complete_json(input_str: str) -> bool:
111
+ try:
112
+ json.loads(input_str)
113
+ return True
114
+ except JSONDecodeError:
115
+ return False
116
+
117
+
118
+def consume_space(i: int, s: str) -> int:
119
+ while i < len(s) and s[i].isspace():
120
+ i += 1
121
+ return i