f3a8a38acd
web-platform-ci / Standalone decision service (no cloud credentials) (push) Has been cancelled
web-platform-ci / TypeScript, lint, unit, build (push) Has been cancelled
web-platform-ci / Playwright E2E (push) Has been cancelled
lekiwi-compatibility / cpu-compatibility (push) Has been cancelled
web-platform-ci / Standalone decision service (no cloud credentials) (pull_request) Has been cancelled
web-platform-ci / TypeScript, lint, unit, build (pull_request) Has been cancelled
web-platform-ci / Playwright E2E (pull_request) Has been cancelled
lekiwi-compatibility / cpu-compatibility (pull_request) Has been cancelled
集成同源 BYOK 会话隔离、精简模型设置、官方订阅入口和 HTTPS 发布运维;保留本地训练/调参与控制能力。同步 npm 版本及 CHANGELOG,记录公网真实 API 验收仍待用户凭据。
86 lines
2.8 KiB
Python
86 lines
2.8 KiB
Python
"""Explicit opt-in E2E fixture: real gateway, loopback fake HTTP upstream; never deployed."""
|
|
|
|
import asyncio
|
|
import os
|
|
import time
|
|
from dataclasses import replace
|
|
|
|
from aiohttp import web
|
|
|
|
from decision_server.providers import http, jev, openai
|
|
from decision_server.tests.test_service import plan_value
|
|
from decision_server.web_server import CATALOG, create_website_app
|
|
|
|
|
|
async def main():
|
|
if os.environ.get("CADWORLD_E2E") != "1":
|
|
raise RuntimeError("fixture_requires_explicit_opt_in")
|
|
upstream = web.Application()
|
|
|
|
async def respond(request):
|
|
body = await request.json()
|
|
if request.path == "/decisions":
|
|
return web.json_response(
|
|
{
|
|
"answers": {
|
|
name: {"choice": next(iter(q["criteria"]))}
|
|
for name, q in body["questions"].items()
|
|
},
|
|
"usage": {"input_tokens": 1},
|
|
}
|
|
)
|
|
import json
|
|
|
|
value = '{"ok":true}' if '"ok"' in str(body) else json.dumps(plan_value())
|
|
if request.path == "/chat/completions":
|
|
return web.json_response(
|
|
{"choices": [{"finish_reason": "stop", "message": {"content": value}}]}
|
|
)
|
|
return web.json_response(
|
|
{
|
|
"status": "completed",
|
|
"output": [
|
|
{"type": "message", "content": [{"type": "output_text", "text": value}]}
|
|
],
|
|
"usage": {"input_tokens": 1},
|
|
}
|
|
)
|
|
|
|
upstream.router.add_post("/{path:.*}", respond)
|
|
runner = web.AppRunner(upstream, access_log=None)
|
|
await runner.setup()
|
|
site = web.TCPSite(runner, "127.0.0.1", 0)
|
|
await site.start()
|
|
port = site._server.sockets[0].getsockname()[1]
|
|
|
|
async def fake_post(session, connection, path, payload):
|
|
url = f"http://127.0.0.1:{port}" + ("/decisions" if not path else "")
|
|
return await http.post(session, replace(connection, base_url=url), path, payload)
|
|
|
|
openai.post = jev.post = fake_post
|
|
# test_connection also references the bounded helper directly.
|
|
from decision_server import server
|
|
|
|
server.post = fake_post
|
|
app = create_website_app("http://127.0.0.1:4180", development=True)
|
|
catalog = app[CATALOG]
|
|
catalog.models = {"fixture/structured": "Fixture structured model (not real)"}
|
|
catalog.available = True
|
|
|
|
async def refresh(_):
|
|
catalog.checked_at = time.monotonic()
|
|
|
|
catalog.refresh = refresh
|
|
gateway = web.AppRunner(app, access_log=None, handler_cancellation=True)
|
|
await gateway.setup()
|
|
await web.TCPSite(gateway, "127.0.0.1", 8769).start()
|
|
try:
|
|
await asyncio.Event().wait()
|
|
finally:
|
|
await gateway.cleanup()
|
|
await runner.cleanup()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|