mirror of
https://github.com/arc53/DocsGPT.git
synced 2025-11-29 08:33:20 +00:00
refactor: use list instead of string parsing
This commit is contained in:
@@ -46,17 +46,10 @@ class ClassicRAG(BaseRetriever):
|
||||
user_api_key=self.user_api_key,
|
||||
decoded_token=decoded_token,
|
||||
)
|
||||
if "active_docs" in source:
|
||||
|
||||
if "active_docs" in source and source["active_docs"] is not None:
|
||||
if isinstance(source["active_docs"], list):
|
||||
self.vectorstores = source["active_docs"]
|
||||
elif (
|
||||
isinstance(source["active_docs"], str) and "," in source["active_docs"]
|
||||
):
|
||||
self.vectorstores = [
|
||||
doc_id.strip()
|
||||
for doc_id in source["active_docs"].split(",")
|
||||
if doc_id.strip()
|
||||
]
|
||||
else:
|
||||
self.vectorstores = [source["active_docs"]]
|
||||
else:
|
||||
|
||||
@@ -17,7 +17,7 @@ type SourcesPopupProps = {
|
||||
isOpen: boolean;
|
||||
onClose: () => void;
|
||||
anchorRef: React.RefObject<HTMLButtonElement | null>;
|
||||
handlePostDocumentSelect: (doc: Doc | null) => void;
|
||||
handlePostDocumentSelect: (doc: Doc[] | null) => void;
|
||||
setUploadModalState: React.Dispatch<React.SetStateAction<ActiveState>>;
|
||||
};
|
||||
|
||||
@@ -149,9 +149,12 @@ export default function SourcesPopup({
|
||||
if (option.model === embeddingsName) {
|
||||
const isSelected =
|
||||
selectedDocs &&
|
||||
Array.isArray(selectedDocs) && selectedDocs.length > 0 &&
|
||||
selectedDocs.some(doc =>
|
||||
option.id ? doc.id === option.id : doc.date === option.date
|
||||
Array.isArray(selectedDocs) &&
|
||||
selectedDocs.length > 0 &&
|
||||
selectedDocs.some((doc) =>
|
||||
option.id
|
||||
? doc.id === option.id
|
||||
: doc.date === option.date,
|
||||
);
|
||||
|
||||
return (
|
||||
@@ -160,17 +163,27 @@ export default function SourcesPopup({
|
||||
className="border-opacity-80 dark:border-dim-gray flex cursor-pointer items-center border-b border-[#D9D9D9] p-3 transition-colors hover:bg-gray-100 dark:text-[14px] dark:hover:bg-[#2C2E3C]"
|
||||
onClick={() => {
|
||||
if (isSelected) {
|
||||
const updatedDocs = (selectedDocs && Array.isArray(selectedDocs))
|
||||
? selectedDocs.filter(doc =>
|
||||
option.id ? doc.id !== option.id : doc.date !== option.date
|
||||
)
|
||||
: [];
|
||||
dispatch(setSelectedDocs(updatedDocs.length > 0 ? updatedDocs : null));
|
||||
handlePostDocumentSelect(updatedDocs.length > 0 ? updatedDocs : null);
|
||||
const updatedDocs =
|
||||
selectedDocs && Array.isArray(selectedDocs)
|
||||
? selectedDocs.filter((doc) =>
|
||||
option.id
|
||||
? doc.id !== option.id
|
||||
: doc.date !== option.date,
|
||||
)
|
||||
: [];
|
||||
dispatch(
|
||||
setSelectedDocs(
|
||||
updatedDocs.length > 0 ? updatedDocs : null,
|
||||
),
|
||||
);
|
||||
handlePostDocumentSelect(
|
||||
updatedDocs.length > 0 ? updatedDocs : null,
|
||||
);
|
||||
} else {
|
||||
const updatedDocs = (selectedDocs && Array.isArray(selectedDocs))
|
||||
? [...selectedDocs, option]
|
||||
: [option];
|
||||
const updatedDocs =
|
||||
selectedDocs && Array.isArray(selectedDocs)
|
||||
? [...selectedDocs, option]
|
||||
: [option];
|
||||
dispatch(setSelectedDocs(updatedDocs));
|
||||
handlePostDocumentSelect(updatedDocs);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ export function handleFetchAnswer(
|
||||
question: string,
|
||||
signal: AbortSignal,
|
||||
token: string | null,
|
||||
selectedDocs: Doc | Doc[] | null,
|
||||
selectedDocs: Doc[] | null,
|
||||
conversationId: string | null,
|
||||
promptId: string | null,
|
||||
chunks: string,
|
||||
@@ -52,15 +52,15 @@ export function handleFetchAnswer(
|
||||
payload.attachments = attachments;
|
||||
}
|
||||
|
||||
if (selectedDocs) {
|
||||
if (Array.isArray(selectedDocs)) {
|
||||
if (selectedDocs && Array.isArray(selectedDocs)) {
|
||||
if (selectedDocs.length > 1) {
|
||||
// Handle multiple documents
|
||||
payload.active_docs = selectedDocs.map(doc => doc.id).join(',');
|
||||
payload.active_docs = selectedDocs.map((doc) => doc.id!);
|
||||
payload.retriever = selectedDocs[0]?.retriever as string;
|
||||
} else if ('id' in selectedDocs) {
|
||||
} else if (selectedDocs.length === 1 && 'id' in selectedDocs[0]) {
|
||||
// Handle single document (backward compatibility)
|
||||
payload.active_docs = selectedDocs.id as string;
|
||||
payload.retriever = selectedDocs.retriever as string;
|
||||
payload.active_docs = selectedDocs[0].id as string;
|
||||
payload.retriever = selectedDocs[0].retriever as string;
|
||||
}
|
||||
}
|
||||
return conversationService
|
||||
@@ -91,7 +91,7 @@ export function handleFetchAnswerSteaming(
|
||||
question: string,
|
||||
signal: AbortSignal,
|
||||
token: string | null,
|
||||
selectedDocs: Doc | Doc[] | null,
|
||||
selectedDocs: Doc[] | null,
|
||||
conversationId: string | null,
|
||||
promptId: string | null,
|
||||
chunks: string,
|
||||
@@ -119,15 +119,15 @@ export function handleFetchAnswerSteaming(
|
||||
payload.attachments = attachments;
|
||||
}
|
||||
|
||||
if (selectedDocs) {
|
||||
if (Array.isArray(selectedDocs)) {
|
||||
if (selectedDocs && Array.isArray(selectedDocs)) {
|
||||
if (selectedDocs.length > 1) {
|
||||
// Handle multiple documents
|
||||
payload.active_docs = selectedDocs.map(doc => doc.id).join(',');
|
||||
payload.active_docs = selectedDocs.map((doc) => doc.id!);
|
||||
payload.retriever = selectedDocs[0]?.retriever as string;
|
||||
} else if ('id' in selectedDocs) {
|
||||
} else if (selectedDocs.length === 1 && 'id' in selectedDocs[0]) {
|
||||
// Handle single document (backward compatibility)
|
||||
payload.active_docs = selectedDocs.id as string;
|
||||
payload.retriever = selectedDocs.retriever as string;
|
||||
payload.active_docs = selectedDocs[0].id as string;
|
||||
payload.retriever = selectedDocs[0].retriever as string;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ export function handleFetchAnswerSteaming(
|
||||
export function handleSearch(
|
||||
question: string,
|
||||
token: string | null,
|
||||
selectedDocs: Doc | Doc[] | null,
|
||||
selectedDocs: Doc[] | null,
|
||||
conversation_id: string | null,
|
||||
chunks: string,
|
||||
token_limit: number,
|
||||
@@ -197,15 +197,15 @@ export function handleSearch(
|
||||
token_limit: token_limit,
|
||||
isNoneDoc: selectedDocs === null,
|
||||
};
|
||||
if (selectedDocs) {
|
||||
if (Array.isArray(selectedDocs)) {
|
||||
if (selectedDocs && Array.isArray(selectedDocs)) {
|
||||
if (selectedDocs.length > 1) {
|
||||
// Handle multiple documents
|
||||
payload.active_docs = selectedDocs.map(doc => doc.id).join(',');
|
||||
payload.active_docs = selectedDocs.map((doc) => doc.id!);
|
||||
payload.retriever = selectedDocs[0]?.retriever as string;
|
||||
} else if ('id' in selectedDocs) {
|
||||
} else if (selectedDocs.length === 1 && 'id' in selectedDocs[0]) {
|
||||
// Handle single document (backward compatibility)
|
||||
payload.active_docs = selectedDocs.id as string;
|
||||
payload.retriever = selectedDocs.retriever as string;
|
||||
payload.active_docs = selectedDocs[0].id as string;
|
||||
payload.retriever = selectedDocs[0].retriever as string;
|
||||
}
|
||||
}
|
||||
return conversationService
|
||||
|
||||
@@ -54,7 +54,7 @@ export interface Query {
|
||||
|
||||
export interface RetrievalPayload {
|
||||
question: string;
|
||||
active_docs?: string;
|
||||
active_docs?: string | string[];
|
||||
retriever?: string;
|
||||
conversation_id: string | null;
|
||||
prompt_id?: string | null;
|
||||
|
||||
@@ -60,7 +60,7 @@ export const ShareConversationModal = ({
|
||||
const [sourcePath, setSourcePath] = useState<{
|
||||
label: string;
|
||||
value: string;
|
||||
} | null>(preSelectedDoc ? extractDocPaths([preSelectedDoc])[0] : null);
|
||||
} | null>(preSelectedDoc ? extractDocPaths(preSelectedDoc)[0] : null);
|
||||
|
||||
const handleCopyKey = (url: string) => {
|
||||
navigator.clipboard.writeText(url);
|
||||
@@ -105,14 +105,14 @@ export const ShareConversationModal = ({
|
||||
return (
|
||||
<WrapperModal close={close}>
|
||||
<div className="flex flex-col gap-2">
|
||||
<h2 className="text-xl font-medium text-eerie-black dark:text-chinese-white">
|
||||
<h2 className="text-eerie-black dark:text-chinese-white text-xl font-medium">
|
||||
{t('modals.shareConv.label')}
|
||||
</h2>
|
||||
<p className="text-sm text-eerie-black dark:text-silver/60">
|
||||
<p className="text-eerie-black dark:text-silver/60 text-sm">
|
||||
{t('modals.shareConv.note')}
|
||||
</p>
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="text-lg text-eerie-black dark:text-white">
|
||||
<span className="text-eerie-black text-lg dark:text-white">
|
||||
{t('modals.shareConv.option')}
|
||||
</span>
|
||||
<ToggleSwitch
|
||||
@@ -136,19 +136,19 @@ export const ShareConversationModal = ({
|
||||
</div>
|
||||
)}
|
||||
<div className="flex items-baseline justify-between gap-2">
|
||||
<span className="no-scrollbar w-full overflow-x-auto whitespace-nowrap rounded-full border-2 border-silver px-4 py-3 text-eerie-black dark:border-silver/40 dark:text-white">
|
||||
<span className="no-scrollbar border-silver text-eerie-black dark:border-silver/40 w-full overflow-x-auto rounded-full border-2 px-4 py-3 whitespace-nowrap dark:text-white">
|
||||
{`${domain}/share/${identifier ?? '....'}`}
|
||||
</span>
|
||||
{status === 'fetched' ? (
|
||||
<button
|
||||
className="my-1 h-10 w-28 rounded-full bg-purple-30 p-2 text-sm text-white hover:bg-violets-are-blue"
|
||||
className="bg-purple-30 hover:bg-violets-are-blue my-1 h-10 w-28 rounded-full p-2 text-sm text-white"
|
||||
onClick={() => handleCopyKey(`${domain}/share/${identifier}`)}
|
||||
>
|
||||
{isCopied ? t('modals.saveKey.copied') : t('modals.saveKey.copy')}
|
||||
</button>
|
||||
) : (
|
||||
<button
|
||||
className="my-1 flex h-10 w-28 items-center justify-evenly rounded-full bg-purple-30 p-2 text-center text-sm font-normal text-white hover:bg-violets-are-blue"
|
||||
className="bg-purple-30 hover:bg-violets-are-blue my-1 flex h-10 w-28 items-center justify-evenly rounded-full p-2 text-center text-sm font-normal text-white"
|
||||
onClick={() => {
|
||||
shareCoversationPublicly(allowPrompt);
|
||||
}}
|
||||
|
||||
@@ -34,15 +34,16 @@ const initialState: Preference = {
|
||||
prompt: { name: 'default', id: 'default', type: 'public' },
|
||||
chunks: '2',
|
||||
token_limit: 2000,
|
||||
selectedDocs: [{
|
||||
id: 'default',
|
||||
name: 'default',
|
||||
type: 'remote',
|
||||
date: 'default',
|
||||
docLink: 'default',
|
||||
model: 'openai_text-embedding-ada-002',
|
||||
retriever: 'classic',
|
||||
}] as Doc[],
|
||||
selectedDocs: [
|
||||
{
|
||||
id: 'default',
|
||||
name: 'default',
|
||||
type: 'remote',
|
||||
date: 'default',
|
||||
model: 'openai_text-embedding-ada-002',
|
||||
retriever: 'classic',
|
||||
},
|
||||
] as Doc[],
|
||||
sourceDocs: null,
|
||||
conversations: {
|
||||
data: null,
|
||||
|
||||
Reference in New Issue
Block a user