diff --git a/dist/main_bun.mjs b/dist/main_bun.mjs index 3e4019e..e21a0a3 100644 --- a/dist/main_bun.mjs +++ b/dist/main_bun.mjs @@ -105,22 +105,18 @@ function genModel(req) { const model = GeminiModel.modelMapping(req.model); let functions = req.tools?.filter((it) => it.type === "function")?.map((it) => it.function) ?? []; functions = functions.concat((req.functions ?? []).map((it) => ({ strict: null, ...it }))); - let responseMimeType; - let responseSchema; - switch (req.response_format?.type) { - case "json_object": - responseMimeType = "application/json"; - break; - case "json_schema": - responseMimeType = "application/json"; - responseSchema = req.response_format.json_schema.schema; - break; - case "text": - responseMimeType = "text/plain"; - break; - default: - break; - } + const [responseMimeType, responseSchema] = (() => { + switch (req.response_format?.type) { + case "json_object": + return ["application/json", void 0]; + case "json_schema": + return ["application/json", req.response_format.json_schema.schema]; + case "text": + return ["text/plain", void 0]; + default: + return [void 0, void 0]; + } + })(); const generateContentRequest = { contents: openAiMessageToGeminiMessage(req.messages), generationConfig: { diff --git a/dist/main_cloudflare-workers.mjs b/dist/main_cloudflare-workers.mjs index a9f3c90..1a3af42 100644 --- a/dist/main_cloudflare-workers.mjs +++ b/dist/main_cloudflare-workers.mjs @@ -105,22 +105,18 @@ function genModel(req) { const model = GeminiModel.modelMapping(req.model); let functions = req.tools?.filter((it) => it.type === "function")?.map((it) => it.function) ?? []; functions = functions.concat((req.functions ?? []).map((it) => ({ strict: null, ...it }))); - let responseMimeType; - let responseSchema; - switch (req.response_format?.type) { - case "json_object": - responseMimeType = "application/json"; - break; - case "json_schema": - responseMimeType = "application/json"; - responseSchema = req.response_format.json_schema.schema; - break; - case "text": - responseMimeType = "text/plain"; - break; - default: - break; - } + const [responseMimeType, responseSchema] = (() => { + switch (req.response_format?.type) { + case "json_object": + return ["application/json", void 0]; + case "json_schema": + return ["application/json", req.response_format.json_schema.schema]; + case "text": + return ["text/plain", void 0]; + default: + return [void 0, void 0]; + } + })(); const generateContentRequest = { contents: openAiMessageToGeminiMessage(req.messages), generationConfig: { diff --git a/dist/main_deno.mjs b/dist/main_deno.mjs index 741aff1..1e1e2f4 100644 --- a/dist/main_deno.mjs +++ b/dist/main_deno.mjs @@ -105,22 +105,18 @@ function genModel(req) { const model = GeminiModel.modelMapping(req.model); let functions = req.tools?.filter((it) => it.type === "function")?.map((it) => it.function) ?? []; functions = functions.concat((req.functions ?? []).map((it) => ({ strict: null, ...it }))); - let responseMimeType; - let responseSchema; - switch (req.response_format?.type) { - case "json_object": - responseMimeType = "application/json"; - break; - case "json_schema": - responseMimeType = "application/json"; - responseSchema = req.response_format.json_schema.schema; - break; - case "text": - responseMimeType = "text/plain"; - break; - default: - break; - } + const [responseMimeType, responseSchema] = (() => { + switch (req.response_format?.type) { + case "json_object": + return ["application/json", void 0]; + case "json_schema": + return ["application/json", req.response_format.json_schema.schema]; + case "text": + return ["text/plain", void 0]; + default: + return [void 0, void 0]; + } + })(); const generateContentRequest = { contents: openAiMessageToGeminiMessage(req.messages), generationConfig: { diff --git a/dist/main_node.mjs b/dist/main_node.mjs index f96367a..a8896ad 100644 --- a/dist/main_node.mjs +++ b/dist/main_node.mjs @@ -563,22 +563,18 @@ function genModel(req) { const model = GeminiModel.modelMapping(req.model); let functions = req.tools?.filter((it) => it.type === "function")?.map((it) => it.function) ?? []; functions = functions.concat((req.functions ?? []).map((it) => ({ strict: null, ...it }))); - let responseMimeType; - let responseSchema; - switch (req.response_format?.type) { - case "json_object": - responseMimeType = "application/json"; - break; - case "json_schema": - responseMimeType = "application/json"; - responseSchema = req.response_format.json_schema.schema; - break; - case "text": - responseMimeType = "text/plain"; - break; - default: - break; - } + const [responseMimeType, responseSchema] = (() => { + switch (req.response_format?.type) { + case "json_object": + return ["application/json", void 0]; + case "json_schema": + return ["application/json", req.response_format.json_schema.schema]; + case "text": + return ["text/plain", void 0]; + default: + return [void 0, void 0]; + } + })(); const generateContentRequest = { contents: openAiMessageToGeminiMessage(req.messages), generationConfig: { diff --git a/src/utils.ts b/src/utils.ts index f2dd2ea..20cfa69 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -78,23 +78,18 @@ export function genModel(req: OpenAI.Chat.ChatCompletionCreateParams): [GeminiMo functions = functions.concat((req.functions ?? []).map((it) => ({ strict: null, ...it }))) - let responseMimeType: string | undefined - let responseSchema: JsonSchema | undefined - - switch (req.response_format?.type) { - case "json_object": - responseMimeType = "application/json" - break - case "json_schema": - responseMimeType = "application/json" - responseSchema = req.response_format.json_schema.schema - break - case "text": - responseMimeType = "text/plain" - break - default: - break - } + const [responseMimeType, responseSchema] = (() => { + switch (req.response_format?.type) { + case "json_object": + return ["application/json", undefined] + case "json_schema": + return ["application/json", req.response_format.json_schema.schema satisfies JsonSchema | undefined] + case "text": + return ["text/plain", undefined] + default: + return [undefined, undefined] + } + })() const generateContentRequest: GenerateContentRequest = { contents: openAiMessageToGeminiMessage(req.messages),