feat: abort openai text completion when stopping responses

This commit is contained in:
Jun Siang Cheah 2024-04-20 21:11:02 +01:00
parent c1d85f8a6f
commit c095a7c291
4 changed files with 20 additions and 8 deletions

View file

@ -211,10 +211,12 @@ export const generateOpenAIChatCompletion = async (
token: string = '',
body: object,
url: string = OPENAI_API_BASE_URL
) => {
): Promise<[Response | null, AbortController]> => {
const controller = new AbortController();
let error = null;
const res = await fetch(`${url}/chat/completions`, {
signal: controller.signal,
method: 'POST',
headers: {
Authorization: `Bearer ${token}`,
@ -231,7 +233,7 @@ export const generateOpenAIChatCompletion = async (
throw error;
}
return res;
return [res, controller];
};
export const synthesizeOpenAISpeech = async (