Files
goose/ui/desktop/src/utils/askAI.ts
T
2024-12-04 10:20:26 +11:00

28 lines
673 B
TypeScript

import { getApiUrl } from '../config';
/**
* Utility to ask the LLM any question to clarify without wider context.
*/
export async function askAi(promptTemplates: string[]) {
const responses = await Promise.all(
promptTemplates.map(async (template) => {
const response = await fetch(getApiUrl('/ask'), {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ prompt: template }),
});
if (!response.ok) {
throw new Error('Failed to get response');
}
const data = await response.json();
return data.response;
})
);
return responses;
}