Refactor API calls for web search context and message regeneration
This commit is contained in:
72
src/App.jsx
72
src/App.jsx
@@ -578,25 +578,21 @@ async function regenerateFromIndex(index, overrideUserText = null) {
|
|||||||
historyForSearch[historyForSearch.length - 1] = { role: 'user', content: promptText }
|
historyForSearch[historyForSearch.length - 1] = { role: 'user', content: promptText }
|
||||||
}
|
}
|
||||||
|
|
||||||
const resp = await fetch(`${backendApiUrl}/websearch`, {
|
const searchContext = await fetchWebSearchContext({
|
||||||
method: 'POST',
|
apiBase: backendApiUrl,
|
||||||
headers: { 'Content-Type': 'application/json' },
|
engines: searxEngines,
|
||||||
|
historyLimit: 8,
|
||||||
|
messages: historyForSearch,
|
||||||
|
model,
|
||||||
|
prompt: promptText,
|
||||||
|
searxUrl,
|
||||||
signal: requestController.signal,
|
signal: requestController.signal,
|
||||||
body: JSON.stringify({
|
|
||||||
prompt: promptText,
|
|
||||||
model,
|
|
||||||
messages: historyForSearch,
|
|
||||||
history_limit: 8,
|
|
||||||
searx_url: searxUrl || null,
|
|
||||||
engines: Array.isArray(searxEngines) ? searxEngines : null,
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
const data = await resp.json()
|
if (searchContext.contextBlock) {
|
||||||
if (data && typeof data.context_block === 'string' && data.context_block.trim()) {
|
contextBlocks.push(searchContext.contextBlock)
|
||||||
contextBlocks.push(data.context_block.trim())
|
|
||||||
}
|
}
|
||||||
if (Array.isArray(data?.sources)) {
|
if (Array.isArray(searchContext.sources)) {
|
||||||
citationSources.push(...data.sources)
|
citationSources.push(...searchContext.sources)
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (isAbortError(error)) throw error
|
if (isAbortError(error)) throw error
|
||||||
@@ -623,19 +619,17 @@ async function regenerateFromIndex(index, overrideUserText = null) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${backendApiUrl}/sessions/${sessionId}/regenerate`, {
|
const res = await postRegenerateMessage({
|
||||||
method: 'POST',
|
apiBase: backendApiUrl,
|
||||||
headers: { 'Content-Type': 'application/json' },
|
enrichedMessage: enrichedPrompt,
|
||||||
|
index,
|
||||||
|
model,
|
||||||
|
sessionId,
|
||||||
signal: requestController.signal,
|
signal: requestController.signal,
|
||||||
body: JSON.stringify({
|
sources: citationSources || [],
|
||||||
index,
|
stream: true,
|
||||||
model,
|
transcriptionModel,
|
||||||
stream: true,
|
visionModel,
|
||||||
enriched_message: enrichedPrompt,
|
|
||||||
sources: citationSources || [],
|
|
||||||
vision_model: visionModel || null,
|
|
||||||
transcription_model: transcriptionModel || null,
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
if (!res.ok) throw new Error(await readBackendErrorText(res))
|
if (!res.ok) throw new Error(await readBackendErrorText(res))
|
||||||
|
|
||||||
@@ -679,19 +673,17 @@ async function regenerateFromIndex(index, overrideUserText = null) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const res = await fetch(`${backendApiUrl}/sessions/${sessionId}/regenerate`, {
|
const res = await postRegenerateMessage({
|
||||||
method: 'POST',
|
apiBase: backendApiUrl,
|
||||||
headers: { 'Content-Type': 'application/json' },
|
enrichedMessage: enrichedPrompt,
|
||||||
|
index,
|
||||||
|
model,
|
||||||
|
sessionId,
|
||||||
signal: requestController.signal,
|
signal: requestController.signal,
|
||||||
body: JSON.stringify({
|
sources: citationSources || [],
|
||||||
index,
|
stream: false,
|
||||||
model,
|
transcriptionModel,
|
||||||
stream: false,
|
visionModel,
|
||||||
enriched_message: enrichedPrompt,
|
|
||||||
sources: citationSources || [],
|
|
||||||
vision_model: visionModel || null,
|
|
||||||
transcription_model: transcriptionModel || null,
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
if (!res.ok) throw new Error(await readBackendErrorText(res))
|
if (!res.ok) throw new Error(await readBackendErrorText(res))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user