integrate /api/search endpoint, get sources post stream

This commit is contained in:
ManishMadan2882
2024-01-15 20:23:18 +05:30
parent 6a70e3e45b
commit f4f056449f
2 changed files with 84 additions and 33 deletions

View File

@@ -12,20 +12,20 @@ export function fetchAnswerApi(
promptId: string | null,
): Promise<
| {
result: any;
answer: any;
sources: any;
conversationId: any;
query: string;
}
result: any;
answer: any;
sources: any;
conversationId: any;
query: string;
}
| {
result: any;
answer: any;
sources: any;
query: string;
conversationId: any;
title: any;
}
result: any;
answer: any;
sources: any;
query: string;
conversationId: any;
title: any;
}
> {
let namePath = selectedDocs.name;
if (selectedDocs.language === namePath) {
@@ -128,7 +128,6 @@ export function fetchAnswerSteaming(
conversation_id: conversationId,
prompt_id: promptId,
};
fetch(apiHost + '/stream', {
method: 'POST',
headers: {
@@ -183,7 +182,58 @@ export function fetchAnswerSteaming(
});
});
}
export function searchEndpoint(
question: string,
apiKey: string,
selectedDocs: Doc,
conversation_id: string | null,
history: Array<any> = [],
) {
/*
"active_docs": "default",
"question": "Summarise",
"conversation_id": null,
"history": "[]" */
let namePath = selectedDocs.name;
if (selectedDocs.language === namePath) {
namePath = '.project';
}
let docPath = 'default';
if (selectedDocs.location === 'local') {
docPath = 'local' + '/' + selectedDocs.name + '/';
} else if (selectedDocs.location === 'remote') {
docPath =
selectedDocs.language +
'/' +
namePath +
'/' +
selectedDocs.version +
'/' +
selectedDocs.model +
'/';
}
const body = {
question: question,
active_docs: docPath,
conversation_id,
history
};
return fetch(`${apiHost}/api/search`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(
body
),
}).then((response) => response.json())
.then((data) => {
return data;
})
.catch(err => console.log(err))
}
export function sendFeedback(
prompt: string,
response: string,