From 93cdec89edb819984c475c60dcbad51293339e77 Mon Sep 17 00:00:00 2001 From: Igor Soarez Date: Thu, 5 Nov 2026 20:22:02 +0200 Subject: name pi sessions automatically, replacing the pi-auto-session-name package --- tests/fake-model.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'tests/fake-model.py') diff --git a/tests/fake-model.py b/tests/fake-model.py index 98a61db..a00ccb2 100755 --- a/tests/fake-model.py +++ b/tests/fake-model.py @@ -2,7 +2,8 @@ """A fake OpenAI-compatible model for tests/pi-live.sh: streams a short reply to /v1/chat/completions, after a delay taken from the last user message ("slow 3" waits 3 seconds), or fails as a provider does ("fail 401": an -authentication error). Prints its port, then serves until killed.""" +authentication error). Asked to name a session, it answers "About ". Prints its port, then serves until killed.""" import json import re import sys @@ -33,6 +34,10 @@ class Handler(BaseHTTPRequestHandler): def do_POST(self): body = json.loads(self.rfile.read(int(self.headers.get("Content-Length", 0))) or b"{}") text = last_user_text(body) + if "Name this coding-agent session" in text: + said = re.findall(r"^User: (.*)$", text, re.M) + self.reply("About " + (said[-1][:40] if said else "nothing")) + return match = re.search(r"slow (\d+(?:\.\d+)?)", text) time.sleep(float(match.group(1)) if match else 0.2) failure = re.search(r"fail (\d{3})", text) @@ -43,6 +48,9 @@ class Handler(BaseHTTPRequestHandler): self.end_headers() self.wfile.write(error.encode()) return + self.reply("Done: fake reply.") + + def reply(self, text): self.send_response(200) self.send_header("Content-Type", "text/event-stream") self.send_header("Cache-Control", "no-cache") @@ -56,8 +64,7 @@ class Handler(BaseHTTPRequestHandler): self.wfile.write(f"data: {json.dumps(data)}\n\n".encode()) self.wfile.flush() - chunk({"role": "assistant", "content": "Done: "}) - chunk({"content": "fake reply."}) + chunk({"role": "assistant", "content": text}) chunk({}, "stop", {"prompt_tokens": 10, "completion_tokens": 3, "total_tokens": 13}) self.wfile.write(b"data: [DONE]\n\n") self.wfile.flush() -- cgit v1.2.3