This commit is contained in:
Nicolas 2024-08-30 12:34:45 -03:00
parent 1805d901a9
commit ee3e5dc69c
2 changed files with 30 additions and 13 deletions

View File

@ -312,12 +312,12 @@ export function legacyScrapeOptions(x: ScrapeOptions): PageOptions {
};
}
export function legacyExtractorOptions(x: ExtractOptions): ExtractorOptions {
export function legacyExtractorOptions(x?: ExtractOptions): ExtractorOptions {
return {
mode: x.mode ? "llm-extraction" : "markdown",
extractionPrompt: x.prompt ?? "Based on the information on the page, extract the information from the schema.",
extractionSchema: x.schema,
userPrompt: x.prompt ?? "",
mode: x?.mode ? "llm-extraction" : "markdown",
extractionPrompt: x?.prompt ?? "Based on the information on the page, extract the information from the schema.",
extractionSchema: x?.schema,
userPrompt: x?.prompt ?? "",
};
}

View File

@ -199,27 +199,44 @@ export async function supaCheckTeamCredits(team_id: string, credits: number) {
);
}
if(subscriptionError) {
Logger.error(`Subscription error: ${subscriptionError}`);
throw new Error(`Subscription error: ${subscriptionError}`);
}
// Free credits, no coupons
if (!subscription) {
if (!subscription || subscriptionError) {
// If there is no active subscription but there are available coupons
if (couponCredits >= credits) {
return { success: true, message: "Sufficient credits available", remainingCredits: couponCredits };
}
const { data: creditUsages, error: creditUsageError } =
await supabase_service
let creditUsages;
let creditUsageError;
let retries = 0;
const maxRetries = 3;
const retryInterval = 2000; // 2 seconds
while (retries < maxRetries) {
const result = await supabase_service
.from("credit_usage")
.select("credits_used")
.is("subscription_id", null)
.eq("team_id", team_id);
creditUsages = result.data;
creditUsageError = result.error;
if (!creditUsageError) {
break;
}
retries++;
if (retries < maxRetries) {
await new Promise(resolve => setTimeout(resolve, retryInterval));
}
}
if (creditUsageError) {
Logger.error(`Credit usage error: ${creditUsageError}`);
Logger.error(`Credit usage error after ${maxRetries} attempts: ${creditUsageError}`);
throw new Error(
`Failed to retrieve credit usage for team_id: ${team_id}`
);