mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-05-28 08:30:19 +09:00
fix: docker rag bug
This commit is contained in:
parent
b00e9f0c79
commit
dc4137505e
@ -55,7 +55,7 @@ NEXT_PUBLIC_ENABLE_NODEJS_PLUGIN=1
|
||||
# (optional)
|
||||
# Default: Empty
|
||||
# If you want to enable RAG, set this value to 1.
|
||||
NEXT_PUBLIC_ENABLE_RAG=
|
||||
ENABLE_RAG=
|
||||
|
||||
# (optional)
|
||||
# Default: Empty
|
||||
|
@ -13,6 +13,7 @@ const DANGER_CONFIG = {
|
||||
hideBalanceQuery: serverConfig.hideBalanceQuery,
|
||||
disableFastLink: serverConfig.disableFastLink,
|
||||
customModels: serverConfig.customModels,
|
||||
isEnableRAG: serverConfig.isEnableRAG,
|
||||
};
|
||||
|
||||
declare global {
|
||||
|
@ -21,14 +21,9 @@ async function handle(req: NextRequest) {
|
||||
try {
|
||||
const formData = await req.formData();
|
||||
const file = formData.get("file") as File;
|
||||
const fileData = await file.arrayBuffer();
|
||||
const originalFileName = file?.name;
|
||||
|
||||
let fileData: ArrayBuffer | undefined;
|
||||
for (const [key, value] of formData.entries()) {
|
||||
if (value instanceof File) {
|
||||
fileData = await value.arrayBuffer();
|
||||
}
|
||||
}
|
||||
if (!fileData) throw new Error("Get file buffer error");
|
||||
const buffer = Buffer.from(fileData);
|
||||
const fileType = path.extname(originalFileName).slice(1);
|
||||
|
@ -60,7 +60,7 @@ export class NodeJSTool {
|
||||
wolframAlphaTool,
|
||||
pdfBrowserTool,
|
||||
];
|
||||
if (!!process.env.NEXT_PUBLIC_ENABLE_RAG) {
|
||||
if (!!process.env.ENABLE_RAG) {
|
||||
tools.push(new RAGSearch(this.sessionId, this.model, this.ragEmbeddings));
|
||||
}
|
||||
return tools;
|
||||
|
@ -37,6 +37,8 @@ export class RAGSearch extends Tool {
|
||||
/** @ignore */
|
||||
async _call(inputs: string, runManager?: CallbackManagerForToolRun) {
|
||||
const serverConfig = getServerSideConfig();
|
||||
if (!serverConfig.isEnableRAG)
|
||||
throw new Error("env ENABLE_RAG not configured");
|
||||
// const pinecone = new Pinecone();
|
||||
// const pineconeIndex = pinecone.Index(serverConfig.pineconeIndex!);
|
||||
// const vectorStore = await PineconeStore.fromExistingIndex(this.embeddings, {
|
||||
|
@ -117,7 +117,6 @@ import {
|
||||
SpeechApi,
|
||||
WebTranscriptionApi,
|
||||
} from "../utils/speech";
|
||||
import { getServerSideConfig } from "../config/server";
|
||||
import { FileInfo } from "../client/platforms/utils";
|
||||
|
||||
const ttsPlayer = createTTSPlayer();
|
||||
@ -507,14 +506,18 @@ export function ChatActions(props: {
|
||||
);
|
||||
const [showModelSelector, setShowModelSelector] = useState(false);
|
||||
const [showUploadImage, setShowUploadImage] = useState(false);
|
||||
|
||||
const [showUploadFile, setShowUploadFile] = useState(false);
|
||||
|
||||
const accessStore = useAccessStore();
|
||||
const isEnableRAG = useMemo(
|
||||
() => accessStore.enableRAG(),
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
[],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const show = isVisionModel(currentModel);
|
||||
setShowUploadImage(show);
|
||||
const isEnableRAG = !!process.env.NEXT_PUBLIC_ENABLE_RAG;
|
||||
setShowUploadFile(isEnableRAG && !show && isSupportRAGModel(currentModel));
|
||||
if (!show) {
|
||||
props.setAttachImages([]);
|
||||
|
@ -112,7 +112,7 @@ export const getServerSideConfig = () => {
|
||||
!process.env.R2_ACCOUNT_ID &&
|
||||
!process.env.S3_ENDPOINT,
|
||||
|
||||
isEnableRAG: !!process.env.NEXT_PUBLIC_ENABLE_RAG,
|
||||
isEnableRAG: !!process.env.ENABLE_RAG,
|
||||
ragEmbeddingModel:
|
||||
process.env.RAG_EMBEDDING_MODEL ?? "text-embedding-3-large",
|
||||
ragChunkSize: process.env.RAG_CHUNK_SIZE ?? "2000",
|
||||
|
@ -56,8 +56,10 @@ export const useAccessStore = createPersistStore(
|
||||
return get().needCode;
|
||||
},
|
||||
|
||||
isEnableRAG() {
|
||||
return ensure(get(), ["isEnableRAG"]);
|
||||
enableRAG() {
|
||||
this.fetch();
|
||||
|
||||
return get().isEnableRAG;
|
||||
},
|
||||
|
||||
isValidOpenAI() {
|
||||
|
@ -374,9 +374,9 @@ export const useChatStore = createPersistStore(
|
||||
session.messages.push(savedUserMessage);
|
||||
session.messages.push(botMessage);
|
||||
});
|
||||
const isEnableRAG = attachFiles && attachFiles?.length > 0;
|
||||
var api: ClientApi;
|
||||
api = new ClientApi(ModelProvider.GPT);
|
||||
const isEnableRAG = !!process.env.NEXT_PUBLIC_ENABLE_RAG;
|
||||
if (
|
||||
config.pluginConfig.enable &&
|
||||
session.mask.usePlugins &&
|
||||
|
@ -3,6 +3,7 @@ import { showToast } from "./components/ui-lib";
|
||||
import Locale from "./locales";
|
||||
import { RequestMessage } from "./client/api";
|
||||
import { DEFAULT_MODELS } from "./constant";
|
||||
import { useAccessStore } from "./store";
|
||||
|
||||
export function trimTopic(topic: string) {
|
||||
// Fix an issue where double quotes still show in the Indonesian language
|
||||
|
@ -41,7 +41,7 @@
|
||||
|
||||
## 环境变量
|
||||
|
||||
### `NEXT_PUBLIC_ENABLE_RAG`
|
||||
### `ENABLE_RAG`
|
||||
|
||||
如果你想启用 RAG 功能,将此环境变量设置为 1 即可。
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user