This commit is contained in:
GH Action - Upstream Sync 2023-04-15 00:59:39 +00:00
commit faafb45d83
6 changed files with 33 additions and 45 deletions

View File

@ -97,6 +97,7 @@ We recommend that you follow the steps below to re-deploy:
- Choose and deploy in Vercel again, [please see the detailed tutorial](./docs/vercel-cn.md). - Choose and deploy in Vercel again, [please see the detailed tutorial](./docs/vercel-cn.md).
### Enable Automatic Updates ### Enable Automatic Updates
After forking the project, due to the limitations imposed by Github, you need to manually enable Workflows and Upstream Sync Action on the Actions page of the forked project. Once enabled, automatic updates will be scheduled every hour: After forking the project, due to the limitations imposed by Github, you need to manually enable Workflows and Upstream Sync Action on the Actions page of the forked project. Once enabled, automatic updates will be scheduled every hour:
![Automatic Updates](./docs/images/enable-actions.jpg) ![Automatic Updates](./docs/images/enable-actions.jpg)
@ -104,6 +105,7 @@ After forking the project, due to the limitations imposed by Github, you need to
![Enable Automatic Updates](./docs/images/enable-actions-sync.jpg) ![Enable Automatic Updates](./docs/images/enable-actions-sync.jpg)
### Manually Updating Code ### Manually Updating Code
If you want to update instantly, you can check out the [Github documentation](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork) to learn how to synchronize a forked project with upstream code. If you want to update instantly, you can check out the [Github documentation](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork) to learn how to synchronize a forked project with upstream code.
You can star or watch this project or follow author to get release notifictions in time. You can star or watch this project or follow author to get release notifictions in time.
@ -134,18 +136,12 @@ Access passsword, separated by comma.
### `BASE_URL` (optional) ### `BASE_URL` (optional)
> Default: `api.openai.com` > Default: `https://api.openai.com`
> Examples: `http://your-openai-proxy.com`
Override openai api request base url. Override openai api request base url.
### `PROTOCOL` (optional)
> Default: `https`
> Values: `http` | `https`
Override openai api request protocol.
## Development ## Development
> [简体中文 > 如何进行二次开发](./README_CN.md#开发) > [简体中文 > 如何进行二次开发](./README_CN.md#开发)

View File

@ -43,6 +43,7 @@
- 在 Vercel 重新选择并部署,[请查看详细教程](./docs/vercel-cn.md#如何新建项目)。 - 在 Vercel 重新选择并部署,[请查看详细教程](./docs/vercel-cn.md#如何新建项目)。
### 打开自动更新 ### 打开自动更新
当你 fork 项目之后,由于 Github 的限制,需要手动去你 fork 后的项目的 Actions 页面启用 Workflows并启用 Upstream Sync Action启用之后即可开启每小时定时自动更新 当你 fork 项目之后,由于 Github 的限制,需要手动去你 fork 后的项目的 Actions 页面启用 Workflows并启用 Upstream Sync Action启用之后即可开启每小时定时自动更新
![自动更新](./docs/images/enable-actions.jpg) ![自动更新](./docs/images/enable-actions.jpg)
@ -85,17 +86,13 @@ OpanAI 密钥,你在 openai 账户页面申请的 api key。
### `BASE_URL` (可选) ### `BASE_URL` (可选)
> Default: `api.openai.com` > Default: `https://api.openai.com`
> Examples: `http://your-openai-proxy.com`
OpenAI 接口代理 URL如果你手动配置了 openai 接口代理,请填写此选项。 OpenAI 接口代理 URL如果你手动配置了 openai 接口代理,请填写此选项。
### `PROTOCOL` (可选) > 如果遇到 ssl 证书问题,请将 `BASE_URL` 的协议设置为 http。
> Default: `https`
> Values: `http` | `https`
OpenAI 代理接口协议,如果遇到 ssl 证书问题,请尝试通过此选项设置为 http。
## 开发 ## 开发

View File

@ -9,9 +9,16 @@ export async function requestOpenai(req: NextRequest) {
const apiKey = req.headers.get("token"); const apiKey = req.headers.get("token");
const openaiPath = req.headers.get("path"); const openaiPath = req.headers.get("path");
console.log("[Proxy] ", openaiPath); let baseUrl = BASE_URL;
return fetch(`${PROTOCOL}://${BASE_URL}/${openaiPath}`, { if (!baseUrl.startsWith("http")) {
baseUrl = `${PROTOCOL}://${baseUrl}`;
}
console.log("[Proxy] ", openaiPath);
console.log("[Base Url]", baseUrl);
return fetch(`${baseUrl}/${openaiPath}`, {
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
Authorization: `Bearer ${apiKey}`, Authorization: `Bearer ${apiKey}`,

View File

@ -3,6 +3,7 @@ import { memo, useState, useRef, useEffect, useLayoutEffect } from "react";
import SendWhiteIcon from "../icons/send-white.svg"; import SendWhiteIcon from "../icons/send-white.svg";
import BrainIcon from "../icons/brain.svg"; import BrainIcon from "../icons/brain.svg";
import RenameIcon from "../icons/rename.svg";
import ExportIcon from "../icons/share.svg"; import ExportIcon from "../icons/share.svg";
import ReturnIcon from "../icons/return.svg"; import ReturnIcon from "../icons/return.svg";
import CopyIcon from "../icons/copy.svg"; import CopyIcon from "../icons/copy.svg";
@ -442,16 +443,6 @@ export function Chat(props: {
inputRef.current?.focus(); inputRef.current?.focus();
}; };
const scrollInput = () => {
const dom = inputRef.current;
if (!dom) return;
const paddingBottomNum: number = parseInt(
window.getComputedStyle(dom).paddingBottom,
10,
);
dom.scrollTop = dom.scrollHeight - dom.offsetHeight + paddingBottomNum;
};
// auto grow input // auto grow input
const [inputRows, setInputRows] = useState(2); const [inputRows, setInputRows] = useState(2);
const measure = useDebouncedCallback( const measure = useDebouncedCallback(
@ -476,7 +467,6 @@ export function Chat(props: {
// only search prompts when user input is short // only search prompts when user input is short
const SEARCH_TEXT_LIMIT = 30; const SEARCH_TEXT_LIMIT = 30;
const onInput = (text: string) => { const onInput = (text: string) => {
scrollInput();
setUserInput(text); setUserInput(text);
const n = text.trim().length; const n = text.trim().length;
@ -600,6 +590,13 @@ export function Chat(props: {
const [showPromptModal, setShowPromptModal] = useState(false); const [showPromptModal, setShowPromptModal] = useState(false);
const renameSession = () => {
const newTopic = prompt(Locale.Chat.Rename, session.topic);
if (newTopic && newTopic !== session.topic) {
chatStore.updateCurrentSession((session) => (session.topic = newTopic!));
}
};
// Auto focus // Auto focus
useEffect(() => { useEffect(() => {
if (props.sideBarShowing && isMobileScreen()) return; if (props.sideBarShowing && isMobileScreen()) return;
@ -613,14 +610,7 @@ export function Chat(props: {
<div className={styles["window-header-title"]}> <div className={styles["window-header-title"]}>
<div <div
className={`${styles["window-header-main-title"]} ${styles["chat-body-title"]}`} className={`${styles["window-header-main-title"]} ${styles["chat-body-title"]}`}
onClickCapture={() => { onClickCapture={renameSession}
const newTopic = prompt(Locale.Chat.Rename, session.topic);
if (newTopic && newTopic !== session.topic) {
chatStore.updateCurrentSession(
(session) => (session.topic = newTopic!),
);
}
}}
> >
{session.topic} {session.topic}
</div> </div>
@ -639,12 +629,9 @@ export function Chat(props: {
</div> </div>
<div className={styles["window-action-button"]}> <div className={styles["window-action-button"]}>
<IconButton <IconButton
icon={<BrainIcon />} icon={<RenameIcon />}
bordered bordered
title={Locale.Chat.Actions.CompressedHistory} onClick={renameSession}
onClick={() => {
setShowPromptModal(true);
}}
/> />
</div> </div>
<div className={styles["window-action-button"]}> <div className={styles["window-action-button"]}>

1
app/icons/rename.svg Normal file
View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16" fill="none"><defs><rect id="path_0" x="0" y="0" width="16" height="16" /></defs><g opacity="1" transform="translate(0 0) rotate(0 8 8)"><mask id="bg-mask-0" fill="white"><use xlink:href="#path_0"></use></mask><g mask="url(#bg-mask-0)" ><path id="路径 1" style="stroke:#333333; stroke-width:1.3333333333333333; stroke-opacity:1; stroke-dasharray:0 0" transform="translate(1.774903333333333 1.3006199999999999) rotate(0 6.599664999999999 6.599656666666666)" d="M2.83,13.2L13.2,2.83L10.37,0L0,10.37L0,13.2L2.83,13.2Z " /><path id="路径 2" style="stroke:#333333; stroke-width:1.3333333333333333; stroke-opacity:1; stroke-dasharray:0 0" transform="translate(9.317366666666667 4.129066666666667) rotate(0 1.4142166666666658 1.4142166666666665)" d="M0,0L2.83,2.83 " /></g></g></svg>

After

Width:  |  Height:  |  Size: 911 B

View File

@ -152,9 +152,9 @@ const tw: LocaleType = {
Prompt: { Prompt: {
History: (content: string) => History: (content: string) =>
"這是 AI 與用戶的歷史聊天總結,作為前情提要:" + content, "這是 AI 與用戶的歷史聊天總結,作為前情提要:" + content,
Topic: "直接返回這句話的簡要主題,無須解釋,若無主題,請直接返回「閒聊」", Topic: "Summarise the conversation in a short and concise eye-catching title that instantly conveys the main topic. Use as few words as possible. Use the language used in the enquiry, e.g. use English for English enquiry, use zh-hant for traditional chinese enquiry. Don't use quotation marks at the beginning and the end.",
Summarize: Summarize:
"簡要總結一下你和用戶的對話,作為後續的上下文提示 prompt且字數控制在 200 字以內", "Summarise the conversation in at most 250 tokens for continuing the conversation in future. Use the language used in the conversation, e.g. use English for English conversation, use zh-hant for traditional chinese conversation.",
}, },
ConfirmClearAll: "確認清除所有對話、設定數據?", ConfirmClearAll: "確認清除所有對話、設定數據?",
}, },