mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-11-15 05:23:42 +08:00
feat: optimize rag
This commit is contained in:
@@ -89,7 +89,7 @@ export class ClaudeApi implements LLMApi {
|
||||
toolAgentChat(options: AgentChatOptions): Promise<void> {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
createRAGStore(options: CreateRAGStoreOptions): Promise<void> {
|
||||
createRAGStore(options: CreateRAGStoreOptions): Promise<string> {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
extractMessage(res: any) {
|
||||
|
||||
@@ -20,7 +20,7 @@ import {
|
||||
} from "@/app/utils";
|
||||
|
||||
export class GeminiProApi implements LLMApi {
|
||||
createRAGStore(options: CreateRAGStoreOptions): Promise<void> {
|
||||
createRAGStore(options: CreateRAGStoreOptions): Promise<string> {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
transcription(options: TranscriptionOptions): Promise<string> {
|
||||
|
||||
@@ -373,7 +373,7 @@ export class ChatGPTApi implements LLMApi {
|
||||
}
|
||||
}
|
||||
|
||||
async createRAGStore(options: CreateRAGStoreOptions): Promise<void> {
|
||||
async createRAGStore(options: CreateRAGStoreOptions): Promise<string> {
|
||||
try {
|
||||
const accessStore = useAccessStore.getState();
|
||||
const isAzure = accessStore.provider === ServiceProvider.Azure;
|
||||
@@ -395,9 +395,12 @@ export class ChatGPTApi implements LLMApi {
|
||||
};
|
||||
const res = await fetch(path, chatPayload);
|
||||
if (res.status !== 200) throw new Error(await res.text());
|
||||
const resJson = await res.json();
|
||||
return resJson.partial;
|
||||
} catch (e) {
|
||||
console.log("[Request] failed to make a chat reqeust", e);
|
||||
options.onError?.(e as Error);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import { getHeaders } from "../api";
|
||||
import { getClientApi } from "@/app/utils";
|
||||
import { ClientApi, getHeaders } from "../api";
|
||||
import { ChatSession } from "@/app/store";
|
||||
|
||||
export interface FileInfo {
|
||||
originalFilename: string;
|
||||
fileName: string;
|
||||
filePath: string;
|
||||
size: number;
|
||||
partial?: string;
|
||||
}
|
||||
|
||||
export class FileApi {
|
||||
@@ -31,4 +34,15 @@ export class FileApi {
|
||||
filePath: resJson.filePath,
|
||||
};
|
||||
}
|
||||
|
||||
async uploadForRag(file: any, session: ChatSession): Promise<FileInfo> {
|
||||
var fileInfo = await this.upload(file);
|
||||
var api: ClientApi = getClientApi(session.mask.modelConfig.model);
|
||||
let partial = await api.llm.createRAGStore({
|
||||
chatSessionId: session.id,
|
||||
fileInfos: [fileInfo],
|
||||
});
|
||||
fileInfo.partial = partial;
|
||||
return fileInfo;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user