-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmink_quickstart.py
More file actions
executable file
·98 lines (79 loc) · 2.95 KB
/
Copy pathmink_quickstart.py
File metadata and controls
executable file
·98 lines (79 loc) · 2.95 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python3
"""Quickstart for the ``chimera mink`` TUI-first CLI.
Drives ``chimera mink`` end-to-end through ``subprocess.run`` so the
example mirrors what a shell user would actually type. Covers two
canonical surfaces:
1. **One-shot**: ``chimera mink -p "<prompt>" --model glm-5`` runs a
single turn, prints the answer, and persists the run under
``~/.chimera/eventlog/`` (default behavior).
2. **Runs introspection**: ``chimera mink runs list`` enumerates every
persisted mink run so users can resume / share / inspect them.
Skip-conditions:
* No GLM-5 credential (``ANTHROPIC_AUTH_TOKEN`` or ``Z_AI_API_KEY``)
AND no ``CHIMERA_MINK_MODEL`` override pointing at Ollama-cloud.
We print a friendly message and exit 0.
Usage:
python examples/mink_quickstart.py
python examples/mink_quickstart.py --model kimi-k2.6:cloud
"""
from __future__ import annotations
import argparse
import os
import shutil
import subprocess
import sys
def _has_credential() -> bool:
"""Return True when at least one supported credential is set."""
for var in ("ANTHROPIC_AUTH_TOKEN", "ANTHROPIC_API_KEY", "Z_AI_API_KEY"):
if os.environ.get(var):
return True
return False
def demo_one_shot(model: str) -> int:
"""Run ``chimera mink -p ... --model ...`` and stream stdout."""
cmd = [
"chimera",
"mink",
"-p",
"Add a one-line docstring to a hypothetical fibonacci function.",
"--model",
model,
"--max-steps",
"8",
"--no-rich",
]
print(f"$ {' '.join(cmd)}")
proc = subprocess.run(cmd, capture_output=True, text=True, timeout=180)
sys.stdout.write(proc.stdout)
if proc.returncode != 0:
sys.stderr.write(proc.stderr)
return proc.returncode
def demo_runs_list() -> int:
"""List persisted mink runs (no LLM call required)."""
cmd = ["chimera", "mink", "runs", "list", "--limit", "5"]
print(f"\n$ {' '.join(cmd)}")
proc = subprocess.run(cmd, capture_output=True, text=True, timeout=30)
sys.stdout.write(proc.stdout)
if proc.returncode != 0:
sys.stderr.write(proc.stderr)
return proc.returncode
def main() -> int:
"""Entry point. Returns 0 on success or graceful skip."""
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--model", default="glm-5")
args = parser.parse_args()
if shutil.which("chimera") is None:
print("skipping: `chimera` CLI not on PATH (run `uv sync`).")
return 0
if not _has_credential():
print("skipping: no provider credential found.")
print(" Set ANTHROPIC_AUTH_TOKEN, Z_AI_API_KEY, or ANTHROPIC_API_KEY.")
return 0
print("=== mink demo: one-shot -p ===")
rc1 = demo_one_shot(args.model)
print(f"[one-shot] exit={rc1}")
print("\n=== mink demo: runs list ===")
rc2 = demo_runs_list()
print(f"[runs list] exit={rc2}")
return 0
if __name__ == "__main__":
sys.exit(main())