Skip to content

Commit

Permalink
don't mapping if model name start with 'gemini'
Browse files Browse the repository at this point in the history
  • Loading branch information
zuisong committed Sep 2, 2024
1 parent 2617bb0 commit 56b6927
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 5 deletions.
8 changes: 7 additions & 1 deletion dist/main_bun.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,13 @@ function openAiMessageToGeminiMessage(messages) {
return result;
}
function genModel(req) {
const model = ModelMapping[req.model] ?? "gemini-1.0-pro-latest";
const defaultModel = (m) => {
if (m.startsWith("gemini")) {
return m;
}
return "gemini-1.5-flash-latest";
};
const model = ModelMapping[req.model] ?? defaultModel(req.model);
let functions = req.tools?.filter((it) => it.type === "function")?.map((it) => it.function) ?? [];
functions = functions.concat(req.functions ?? []);
const responseMimeType = req.response_format?.type === "json_object" ? "application/json" : "text/plain";
Expand Down
8 changes: 7 additions & 1 deletion dist/main_cloudflare-workers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,13 @@ function openAiMessageToGeminiMessage(messages) {
return result;
}
function genModel(req) {
const model = ModelMapping[req.model] ?? "gemini-1.0-pro-latest";
const defaultModel = (m) => {
if (m.startsWith("gemini")) {
return m;
}
return "gemini-1.5-flash-latest";
};
const model = ModelMapping[req.model] ?? defaultModel(req.model);
let functions = req.tools?.filter((it) => it.type === "function")?.map((it) => it.function) ?? [];
functions = functions.concat(req.functions ?? []);
const responseMimeType = req.response_format?.type === "json_object" ? "application/json" : "text/plain";
Expand Down
8 changes: 7 additions & 1 deletion dist/main_deno.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,13 @@ function openAiMessageToGeminiMessage(messages) {
return result;
}
function genModel(req) {
const model = ModelMapping[req.model] ?? "gemini-1.0-pro-latest";
const defaultModel = (m) => {
if (m.startsWith("gemini")) {
return m;
}
return "gemini-1.5-flash-latest";
};
const model = ModelMapping[req.model] ?? defaultModel(req.model);
let functions = req.tools?.filter((it) => it.type === "function")?.map((it) => it.function) ?? [];
functions = functions.concat(req.functions ?? []);
const responseMimeType = req.response_format?.type === "json_object" ? "application/json" : "text/plain";
Expand Down
8 changes: 7 additions & 1 deletion dist/main_node.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,13 @@ function openAiMessageToGeminiMessage(messages) {
return result;
}
function genModel(req) {
const model = ModelMapping[req.model] ?? "gemini-1.0-pro-latest";
const defaultModel = (m) => {
if (m.startsWith("gemini")) {
return m;
}
return "gemini-1.5-flash-latest";
};
const model = ModelMapping[req.model] ?? defaultModel(req.model);
let functions = req.tools?.filter((it) => it.type === "function")?.map((it) => it.function) ?? [];
functions = functions.concat(req.functions ?? []);
const responseMimeType = req.response_format?.type === "json_object" ? "application/json" : "text/plain";
Expand Down
9 changes: 8 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,14 @@ export function openAiMessageToGeminiMessage(messages: OpenAI.Chat.ChatCompletio
}

export function genModel(req: OpenAI.Chat.ChatCompletionCreateParams): [GeminiModel, GenerateContentRequest] {
const model: GeminiModel = ModelMapping[req.model] ?? "gemini-1.0-pro-latest"
const defaultModel = (m: string): GeminiModel => {
if (m.startsWith("gemini")) {
return m as GeminiModel
}
return "gemini-1.5-flash-latest"
}

const model: GeminiModel = ModelMapping[req.model] ?? defaultModel(req.model)

let functions: OpenAI.Chat.FunctionObject[] =
req.tools?.filter((it) => it.type === "function")?.map((it) => it.function) ?? []
Expand Down

0 comments on commit 56b6927

Please sign in to comment.