Update context fetching logic in App.jsx
This commit is contained in:
23
src/App.jsx
23
src/App.jsx
@@ -1209,23 +1209,16 @@ async function sendMessage() {
|
|||||||
let citationSources = []
|
let citationSources = []
|
||||||
const contextBlocks = []
|
const contextBlocks = []
|
||||||
|
|
||||||
if (chatLibrarySlug && chatLibrary?.states?.is_indexed) {
|
const selectedLibrary = getChatLibraryForSession(targetSessionId)
|
||||||
|
|
||||||
|
if (selectedLibrary?.states?.is_indexed) {
|
||||||
try {
|
try {
|
||||||
const resp = await fetch(`${ollamaApiUrl}/libraries/${chatLibrarySlug}/context`, {
|
const localContext = await fetchLocalLibraryContext(selectedLibrary.slug, userMsg.content, requestController.signal)
|
||||||
method: 'POST',
|
if (localContext.contextBlock) {
|
||||||
headers: { 'Content-Type': 'application/json' },
|
contextBlocks.push(localContext.contextBlock)
|
||||||
signal: requestController.signal,
|
|
||||||
body: JSON.stringify({
|
|
||||||
prompt: userMsg.content,
|
|
||||||
top_k: 5
|
|
||||||
})
|
|
||||||
})
|
|
||||||
const data = await resp.json()
|
|
||||||
if (data && typeof data.context_block === 'string' && data.context_block.trim()) {
|
|
||||||
contextBlocks.push(data.context_block.trim())
|
|
||||||
}
|
}
|
||||||
if (Array.isArray(data?.sources)) {
|
if (Array.isArray(localContext.sources)) {
|
||||||
citationSources.push(...data.sources)
|
citationSources.push(...localContext.sources)
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (isAbortError(error)) throw error
|
if (isAbortError(error)) throw error
|
||||||
|
|||||||
Reference in New Issue
Block a user