Support fenced local model tool requests
This commit is contained in:
parent
e1800c8846
commit
52f7c51111
|
|
@ -99,7 +99,8 @@ per-tool memory limit; `LAB_HOLMES_REPAIR_MAX_STEPS`,
|
|||
override these limits. These are limits, not a guarantee that Holmes will
|
||||
complete or that every tool can run within them.
|
||||
When `LAB_HOLMES_MODEL` selects `ollama_chat/...`, repair mode starts a
|
||||
temporary loopback proxy that translates a single bare JSON tool request into
|
||||
temporary loopback proxy that translates a single JSON tool request, optionally
|
||||
in one Markdown JSON fence, into
|
||||
an OpenAI-style tool call only if the requested name and arguments pass the
|
||||
tool's supplied JSON Schema. Other responses are passed through. It uses the
|
||||
Holmes pipx Python environment for `jsonschema`; override that interpreter with
|
||||
|
|
|
|||
|
|
@ -35,6 +35,11 @@ fresh mounts. Immediately re-check the pod UID and owner before deleting it.
|
|||
Use `kubectl -n <namespace> delete pod <pod-name>`; never use force or zero
|
||||
grace period. Do not delete, recreate, reformat or modify the PVC, PV, data,
|
||||
configuration or encryption keys. Do not regenerate an application key.
|
||||
When calling the Bash tool, include both required fields: `command` is the exact
|
||||
command and `suggested_prefixes` is an array containing `kubectl`. For example,
|
||||
the arguments are `{"command":"kubectl -n demo delete pod example-123",
|
||||
"suggested_prefixes":["kubectl"]}`. Substitute only the verified namespace
|
||||
and current pod name; this example is not an instruction to act on demo.
|
||||
If the pod is not controller-managed, mounts remain busy, the volume is not
|
||||
confirmed, or the delete fails, stop and report what remains unknown.
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
This is a testing utility: it never executes a tool or starts a network service.
|
||||
"""
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
|
||||
import jsonschema
|
||||
|
|
@ -29,8 +30,12 @@ def has_external_reference(value):
|
|||
|
||||
def convert(content, tools):
|
||||
"""Return a structured call only for a single exact, schema-valid request."""
|
||||
if not isinstance(content, str):
|
||||
return None
|
||||
try:
|
||||
request = json.loads(content, object_pairs_hook=unique_object)
|
||||
text = content.strip()
|
||||
fenced = re.fullmatch(r"```(?:json)?[ \t]*\r?\n(.*?)\r?\n```", text, re.IGNORECASE | re.DOTALL)
|
||||
request = json.loads(fenced.group(1) if fenced else text, object_pairs_hook=unique_object)
|
||||
except (TypeError, ValueError):
|
||||
return None
|
||||
if not isinstance(request, dict) or set(request) != {"name", "arguments"}:
|
||||
|
|
|
|||
|
|
@ -20,9 +20,11 @@ class ToolAdapterTests(unittest.TestCase):
|
|||
def test_valid_call(self):
|
||||
result = ADAPTER.convert(json.dumps({"name": "get_status", "arguments": {"service": "demo"}}), self.tools)
|
||||
self.assertEqual(result["function"]["arguments"], {"service": "demo"})
|
||||
self.assertIsNotNone(ADAPTER.convert('```json\n{"name":"get_status","arguments":{"service":"demo"}}\n```', self.tools))
|
||||
|
||||
def test_invalid_or_ambiguous_calls_are_not_translated(self):
|
||||
for value in ('prefix {"name":"get_status","arguments":{}}',
|
||||
'prose\n```json\n{"name":"get_status","arguments":{"service":"demo"}}\n```',
|
||||
'{"name":"unknown","arguments":{}}',
|
||||
'{"name":"get_status","arguments":{"service":42}}',
|
||||
'{"name":"get_status","arguments":{"service":"demo","extra":1}}',
|
||||
|
|
|
|||
Loading…
Reference in New Issue