fix(server): Properly build ML predict URL (#9751)

New URL via URL constructor and not string concatenation
This commit is contained in:
safehome-jdev 2024-05-26 05:21:10 -07:00 committed by GitHub
parent 99f0aa868a
commit 4d4bb8b6a7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -19,9 +19,11 @@ export class MachineLearningRepository implements IMachineLearningRepository {
private async predict<T>(url: string, input: TextModelInput | VisionModelInput, config: ModelConfig): Promise<T> {
const formData = await this.getFormData(input, config);
const res = await fetch(`${url}/predict`, { method: 'POST', body: formData }).catch((error: Error | any) => {
throw new Error(`${errorPrefix} to "${url}" failed with ${error?.cause || error}`);
});
const res = await fetch(new URL('/predict', url), { method: 'POST', body: formData }).catch(
(error: Error | any) => {
throw new Error(`${errorPrefix} to "${url}" failed with ${error?.cause || error}`);
},
);
if (res.status >= 400) {
const modelType = config.modelType ? ` for ${config.modelType.replace('-', ' ')}` : '';