-
Notifications
You must be signed in to change notification settings - Fork 664
Expand file tree
/
Copy pathshell.py
More file actions
54 lines (44 loc) · 1.17 KB
/
Copy pathshell.py
File metadata and controls
54 lines (44 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""
Shell execution with the OS-level sandbox enabled.
The model is given a shell tool and can run commands in a per-session working
directory.
Run with:
pip install -e mistralrs-pyo3 --features code-execution
python examples/python/shell.py
"""
from mistralrs import (
ChatCompletionRequest,
NetworkMode,
Runner,
SandboxPolicy,
ShellConfig,
Which,
)
def main():
sandbox = SandboxPolicy(
max_memory_mb=1024,
max_cpu_secs=120,
max_procs=32,
network=NetworkMode.Loopback,
)
runner = Runner(
which=Which.Plain(model_id="Qwen/Qwen3-4B"),
shell_config=ShellConfig(sandbox_policy=sandbox),
)
response = runner.send_chat_completion_request(
ChatCompletionRequest(
model="default",
messages=[
{
"role": "user",
"content": "Use the shell to print the current directory and list its files.",
}
],
enable_shell=True,
max_tool_rounds=4,
)
)
for choice in response.choices:
print(choice.message.content)
if __name__ == "__main__":
main()