Refactor public API around environments
This commit is contained in:
parent
57dae52cc2
commit
5d5243df23
41 changed files with 1301 additions and 459 deletions
|
|
@ -31,7 +31,7 @@ def _stepwise_model_response(payload: dict[str, Any], step: int) -> dict[str, An
|
|||
"message": {
|
||||
"role": "assistant",
|
||||
"content": "",
|
||||
"tool_calls": [{"id": "1", "function": {"name": "vm_list_profiles"}}],
|
||||
"tool_calls": [{"id": "1", "function": {"name": "vm_list_environments"}}],
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
@ -50,7 +50,7 @@ def _stepwise_model_response(payload: dict[str, Any], step: int) -> dict[str, An
|
|||
"name": "vm_run",
|
||||
"arguments": json.dumps(
|
||||
{
|
||||
"profile": "debian-git",
|
||||
"environment": "debian:12",
|
||||
"command": "printf 'true\\n'",
|
||||
"vcpu_count": 1,
|
||||
"mem_mib": 512,
|
||||
|
|
@ -117,7 +117,7 @@ def test_run_ollama_tool_demo_recovers_from_bad_vm_id(
|
|||
"name": "vm_exec",
|
||||
"arguments": json.dumps(
|
||||
{
|
||||
"vm_id": "vm_list_profiles",
|
||||
"vm_id": "vm_list_environments",
|
||||
"command": ollama_demo.NETWORK_PROOF_COMMAND,
|
||||
}
|
||||
),
|
||||
|
|
@ -157,15 +157,15 @@ def test_run_ollama_tool_demo_resolves_vm_id_placeholder(
|
|||
"role": "assistant",
|
||||
"content": "",
|
||||
"tool_calls": [
|
||||
{"id": "1", "function": {"name": "vm_list_profiles"}},
|
||||
{"id": "2", "function": {"name": "vm_list_profiles"}},
|
||||
{"id": "1", "function": {"name": "vm_list_environments"}},
|
||||
{"id": "2", "function": {"name": "vm_list_environments"}},
|
||||
{
|
||||
"id": "3",
|
||||
"function": {
|
||||
"name": "vm_create",
|
||||
"arguments": json.dumps(
|
||||
{
|
||||
"profile": "debian-git",
|
||||
"environment": "debian:12",
|
||||
"vcpu_count": "2",
|
||||
"mem_mib": "2048",
|
||||
}
|
||||
|
|
@ -217,7 +217,12 @@ def test_run_ollama_tool_demo_resolves_vm_id_placeholder(
|
|||
|
||||
def test_dispatch_tool_call_vm_exec_autostarts_created_vm(tmp_path: Path) -> None:
|
||||
pyro = RealPyro(manager=RealVmManager(backend_name="mock", base_dir=tmp_path / "vms"))
|
||||
created = pyro.create_vm(profile="debian-base", vcpu_count=1, mem_mib=512, ttl_seconds=60)
|
||||
created = pyro.create_vm(
|
||||
environment="debian:12-base",
|
||||
vcpu_count=1,
|
||||
mem_mib=512,
|
||||
ttl_seconds=60,
|
||||
)
|
||||
vm_id = str(created["vm_id"])
|
||||
|
||||
executed = ollama_demo._dispatch_tool_call(
|
||||
|
|
@ -291,7 +296,7 @@ def test_run_ollama_tool_demo_verbose_logs_values(monkeypatch: pytest.MonkeyPatc
|
|||
assert result["fallback_used"] is False
|
||||
assert str(result["exec_result"]["stdout"]).strip() == "true"
|
||||
assert any("[model] input user:" in line for line in logs)
|
||||
assert any("[model] tool_call vm_list_profiles args={}" in line for line in logs)
|
||||
assert any("[model] tool_call vm_list_environments args={}" in line for line in logs)
|
||||
assert any("[tool] result vm_run " in line for line in logs)
|
||||
|
||||
|
||||
|
|
@ -299,7 +304,7 @@ def test_run_ollama_tool_demo_verbose_logs_values(monkeypatch: pytest.MonkeyPatc
|
|||
("tool_call", "error"),
|
||||
[
|
||||
(1, "invalid tool call entry"),
|
||||
({"id": "", "function": {"name": "vm_list_profiles"}}, "valid call id"),
|
||||
({"id": "", "function": {"name": "vm_list_environments"}}, "valid call id"),
|
||||
({"id": "1"}, "function metadata"),
|
||||
({"id": "1", "function": {"name": 3}}, "name is invalid"),
|
||||
],
|
||||
|
|
@ -326,7 +331,7 @@ def test_run_ollama_tool_demo_max_rounds(monkeypatch: pytest.MonkeyPatch) -> Non
|
|||
{
|
||||
"message": {
|
||||
"role": "assistant",
|
||||
"tool_calls": [{"id": "1", "function": {"name": "vm_list_profiles"}}],
|
||||
"tool_calls": [{"id": "1", "function": {"name": "vm_list_environments"}}],
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
@ -384,13 +389,13 @@ def test_run_ollama_tool_demo_exec_result_validation(
|
|||
|
||||
def test_dispatch_tool_call_coverage(tmp_path: Path) -> None:
|
||||
pyro = RealPyro(manager=RealVmManager(backend_name="mock", base_dir=tmp_path / "vms"))
|
||||
profiles = ollama_demo._dispatch_tool_call(pyro, "vm_list_profiles", {})
|
||||
assert "profiles" in profiles
|
||||
environments = ollama_demo._dispatch_tool_call(pyro, "vm_list_environments", {})
|
||||
assert "environments" in environments
|
||||
created = ollama_demo._dispatch_tool_call(
|
||||
pyro,
|
||||
"vm_create",
|
||||
{
|
||||
"profile": "debian-base",
|
||||
"environment": "debian:12-base",
|
||||
"vcpu_count": "1",
|
||||
"mem_mib": "512",
|
||||
"ttl_seconds": "60",
|
||||
|
|
@ -412,7 +417,7 @@ def test_dispatch_tool_call_coverage(tmp_path: Path) -> None:
|
|||
pyro,
|
||||
"vm_run",
|
||||
{
|
||||
"profile": "debian-base",
|
||||
"environment": "debian:12-base",
|
||||
"command": "printf 'true\\n'",
|
||||
"vcpu_count": "1",
|
||||
"mem_mib": "512",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue