adding continuous
All checks were successful
Recommender Build and Deploy (internal) / Build Recommender Image (push) Successful in 3m39s
Recommender Build and Deploy (internal) / Deploy Recommender (internal) (push) Successful in 38s

This commit is contained in:
2026-04-17 21:09:59 -03:00
parent 910d26add3
commit 6e9cfc5d30
17 changed files with 1743 additions and 387 deletions

View File

@@ -66,3 +66,81 @@ export function getFeedback(): Promise<FeedbackEntry[]> {
export function deleteRecommendation(id: string): Promise<{ ok: boolean }> {
return request(`/recommendations/${id}`, { method: 'DELETE' });
}
export function createContinuousRecommendation(body: {
liked_shows: string;
disliked_shows?: string;
themes?: string;
requirements?: string;
avoid?: string;
total_count: number;
media_type: MediaType;
use_web_search?: boolean;
validate_results?: boolean;
}): Promise<{ id: string }> {
return (async () => {
const res = await fetch(`${BASE}/recommendations/continuous`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'text/event-stream',
},
body: JSON.stringify(body),
});
if (!res.ok) {
const text = await res.text();
throw new Error(`HTTP ${res.status}: ${text}`);
}
if (!res.body) {
throw new Error('Missing response stream for continuous recommendation');
}
const reader = res.body.getReader();
const decoder = new TextDecoder();
let buffer = '';
try {
while (true) {
const { value, done } = await reader.read();
if (value) {
buffer += decoder.decode(value, { stream: !done });
}
let boundary = buffer.indexOf('\n\n');
while (boundary !== -1) {
const rawEvent = buffer.slice(0, boundary).trim();
buffer = buffer.slice(boundary + 2);
if (rawEvent) {
const dataLine = rawEvent
.split('\n')
.find((line) => line.startsWith('data:'));
if (dataLine) {
const payload = dataLine.slice(5).trim();
const event = JSON.parse(payload) as { type?: string; id?: string };
if (event.type === 'created' && event.id) {
await reader.cancel();
return { id: event.id };
}
}
}
boundary = buffer.indexOf('\n\n');
}
if (done) {
break;
}
}
} finally {
reader.releaseLock();
}
throw new Error('Continuous recommendation stream ended before returning an id');
})();
}