import fetch from "node-fetch";
import { getHeaders } from "../../continueServer/stubs/headers.js";
import { SERVER_URL } from "../../util/parameters.js";
export class FreeTrialReranker {
    name = "free-trial";
    async rerank(query, chunks) {
        const resp = await fetch(new URL("rerank", SERVER_URL), {
            method: "POST",
            headers: {
                "Content-Type": "application/json",
                ...(await getHeaders()),
            },
            body: JSON.stringify({
                query,
                documents: chunks.map((chunk) => chunk.content),
            }),
        });
        if (!resp.ok) {
            throw new Error(await resp.text());
        }
        const data = (await resp.json());
        const results = data.sort((a, b) => a.index - b.index);
        return results.map((result) => result.relevance_score);
    }
}
