MCPcopy
hub / github.com/mudler/LocalAI / parse_options

Function parse_options

backend/python/common/python_utils.py:10–37  ·  view source on GitHub ↗

Parse Options[] list of ``key:value`` strings into a dict. Supports type inference for common cases (bool, int, float). Unknown or mixed-case values are returned as strings. Used by LoadModel to extract backend-specific options passed via ``ModelOptions.Options`` in ``backend.proto

(options_list)

Source from the content-addressed store, hash-verified

8
9
10def parse_options(options_list):
11 """Parse Options[] list of ``key:value`` strings into a dict.
12
13 Supports type inference for common cases (bool, int, float). Unknown or
14 mixed-case values are returned as strings.
15
16 Used by LoadModel to extract backend-specific options passed via
17 ``ModelOptions.Options`` in ``backend.proto``.
18 """
19 opts = {}
20 for opt in options_list:
21 if ":" not in opt:
22 continue
23 key, value = opt.split(":", 1)
24 key = key.strip()
25 value = value.strip()
26 # Try type conversion
27 if value.lower() in ("true", "false"):
28 opts[key] = value.lower() == "true"
29 else:
30 try:
31 opts[key] = int(value)
32 except ValueError:
33 try:
34 opts[key] = float(value)
35 except ValueError:
36 opts[key] = value
37 return opts
38
39
40def messages_to_dicts(proto_messages):

Callers 8

LoadModelMethod · 0.90
LoadModelMethod · 0.90
LoadModelMethod · 0.90
LoadModelMethod · 0.85
LoadModelMethod · 0.85

Calls

no outgoing calls

Tested by 3