Skip to content

Commit

Permalink
Merge pull request ChatGPTNextWeb#4710 from Kivi1998/chatGPT
Browse files Browse the repository at this point in the history
Chat gpt
  • Loading branch information
Dean-YZG authored May 20, 2024
2 parents c3e2f3b + 7f3516f commit 754acd7
Show file tree
Hide file tree
Showing 38 changed files with 658 additions and 715 deletions.
22 changes: 10 additions & 12 deletions app/api/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,24 +112,23 @@ export async function requestOpenai(req: NextRequest) {
try {
const res = await fetch(fetchUrl, fetchOptions);

// Extract the OpenAI-Organization header from the response
const openaiOrganizationHeader = res.headers.get("OpenAI-Organization");

// Check if serverConfig.openaiOrgId is defined and not an empty string
if (serverConfig.openaiOrgId && serverConfig.openaiOrgId.trim() !== "") {
// If openaiOrganizationHeader is present, log it; otherwise, log that the header is not present
console.log("[Org ID]", openaiOrganizationHeader);
} else {
console.log("[Org ID] is not set up.");
}
// Extract the OpenAI-Organization header from the response
const openaiOrganizationHeader = res.headers.get("OpenAI-Organization");

// Check if serverConfig.openaiOrgId is defined and not an empty string
if (serverConfig.openaiOrgId && serverConfig.openaiOrgId.trim() !== "") {
// If openaiOrganizationHeader is present, log it; otherwise, log that the header is not present
console.log("[Org ID]", openaiOrganizationHeader);
} else {
console.log("[Org ID] is not set up.");
}

// to prevent browser prompt for credentials
const newHeaders = new Headers(res.headers);
newHeaders.delete("www-authenticate");
// to disable nginx buffering
newHeaders.set("X-Accel-Buffering", "no");


// Conditionally delete the OpenAI-Organization header from the response if [Org ID] is undefined or empty (not setup in ENV)
// Also, this is to prevent the header from being sent to the client
if (!serverConfig.openaiOrgId || serverConfig.openaiOrgId.trim() === "") {
Expand All @@ -142,7 +141,6 @@ export async function requestOpenai(req: NextRequest) {
// The browser will try to decode the response with brotli and fail
newHeaders.delete("content-encoding");


return new Response(res.body, {
status: res.status,
statusText: res.statusText,
Expand Down
6 changes: 4 additions & 2 deletions app/client/platforms/google.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ export class GeminiProApi implements LLMApi {

if (!baseUrl) {
baseUrl = isApp
? DEFAULT_API_HOST + "/api/proxy/google/" + Google.ChatPath(modelConfig.model)
? DEFAULT_API_HOST +
"/api/proxy/google/" +
Google.ChatPath(modelConfig.model)
: this.path(Google.ChatPath(modelConfig.model));
}

Expand All @@ -139,7 +141,7 @@ export class GeminiProApi implements LLMApi {
() => controller.abort(),
REQUEST_TIMEOUT_MS,
);

if (shouldStream) {
let responseText = "";
let remainText = "";
Expand Down
54 changes: 27 additions & 27 deletions app/components/auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,33 +50,33 @@ export function AuthPage() {
);
}}
/>
{!accessStore.hideUserApiKey ? (
<>
<div className={styles["auth-tips"]}>{Locale.Auth.SubTips}</div>
<input
className={styles["auth-input"]}
type="password"
placeholder={Locale.Settings.Access.OpenAI.ApiKey.Placeholder}
value={accessStore.openaiApiKey}
onChange={(e) => {
accessStore.update(
(access) => (access.openaiApiKey = e.currentTarget.value),
);
}}
/>
<input
className={styles["auth-input"]}
type="password"
placeholder={Locale.Settings.Access.Google.ApiKey.Placeholder}
value={accessStore.googleApiKey}
onChange={(e) => {
accessStore.update(
(access) => (access.googleApiKey = e.currentTarget.value),
);
}}
/>
</>
) : null}
{/*{!accessStore.hideUserApiKey ? (*/}
{/* <>*/}
{/* <div className={styles["auth-tips"]}>{Locale.Auth.SubTips}</div>*/}
{/* <input*/}
{/* className={styles["auth-input"]}*/}
{/* type="password"*/}
{/* placeholder={Locale.Settings.Access.OpenAI.ApiKey.Placeholder}*/}
{/* value={accessStore.openaiApiKey}*/}
{/* onChange={(e) => {*/}
{/* accessStore.update(*/}
{/* (access) => (access.openaiApiKey = e.currentTarget.value),*/}
{/* );*/}
{/* }}*/}
{/* />*/}
{/* <input*/}
{/* className={styles["auth-input"]}*/}
{/* type="password"*/}
{/* placeholder={Locale.Settings.Access.Google.ApiKey.Placeholder}*/}
{/* value={accessStore.googleApiKey}*/}
{/* onChange={(e) => {*/}
{/* accessStore.update(*/}
{/* (access) => (access.googleApiKey = e.currentTarget.value),*/}
{/* );*/}
{/* }}*/}
{/* />*/}
{/* </>*/}
{/*) : null}*/}

<div className={styles["auth-actions"]}>
<IconButton
Expand Down
185 changes: 92 additions & 93 deletions app/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -491,79 +491,79 @@ export function ChatActions(props: {

return (
<div className={styles["chat-input-actions"]}>
{couldStop && (
<ChatAction
onClick={stopAll}
text={Locale.Chat.InputActions.Stop}
icon={<StopIcon />}
/>
)}
{!props.hitBottom && (
<ChatAction
onClick={props.scrollToBottom}
text={Locale.Chat.InputActions.ToBottom}
icon={<BottomIcon />}
/>
)}
{props.hitBottom && (
<ChatAction
onClick={props.showPromptModal}
text={Locale.Chat.InputActions.Settings}
icon={<SettingsIcon />}
/>
)}

{showUploadImage && (
<ChatAction
onClick={props.uploadImage}
text={Locale.Chat.InputActions.UploadImage}
icon={props.uploading ? <LoadingButtonIcon /> : <ImageIcon />}
/>
)}
<ChatAction
onClick={nextTheme}
text={Locale.Chat.InputActions.Theme[theme]}
icon={
<>
{theme === Theme.Auto ? (
<AutoIcon />
) : theme === Theme.Light ? (
<LightIcon />
) : theme === Theme.Dark ? (
<DarkIcon />
) : null}
</>
}
/>

<ChatAction
onClick={props.showPromptHints}
text={Locale.Chat.InputActions.Prompt}
icon={<PromptIcon />}
/>

<ChatAction
onClick={() => {
navigate(Path.Masks);
}}
text={Locale.Chat.InputActions.Masks}
icon={<MaskIcon />}
/>

<ChatAction
text={Locale.Chat.InputActions.Clear}
icon={<BreakIcon />}
onClick={() => {
chatStore.updateCurrentSession((session) => {
if (session.clearContextIndex === session.messages.length) {
session.clearContextIndex = undefined;
} else {
session.clearContextIndex = session.messages.length;
session.memoryPrompt = ""; // will clear memory
}
});
}}
/>
{/*{couldStop && (*/}
{/* <ChatAction*/}
{/* onClick={stopAll}*/}
{/* text={Locale.Chat.InputActions.Stop}*/}
{/* icon={<StopIcon />}*/}
{/* />*/}
{/*)}*/}
{/*{!props.hitBottom && (*/}
{/* <ChatAction*/}
{/* onClick={props.scrollToBottom}*/}
{/* text={Locale.Chat.InputActions.ToBottom}*/}
{/* icon={<BottomIcon />}*/}
{/* />*/}
{/*)}*/}
{/*{props.hitBottom && (*/}
{/* <ChatAction*/}
{/* onClick={props.showPromptModal}*/}
{/* text={Locale.Chat.InputActions.Settings}*/}
{/* icon={<SettingsIcon />}*/}
{/* />*/}
{/*)}*/}

{/*{showUploadImage && (*/}
{/* <ChatAction*/}
{/* onClick={props.uploadImage}*/}
{/* text={Locale.Chat.InputActions.UploadImage}*/}
{/* icon={props.uploading ? <LoadingButtonIcon /> : <ImageIcon />}*/}
{/* />*/}
{/*)}*/}
{/*<ChatAction*/}
{/* onClick={nextTheme}*/}
{/* text={Locale.Chat.InputActions.Theme[theme]}*/}
{/* icon={*/}
{/* <>*/}
{/* {theme === Theme.Auto ? (*/}
{/* <AutoIcon />*/}
{/* ) : theme === Theme.Light ? (*/}
{/* <LightIcon />*/}
{/* ) : theme === Theme.Dark ? (*/}
{/* <DarkIcon />*/}
{/* ) : null}*/}
{/* </>*/}
{/* }*/}
{/*/>*/}

{/*<ChatAction*/}
{/* onClick={props.showPromptHints}*/}
{/* text={Locale.Chat.InputActions.Prompt}*/}
{/* icon={<PromptIcon />}*/}
{/*/>*/}

{/*<ChatAction*/}
{/* onClick={() => {*/}
{/* navigate(Path.Masks);*/}
{/* }}*/}
{/* text={Locale.Chat.InputActions.Masks}*/}
{/* icon={<MaskIcon />}*/}
{/*/>*/}

{/*<ChatAction*/}
{/* text={Locale.Chat.InputActions.Clear}*/}
{/* icon={<BreakIcon />}*/}
{/* onClick={() => {*/}
{/* chatStore.updateCurrentSession((session) => {*/}
{/* if (session.clearContextIndex === session.messages.length) {*/}
{/* session.clearContextIndex = undefined;*/}
{/* } else {*/}
{/* session.clearContextIndex = session.messages.length;*/}
{/* session.memoryPrompt = ""; // will clear memory*/}
{/* }*/}
{/* });*/}
{/* }}*/}
{/*/>*/}

<ChatAction
onClick={() => setShowModelSelector(true)}
Expand Down Expand Up @@ -1089,7 +1089,6 @@ function _Chat() {
if (payload.url) {
accessStore.update((access) => (access.openaiUrl = payload.url!));
}
accessStore.update((access) => (access.useCustomConfig = true));
});
}
} catch {
Expand Down Expand Up @@ -1234,25 +1233,25 @@ function _Chat() {
</div>
</div>
<div className="window-actions">
{!isMobileScreen && (
<div className="window-action-button">
<IconButton
icon={<RenameIcon />}
bordered
onClick={() => setIsEditingMessage(true)}
/>
</div>
)}
<div className="window-action-button">
<IconButton
icon={<ExportIcon />}
bordered
title={Locale.Chat.Actions.Export}
onClick={() => {
setShowExport(true);
}}
/>
</div>
{/*{!isMobileScreen && (*/}
{/* <div className="window-action-button">*/}
{/* <IconButton*/}
{/* icon={<RenameIcon />}*/}
{/* bordered*/}
{/* onClick={() => setIsEditingMessage(true)}*/}
{/* />*/}
{/* </div>*/}
{/*)}*/}
{/*<div className="window-action-button">*/}
{/* <IconButton*/}
{/* icon={<ExportIcon />}*/}
{/* bordered*/}
{/* title={Locale.Chat.Actions.Export}*/}
{/* onClick={() => {*/}
{/* setShowExport(true);*/}
{/* }}*/}
{/* />*/}
{/*</div>*/}
{showMaxIcon && (
<div className="window-action-button">
<IconButton
Expand Down
Loading

0 comments on commit 754acd7

Please sign in to comment.