fix: fix add api auth

This commit is contained in:
Fred Liang 2023-12-24 03:05:23 +08:00
parent 45798f993d
commit 4169431f2c
No known key found for this signature in database
GPG Key ID: 4DABDA85EF70EC71
3 changed files with 7 additions and 10 deletions

View File

@ -43,9 +43,8 @@ async function handle(
10 * 60 * 1000,
);
const fetchUrl = `${baseUrl}/${path}?key=${req.nextUrl.searchParams.get(
"key",
)}`;
const key = req.nextUrl.searchParams.get("key") ?? serverConfig.googleApiKey;
const fetchUrl = `${baseUrl}/${path}?key=${key}`;
const fetchOptions: RequestInit = {
headers: {

View File

@ -145,8 +145,8 @@ export function getHeaders() {
"Content-Type": "application/json",
"x-requested-with": "XMLHttpRequest",
};
const isGoogle = accessStore.provider === ServiceProvider.Google;
const modelConfig = useChatStore.getState().currentSession().mask.modelConfig;
const isGoogle = modelConfig.model === "gemini";
const isAzure = accessStore.provider === ServiceProvider.Azure;
const authHeader = isAzure ? "api-key" : "Authorization";
const apiKey = isGoogle

View File

@ -8,6 +8,7 @@ import {
import { prettyObject } from "@/app/utils/format";
import { getClientConfig } from "@/app/config/client";
import Locale from "../../locales";
import { getServerSideConfig } from "@/app/config/server";
export class GeminiApi implements LLMApi {
extractMessage(res: any) {
console.log("[Response] gemini response: ", res);
@ -30,8 +31,6 @@ export class GeminiApi implements LLMApi {
model: options.config.model,
},
};
const accessStore = useAccessStore.getState();
const requestPayload = {
contents: messages,
// stream: options.config.stream,
@ -44,7 +43,7 @@ export class GeminiApi implements LLMApi {
// Please do not ask me why not send max_tokens, no reason, this param is just shit, I dont want to explain anymore.
};
console.log("[Request] openai payload: ", requestPayload);
console.log("[Request] google payload: ", requestPayload);
// todo: support stream later
const shouldStream = false;
@ -52,8 +51,7 @@ export class GeminiApi implements LLMApi {
options.onController?.(controller);
try {
const chatPath =
this.path(Google.ChatPath) + `?key=${accessStore.googleApiKey}`;
const chatPath = this.path(Google.ChatPath);
const chatPayload = {
method: "POST",
body: JSON.stringify(requestPayload),