mirror of
https://github.com/arc53/DocsGPT.git
synced 2025-11-30 17:13:15 +00:00
integrate /api/search endpoint, get sources post stream
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user