Files
thekhalidsha 917d4632c2 Open source under Apache 2.0, with a new README
- LICENSE (Apache 2.0), NOTICE with credits (Needle 2, LiteRT-LM, Thinai),
  LICENSES/Thinai-MIT.txt, SPDX headers on every source file
- CONTRIBUTING (fork, branch from develop, PR into develop, maintainer
  merges), CODE_OF_CONDUCT (Contributor Covenant 2.1), SECURITY, Gitea
  issue and pull-request templates
- README rewritten with screenshots; the detailed guide moved to
  docs/USER_GUIDE.md
- Personal details removed: made-up contact names in examples and tests,
  a placeholder for the Tailscale address, made-up web-search fixtures
  in place of saved third-party pages
- B-43: the emulator reports Needle as unavailable instead of "init failed"
- B-44: chat previews show plain text, not Markdown symbols
2026-09-28 12:40:28 +05:30

32 lines
1.9 KiB
Python

# 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: <your message> (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()