# SPDX-FileCopyrightText: 2026 Mohammed Khalid # SPDX-License-Identifier: Apache-2.0 """A stand-in for a real AI, for testing Stitch in the emulator without paying for a key. It answers every chat request with "Fake AI reply to: (I can see N messages and M tools)", which is enough to check that chats are saved, that the right history is sent, and how many tools Stitch offers (70 for a cloud AI, 33 for a model on the phone). python3 tools-dev/fake-ai/fake_ai.py # listens on port 8099 # In the emulator, the PC is 10.0.2.2: use http://10.0.2.2:8099/v1 as a Custom provider. # To pretend to be Thinai on the phone itself: adb reverse tcp:11434 tcp:8099 """ import json, http.server class H(http.server.BaseHTTPRequestHandler): def _send(self, obj): b = json.dumps(obj).encode(); self.send_response(200) self.send_header("Content-Type", "application/json"); self.send_header("Content-Length", str(len(b))); self.end_headers(); self.wfile.write(b) def do_GET(self): self._send({"data": [{"id": "fake-model"}]}) def do_POST(self): body = json.loads(self.rfile.read(int(self.headers["Content-Length"]))) msgs = body.get("messages", []) user = [m for m in msgs if m.get("role") == "user"] last = user[-1]["content"] if user else "" if isinstance(last, list): last = " ".join(p.get("text", "") for p in last if isinstance(p, dict)) n_tools = len(body.get("tools") or []) reply = f"Fake AI reply to: {last} (I can see {len(msgs)} messages and {n_tools} tools)" self._send({"id": "x", "object": "chat.completion", "model": "fake-model", "choices": [{"index": 0, "finish_reason": "stop", "message": {"role": "assistant", "content": reply}}]}) def log_message(self, *a): pass http.server.ThreadingHTTPServer(("0.0.0.0", 8099), H).serve_forever()