Sfoglia il codice sorgente

Merge pull request #4412 from RubuJam/main

Gemini will generate the request address based on the selected model name and supports Gemini 1.5 Pro (gemini-1.5-pro-latest).
DeanYao 1 anno fa
parent
commit
1e2a662fa6
3 ha cambiato i file con 24 aggiunte e 8 eliminazioni
  1. 2 2
      app/client/platforms/google.ts
  2. 13 5
      app/constant.ts
  3. 9 1
      app/utils.ts

+ 2 - 2
app/client/platforms/google.ts

@@ -112,8 +112,8 @@ export class GeminiProApi implements LLMApi {
     options.onController?.(controller);
     try {
       let googleChatPath = visionModel
-        ? Google.VisionChatPath
-        : Google.ChatPath;
+        ? Google.VisionChatPath(modelConfig.model)
+        : Google.ChatPath(modelConfig.model);
       let chatPath = this.path(googleChatPath);
 
       // let baseUrl = accessStore.googleUrl;

+ 13 - 5
app/constant.ts

@@ -98,10 +98,8 @@ export const Azure = {
 
 export const Google = {
   ExampleEndpoint: "https://generativelanguage.googleapis.com/",
-  ChatPath: "v1beta/models/gemini-pro:generateContent",
-  VisionChatPath: "v1beta/models/gemini-pro-vision:generateContent",
-
-  // /api/openai/v1/chat/completions
+  ChatPath: (modelName: string) => `v1beta/models/${modelName}:generateContent`,
+  VisionChatPath: (modelName: string) => `v1beta/models/${modelName}:generateContent`,
 };
 
 export const DEFAULT_INPUT_TEMPLATE = `{{input}}`; // input / time / model / lang
@@ -136,6 +134,7 @@ export const KnowledgeCutOffDate: Record<string, string> = {
   // After improvements,
   // it's now easier to add "KnowledgeCutOffDate" instead of stupid hardcoding it, as was done previously.
   "gemini-pro": "2023-12",
+  "gemini-pro-vision": "2023-12",
 };
 
 export const DEFAULT_MODELS = [
@@ -311,7 +310,16 @@ export const DEFAULT_MODELS = [
     },
   },
   {
-    name: "gemini-pro",
+    name: "gemini-1.0-pro",
+    available: true,
+    provider: {
+      id: "google",
+      providerName: "Google",
+      providerType: "google",
+    },
+  },
+  {
+    name: "gemini-1.5-pro-latest",
     available: true,
     provider: {
       id: "google",

+ 9 - 1
app/utils.ts

@@ -290,7 +290,15 @@ export function getMessageImages(message: RequestMessage): string[] {
 }
 
 export function isVisionModel(model: string) {
-  const visionKeywords = ["vision", "claude-3"];
+  
+  // Note: This is a better way using the TypeScript feature instead of `&&` or `||` (ts v5.5.0-dev.20240314 I've been using)
+
+  const visionKeywords = [
+    "vision",
+    "claude-3",
+    "gemini-1.5-pro",
+  ];
+
   const isGpt4Turbo = model.includes("gpt-4-turbo") && !model.includes("preview");
 
   return visionKeywords.some((keyword) => model.includes(keyword)) || isGpt4Turbo;