Skip to content

Commit 9ee74f3

Browse files
committed
fix: embeddings endpoint
1 parent f1d0135 commit 9ee74f3

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/v1/embeddings.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { FastifyPluginAsync } from "fastify";
2-
import { object, z } from "zod";
2+
import { z } from "zod";
33
import { ZodTypeProvider } from "fastify-type-provider-zod";
4-
import { genAI } from "src/genAI";
4+
import { gen_ai_hub } from "src/genAI";
55
import { EmbedContentRequest } from "@google/generative-ai";
66

77
// 定义请求体的 Zod Schema
@@ -15,6 +15,10 @@ const EMBEDDINGS_SCHEMA = z.object({
1515

1616
function build_embedding_payload(body: z.infer<typeof EMBEDDINGS_SCHEMA>) {
1717
const { input, model, encoding_format, dimensions, user } = body;
18+
const genAI = gen_ai_hub.random();
19+
if (!genAI) {
20+
throw new Error("no genai available");
21+
}
1822
const gen_model = genAI.getGenerativeModel({
1923
model: model,
2024
});
@@ -42,8 +46,8 @@ const embeddingsRoute: FastifyPluginAsync = async (app) => {
4246
url: "/v1/embeddings",
4347
schema: { body: EMBEDDINGS_SCHEMA },
4448
handler: async (req, res) => {
45-
const { model } = req.body;
46-
const payload = build_embedding_payload(req.body);
49+
const { model } = req.body as any;
50+
const payload = build_embedding_payload(req.body as any);
4751

4852
const resp = await payload.gen_model.batchEmbedContents({
4953
requests: payload.requests,

0 commit comments

Comments
 (0)