feat: answer routes re-structure for better maintainability and reuse

This commit is contained in:
Siddhant Rai
2025-07-23 20:07:42 +05:30
parent 4185e64c65
commit 76973a4b4c
20 changed files with 970 additions and 993 deletions

View File

@@ -8,7 +8,6 @@ export function handleFetchAnswer(
signal: AbortSignal,
token: string | null,
selectedDocs: Doc | null,
history: Array<any> = [],
conversationId: string | null,
promptId: string | null,
chunks: string,
@@ -37,16 +36,8 @@ export function handleFetchAnswer(
title: any;
}
> {
history = history.map((item) => {
return {
prompt: item.prompt,
response: item.response,
tool_calls: item.tool_calls,
};
});
const payload: RetrievalPayload = {
question: question,
history: JSON.stringify(history),
conversation_id: conversationId,
prompt_id: promptId,
chunks: chunks,
@@ -94,7 +85,6 @@ export function handleFetchAnswerSteaming(
signal: AbortSignal,
token: string | null,
selectedDocs: Doc | null,
history: Array<any> = [],
conversationId: string | null,
promptId: string | null,
chunks: string,
@@ -105,17 +95,8 @@ export function handleFetchAnswerSteaming(
attachments?: string[],
save_conversation = true,
): Promise<Answer> {
history = history.map((item) => {
return {
prompt: item.prompt,
response: item.response,
thought: item.thought,
tool_calls: item.tool_calls,
};
});
const payload: RetrievalPayload = {
question: question,
history: JSON.stringify(history),
conversation_id: conversationId,
prompt_id: promptId,
chunks: chunks,
@@ -192,20 +173,11 @@ export function handleSearch(
token: string | null,
selectedDocs: Doc | null,
conversation_id: string | null,
history: Array<any> = [],
chunks: string,
token_limit: number,
) {
history = history.map((item) => {
return {
prompt: item.prompt,
response: item.response,
tool_calls: item.tool_calls,
};
});
const payload: RetrievalPayload = {
question: question,
history: JSON.stringify(history),
conversation_id: conversation_id,
chunks: chunks,
token_limit: token_limit,

View File

@@ -52,7 +52,6 @@ export interface RetrievalPayload {
question: string;
active_docs?: string;
retriever?: string;
history: string;
conversation_id: string | null;
prompt_id?: string | null;
chunks: string;

View File

@@ -57,7 +57,6 @@ export const fetchAnswer = createAsyncThunk<
signal,
state.preference.token,
state.preference.selectedDocs!,
state.conversation.queries,
currentConversationId,
state.preference.prompt.id,
state.preference.chunks,
@@ -153,7 +152,6 @@ export const fetchAnswer = createAsyncThunk<
signal,
state.preference.token,
state.preference.selectedDocs!,
state.conversation.queries,
state.conversation.conversationId,
state.preference.prompt.id,
state.preference.chunks,