Update context fetching logic in App.jsx

This commit is contained in:
2026-03-19 21:36:43 +01:00
parent 68cb83d32a
commit adc07c5027

View File

@@ -1209,23 +1209,16 @@ async function sendMessage() {
let citationSources = []
const contextBlocks = []
if (chatLibrarySlug && chatLibrary?.states?.is_indexed) {
const selectedLibrary = getChatLibraryForSession(targetSessionId)
if (selectedLibrary?.states?.is_indexed) {
try {
const resp = await fetch(`${ollamaApiUrl}/libraries/${chatLibrarySlug}/context`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
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())
const localContext = await fetchLocalLibraryContext(selectedLibrary.slug, userMsg.content, requestController.signal)
if (localContext.contextBlock) {
contextBlocks.push(localContext.contextBlock)
}
if (Array.isArray(data?.sources)) {
citationSources.push(...data.sources)
if (Array.isArray(localContext.sources)) {
citationSources.push(...localContext.sources)
}
} catch (error) {
if (isAbortError(error)) throw error