mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-11-15 13:33:43 +08:00
feat: support gemini pro
This commit is contained in:
@@ -2,6 +2,7 @@ import { getClientConfig } from "../config/client";
|
||||
import { ACCESS_CODE_PREFIX, Azure, ServiceProvider } from "../constant";
|
||||
import { ChatMessage, ModelType, useAccessStore } from "../store";
|
||||
import { ChatGPTApi } from "./platforms/openai";
|
||||
import { GeminiApi } from "./platforms/google";
|
||||
import { FileApi } from "./platforms/utils";
|
||||
|
||||
export const ROLES = ["system", "user", "assistant"] as const;
|
||||
@@ -105,6 +106,11 @@ export class ClientApi {
|
||||
this.file = new FileApi();
|
||||
}
|
||||
|
||||
switch(model: string) {
|
||||
if (model.startsWith("gemini")) this.llm = new GeminiApi();
|
||||
else this.llm = new ChatGPTApi();
|
||||
}
|
||||
|
||||
config() {}
|
||||
|
||||
prompts() {}
|
||||
@@ -207,3 +213,31 @@ export function getHeaders() {
|
||||
|
||||
return headers;
|
||||
}
|
||||
|
||||
export function getGeminiHeaders() {
|
||||
const accessStore = useAccessStore.getState();
|
||||
const headers: Record<string, string> = {
|
||||
"Content-Type": "application/json",
|
||||
"x-requested-with": "XMLHttpRequest",
|
||||
};
|
||||
|
||||
const authHeader = "Authorization";
|
||||
const apiKey = accessStore.googleApiKey;
|
||||
|
||||
const makeBearer = (s: string) => `${"Bearer "}${s.trim()}`;
|
||||
const validString = (x: string) => x && x.length > 0;
|
||||
|
||||
// use user's api key first
|
||||
if (validString(apiKey)) {
|
||||
headers[authHeader] = makeBearer(apiKey);
|
||||
} else if (
|
||||
accessStore.enabledAccessControl() &&
|
||||
validString(accessStore.accessCode)
|
||||
) {
|
||||
headers[authHeader] = makeBearer(
|
||||
ACCESS_CODE_PREFIX + accessStore.accessCode,
|
||||
);
|
||||
}
|
||||
|
||||
return headers;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user