import { createRoute, type OpenAPIHono, z } from "@hono/zod-openapi";
app.openapi(
createRoute({
method: "get",
path: "/llms-docs",
summary: "LLMs Docs",
description: "Get the combined content of the docs folder.",
responses: {
200: {
description: "Successful get the combined content of the docs",
content: {
"application/json": {
schema: z.object({
text: z.string().openapi({
description: "The generated text",
}),
length: z.number().openapi({
description: "The length of the generated text",
}),
tokens: z.number().openapi({
description: "The number of tokens in the generated text",
}),
}),
},
},
},
},
}),
async (c) => {
// Handler implementation
const contentDir = join(process.cwd(), "./docs");
const files = await getAllFiles(contentDir);
let fullContent = "";
for (const file of files) {
const fileContent = await readFile(file, "utf-8");
fullContent += fileContent + "\n\n";
}
return c.json({
text: fullContent,
length: fullContent.length,
tokens: fullContent.length / 4,
});
}
);