|
|
|
@ -3,6 +3,33 @@ import { Doc } from '../preferences/preferenceApi';
|
|
|
|
|
|
|
|
|
|
const apiHost = import.meta.env.VITE_API_HOST || 'https://docsapi.arc53.com';
|
|
|
|
|
|
|
|
|
|
function getDocPath(selectedDocs: Doc | null): string {
|
|
|
|
|
let docPath = 'default';
|
|
|
|
|
|
|
|
|
|
if (selectedDocs) {
|
|
|
|
|
let namePath = selectedDocs.name;
|
|
|
|
|
if (selectedDocs.language === namePath) {
|
|
|
|
|
namePath = '.project';
|
|
|
|
|
}
|
|
|
|
|
if (selectedDocs.location === 'local') {
|
|
|
|
|
docPath = 'local' + '/' + selectedDocs.name + '/';
|
|
|
|
|
} else if (selectedDocs.location === 'remote') {
|
|
|
|
|
docPath =
|
|
|
|
|
selectedDocs.language +
|
|
|
|
|
'/' +
|
|
|
|
|
namePath +
|
|
|
|
|
'/' +
|
|
|
|
|
selectedDocs.version +
|
|
|
|
|
'/' +
|
|
|
|
|
selectedDocs.model +
|
|
|
|
|
'/';
|
|
|
|
|
} else if (selectedDocs.location === 'custom') {
|
|
|
|
|
docPath = selectedDocs.docLink;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return docPath;
|
|
|
|
|
}
|
|
|
|
|
export function fetchAnswerApi(
|
|
|
|
|
question: string,
|
|
|
|
|
signal: AbortSignal,
|
|
|
|
@ -28,27 +55,7 @@ export function fetchAnswerApi(
|
|
|
|
|
title: any;
|
|
|
|
|
}
|
|
|
|
|
> {
|
|
|
|
|
let docPath = 'default';
|
|
|
|
|
|
|
|
|
|
if (selectedDocs) {
|
|
|
|
|
let namePath = selectedDocs.name;
|
|
|
|
|
if (selectedDocs.language === namePath) {
|
|
|
|
|
namePath = '.project';
|
|
|
|
|
}
|
|
|
|
|
if (selectedDocs.location === 'local') {
|
|
|
|
|
docPath = 'local' + '/' + selectedDocs.name + '/';
|
|
|
|
|
} else if (selectedDocs.location === 'remote') {
|
|
|
|
|
docPath =
|
|
|
|
|
selectedDocs.language +
|
|
|
|
|
'/' +
|
|
|
|
|
namePath +
|
|
|
|
|
'/' +
|
|
|
|
|
selectedDocs.version +
|
|
|
|
|
'/' +
|
|
|
|
|
selectedDocs.model +
|
|
|
|
|
'/';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const docPath = getDocPath(selectedDocs);
|
|
|
|
|
//in history array remove all keys except prompt and response
|
|
|
|
|
history = history.map((item) => {
|
|
|
|
|
return { prompt: item.prompt, response: item.response };
|
|
|
|
@ -98,27 +105,7 @@ export function fetchAnswerSteaming(
|
|
|
|
|
chunks: string,
|
|
|
|
|
onEvent: (event: MessageEvent) => void,
|
|
|
|
|
): Promise<Answer> {
|
|
|
|
|
let docPath = 'default';
|
|
|
|
|
|
|
|
|
|
if (selectedDocs) {
|
|
|
|
|
let namePath = selectedDocs.name;
|
|
|
|
|
if (selectedDocs.language === namePath) {
|
|
|
|
|
namePath = '.project';
|
|
|
|
|
}
|
|
|
|
|
if (selectedDocs.location === 'local') {
|
|
|
|
|
docPath = 'local' + '/' + selectedDocs.name + '/';
|
|
|
|
|
} else if (selectedDocs.location === 'remote') {
|
|
|
|
|
docPath =
|
|
|
|
|
selectedDocs.language +
|
|
|
|
|
'/' +
|
|
|
|
|
namePath +
|
|
|
|
|
'/' +
|
|
|
|
|
selectedDocs.version +
|
|
|
|
|
'/' +
|
|
|
|
|
selectedDocs.model +
|
|
|
|
|
'/';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const docPath = getDocPath(selectedDocs);
|
|
|
|
|
|
|
|
|
|
history = history.map((item) => {
|
|
|
|
|
return { prompt: item.prompt, response: item.response };
|
|
|
|
@ -195,31 +182,7 @@ export function searchEndpoint(
|
|
|
|
|
history: Array<any> = [],
|
|
|
|
|
chunks: string,
|
|
|
|
|
) {
|
|
|
|
|
/*
|
|
|
|
|
"active_docs": "default",
|
|
|
|
|
"question": "Summarise",
|
|
|
|
|
"conversation_id": null,
|
|
|
|
|
"history": "[]" */
|
|
|
|
|
let docPath = 'default';
|
|
|
|
|
if (selectedDocs) {
|
|
|
|
|
let namePath = selectedDocs.name;
|
|
|
|
|
if (selectedDocs.language === namePath) {
|
|
|
|
|
namePath = '.project';
|
|
|
|
|
}
|
|
|
|
|
if (selectedDocs.location === 'local') {
|
|
|
|
|
docPath = 'local' + '/' + selectedDocs.name + '/';
|
|
|
|
|
} else if (selectedDocs.location === 'remote') {
|
|
|
|
|
docPath =
|
|
|
|
|
selectedDocs.language +
|
|
|
|
|
'/' +
|
|
|
|
|
namePath +
|
|
|
|
|
'/' +
|
|
|
|
|
selectedDocs.version +
|
|
|
|
|
'/' +
|
|
|
|
|
selectedDocs.model +
|
|
|
|
|
'/';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const docPath = getDocPath(selectedDocs);
|
|
|
|
|
|
|
|
|
|
const body = {
|
|
|
|
|
question: question,
|
|
|
|
|