Files
zhuangang/topics/backend/nodejs/examples/express-bff/server.ts
T

18 lines
701 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 不自动运行:启动服务 node server.ts,然后 curl -N -X POST localhost:3000/chat -H 'content-type: application/json' -d '{"question":"退货"}'
import { createApp } from "./app.ts";
async function* fakeLLM(q: string, signal: AbortSignal) {
for (const t of ["关于", `“${q}”`, ":", "签收 7 天内", "可以申请退货。"]) {
if (signal.aborted) return;
await new Promise((r) => setTimeout(r, 200));
yield t;
}
}
const app = createApp({
askLLM: fakeLLM,
findOrder: async (id) => (id === "A001" ? { id, status: "paid" } : null),
});
const port = Number(process.env.PORT ?? 3000);
app.listen(port, () => console.log(`listening on http://127.0.0.1:${port}`));