forked from XiaoMo/ChatGPT-Next-Web
fix: fix add api auth
This commit is contained in:
parent
45798f993d
commit
4169431f2c
@ -43,9 +43,8 @@ async function handle(
|
|||||||
10 * 60 * 1000,
|
10 * 60 * 1000,
|
||||||
);
|
);
|
||||||
|
|
||||||
const fetchUrl = `${baseUrl}/${path}?key=${req.nextUrl.searchParams.get(
|
const key = req.nextUrl.searchParams.get("key") ?? serverConfig.googleApiKey;
|
||||||
"key",
|
const fetchUrl = `${baseUrl}/${path}?key=${key}`;
|
||||||
)}`;
|
|
||||||
|
|
||||||
const fetchOptions: RequestInit = {
|
const fetchOptions: RequestInit = {
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -145,8 +145,8 @@ export function getHeaders() {
|
|||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"x-requested-with": "XMLHttpRequest",
|
"x-requested-with": "XMLHttpRequest",
|
||||||
};
|
};
|
||||||
|
const modelConfig = useChatStore.getState().currentSession().mask.modelConfig;
|
||||||
const isGoogle = accessStore.provider === ServiceProvider.Google;
|
const isGoogle = modelConfig.model === "gemini";
|
||||||
const isAzure = accessStore.provider === ServiceProvider.Azure;
|
const isAzure = accessStore.provider === ServiceProvider.Azure;
|
||||||
const authHeader = isAzure ? "api-key" : "Authorization";
|
const authHeader = isAzure ? "api-key" : "Authorization";
|
||||||
const apiKey = isGoogle
|
const apiKey = isGoogle
|
||||||
|
@ -8,6 +8,7 @@ import {
|
|||||||
import { prettyObject } from "@/app/utils/format";
|
import { prettyObject } from "@/app/utils/format";
|
||||||
import { getClientConfig } from "@/app/config/client";
|
import { getClientConfig } from "@/app/config/client";
|
||||||
import Locale from "../../locales";
|
import Locale from "../../locales";
|
||||||
|
import { getServerSideConfig } from "@/app/config/server";
|
||||||
export class GeminiApi implements LLMApi {
|
export class GeminiApi implements LLMApi {
|
||||||
extractMessage(res: any) {
|
extractMessage(res: any) {
|
||||||
console.log("[Response] gemini response: ", res);
|
console.log("[Response] gemini response: ", res);
|
||||||
@ -30,8 +31,6 @@ export class GeminiApi implements LLMApi {
|
|||||||
model: options.config.model,
|
model: options.config.model,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const accessStore = useAccessStore.getState();
|
|
||||||
|
|
||||||
const requestPayload = {
|
const requestPayload = {
|
||||||
contents: messages,
|
contents: messages,
|
||||||
// stream: options.config.stream,
|
// 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.
|
// 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
|
// todo: support stream later
|
||||||
const shouldStream = false;
|
const shouldStream = false;
|
||||||
@ -52,8 +51,7 @@ export class GeminiApi implements LLMApi {
|
|||||||
options.onController?.(controller);
|
options.onController?.(controller);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const chatPath =
|
const chatPath = this.path(Google.ChatPath);
|
||||||
this.path(Google.ChatPath) + `?key=${accessStore.googleApiKey}`;
|
|
||||||
const chatPayload = {
|
const chatPayload = {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify(requestPayload),
|
body: JSON.stringify(requestPayload),
|
||||||
|
Loading…
Reference in New Issue
Block a user