MCPcopy Create free account
hub / github.com/pollinations/pollinations / createTextCacheApp

Function createTextCacheApp

gen.pollinations.ai/test/text-cache.test.ts:29–73  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

27};
28
29function createTextCacheApp() {
30 let originHits = 0;
31 const app = new Hono<TestEnv>()
32 .use("*", async (c, next) => {
33 c.set("log", testLog);
34 c.set("requestId", "test-request");
35 await next();
36 })
37 .post(
38 "/v1/chat/completions",
39 validator("json", CreateChatCompletionRequestSchema),
40 textCache,
41 async (c) => {
42 originHits += 1;
43 return new Response(
44 JSON.stringify({
45 originHits,
46 body: await c.req.text(),
47 }),
48 {
49 headers: {
50 "Content-Type": "application/json; charset=utf-8",
51 "x-model-used": "openai-fast",
52 "x-usage-prompt-text-tokens": "12",
53 "x-moderation-hate-severity": "safe",
54 },
55 },
56 );
57 },
58 )
59 .get("/text/:prompt", textCache, async (c) => {
60 originHits += 1;
61 return new Response(`hit:${originHits}:${c.req.param("prompt")}`, {
62 headers: { "Content-Type": "text/plain" },
63 });
64 })
65 .get("/v1/models", async () => Response.json({ data: [] }));
66
67 return {
68 app,
69 get originHits() {
70 return originHits;
71 },
72 };
73}
74
75function createTextCacheEnv(bucket = createTestR2Bucket()): CloudflareBindings {
76 return {

Callers 1

text-cache.test.tsFile · 0.85

Calls 7

validatorFunction · 0.90
useMethod · 0.80
stringifyMethod · 0.80
jsonMethod · 0.80
getMethod · 0.65
setMethod · 0.65
textMethod · 0.65

Tested by

no test coverage detected