diff --git a/frontend/src/components/Dropdown.tsx b/frontend/src/components/Dropdown.tsx index 17516aaa..0353a191 100644 --- a/frontend/src/components/Dropdown.tsx +++ b/frontend/src/components/Dropdown.tsx @@ -26,6 +26,7 @@ function Dropdown({ | string | { label: string; value: string } | { value: number; description: string } + | { name: string; id: string; type: string } | null; onSelect: | ((value: string) => void) @@ -96,6 +97,10 @@ function Dropdown({ ? selectedValue.value + ` (${selectedValue.description})` : selectedValue.description }` + : selectedValue && + 'name' in selectedValue && + 'id' in selectedValue + ? `${selectedValue.name}` : placeholder ? placeholder : 'From URL'} diff --git a/frontend/src/conversation/conversationHandlers.ts b/frontend/src/conversation/conversationHandlers.ts index 90bbc0a9..9e3d5d2c 100644 --- a/frontend/src/conversation/conversationHandlers.ts +++ b/frontend/src/conversation/conversationHandlers.ts @@ -1,32 +1,6 @@ import conversationService from '../api/services/conversationService'; import { Doc } from '../preferences/preferenceApi'; -import { Answer, FEEDBACK } from './conversationModels'; - -function getDocPath(selectedDocs: Doc | null): string { - let docPath = 'default'; - if (selectedDocs) { - let namePath = selectedDocs.name; - if (selectedDocs.language === namePath) { - namePath = '.project'; - } - if (selectedDocs.location === 'local') { - docPath = 'local' + '/' + selectedDocs.name + '/'; - } else if (selectedDocs.location === 'remote') { - docPath = - selectedDocs.language + - '/' + - namePath + - '/' + - selectedDocs.version + - '/' + - selectedDocs.model + - '/'; - } else if (selectedDocs.location === 'custom') { - docPath = selectedDocs.docLink; - } - } - return docPath; -} +import { Answer, FEEDBACK, RetrievalPayload } from './conversationModels'; export function handleFetchAnswer( question: string, @@ -54,23 +28,22 @@ export function handleFetchAnswer( title: any; } > { - const docPath = getDocPath(selectedDocs); history = history.map((item) => { return { prompt: item.prompt, response: item.response }; }); + const payload: RetrievalPayload = { + question: question, + history: JSON.stringify(history), + conversation_id: conversationId, + prompt_id: promptId, + chunks: chunks, + token_limit: token_limit, + }; + if (selectedDocs && 'id' in selectedDocs) + payload.active_docs = selectedDocs.id as string; + else payload.retriever = selectedDocs?.docLink as string; return conversationService - .answer( - { - question: question, - history: history, - active_docs: docPath, - conversation_id: conversationId, - prompt_id: promptId, - chunks: chunks, - token_limit: token_limit, - }, - signal, - ) + .answer(payload, signal) .then((response) => { if (response.ok) { return response.json(); @@ -101,24 +74,24 @@ export function handleFetchAnswerSteaming( token_limit: number, onEvent: (event: MessageEvent) => void, ): Promise { - const docPath = getDocPath(selectedDocs); history = history.map((item) => { return { prompt: item.prompt, response: item.response }; }); + const payload: RetrievalPayload = { + question: question, + history: JSON.stringify(history), + conversation_id: conversationId, + prompt_id: promptId, + chunks: chunks, + token_limit: token_limit, + }; + if (selectedDocs && 'id' in selectedDocs) + payload.active_docs = selectedDocs.id as string; + else payload.retriever = selectedDocs?.docLink as string; + return new Promise((resolve, reject) => { conversationService - .answerStream( - { - question: question, - active_docs: docPath, - history: JSON.stringify(history), - conversation_id: conversationId, - prompt_id: promptId, - chunks: chunks, - token_limit: token_limit, - }, - signal, - ) + .answerStream(payload, signal) .then((response) => { if (!response.body) throw Error('No response body'); @@ -175,16 +148,21 @@ export function handleSearch( chunks: string, token_limit: number, ) { - const docPath = getDocPath(selectedDocs); + history = history.map((item) => { + return { prompt: item.prompt, response: item.response }; + }); + const payload: RetrievalPayload = { + question: question, + history: JSON.stringify(history), + conversation_id: conversation_id, + chunks: chunks, + token_limit: token_limit, + }; + if (selectedDocs && 'id' in selectedDocs) + payload.active_docs = selectedDocs.id as string; + else payload.retriever = selectedDocs?.docLink as string; return conversationService - .search({ - question: question, - active_docs: docPath, - conversation_id, - history, - chunks: chunks, - token_limit: token_limit, - }) + .search(payload) .then((response) => response.json()) .then((data) => { return data; diff --git a/frontend/src/conversation/conversationModels.ts b/frontend/src/conversation/conversationModels.ts index 347a2521..bf86678b 100644 --- a/frontend/src/conversation/conversationModels.ts +++ b/frontend/src/conversation/conversationModels.ts @@ -31,3 +31,13 @@ export interface Query { conversationId?: string | null; title?: string | null; } +export interface RetrievalPayload { + question: string; + active_docs?: string; + retriever?: string; + history: string; + conversation_id: string | null; + prompt_id?: string | null; + chunks: string; + token_limit: number; +} diff --git a/frontend/src/modals/CreateAPIKeyModal.tsx b/frontend/src/modals/CreateAPIKeyModal.tsx index 2f67d83b..e59fd37e 100644 --- a/frontend/src/modals/CreateAPIKeyModal.tsx +++ b/frontend/src/modals/CreateAPIKeyModal.tsx @@ -22,8 +22,9 @@ export default function CreateAPIKeyModal({ const [APIKeyName, setAPIKeyName] = React.useState(''); const [sourcePath, setSourcePath] = React.useState<{ - label: string; - value: string; + name: string; + id: string; + type: string; } | null>(null); const [prompt, setPrompt] = React.useState<{ name: string; @@ -41,27 +42,17 @@ export default function CreateAPIKeyModal({ ? docs .filter((doc) => doc.model === embeddingsName) .map((doc: Doc) => { - let namePath = doc.name; - if (doc.language === namePath) { - namePath = '.project'; - } - let docPath = 'default'; - if (doc.location === 'local') { - docPath = 'local' + '/' + doc.name + '/'; - } else if (doc.location === 'remote') { - docPath = - doc.language + - '/' + - namePath + - '/' + - doc.version + - '/' + - doc.model + - '/'; + if ('id' in doc) { + return { + name: doc.name, + id: doc.id as string, + type: 'local', + }; } return { - label: doc.name, - value: docPath, + name: doc.name as string, + id: doc.docLink as string, + type: 'default', }; }) : []; @@ -107,9 +98,14 @@ export default function CreateAPIKeyModal({ - setSourcePath(selection) - } + onSelect={(selection: { + name: string; + id: string; + type: string; + }) => { + setSourcePath(selection); + console.log(selection); + }} options={extractDocPaths()} size="w-full" rounded="xl" @@ -142,16 +138,22 @@ export default function CreateAPIKeyModal({