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