fix(gemini): budget-check före bildhämtning så spärr triggars tidigt
This commit is contained in:
@@ -326,12 +326,21 @@ export class GeminiAamosClient implements AamosClient {
|
||||
const locale = options.localeContext ?? this.defaultLocale();
|
||||
const started = Date.now();
|
||||
|
||||
const imageCount = Math.min(input.imageUrls.length, 6);
|
||||
const estimatedCostUsd = imageCount * COST_ESTIMATE_PER_IMAGE_USD;
|
||||
if (await this.isOverBudget(estimatedCostUsd)) {
|
||||
return {
|
||||
status: "failed",
|
||||
output: null,
|
||||
error: "Global Gemini-dagsbudget är förbrukad.",
|
||||
};
|
||||
}
|
||||
|
||||
const imageParts = await Promise.all(
|
||||
input.imageUrls.slice(0, 6).map((url) => this.fetchOneImage(url, this.cfg.timeoutMs)),
|
||||
);
|
||||
|
||||
const estimatedCostUsd = imageParts.length * COST_ESTIMATE_PER_IMAGE_USD;
|
||||
if (await this.isOverBudget(estimatedCostUsd)) {
|
||||
if (imageParts.length === 0) {
|
||||
return {
|
||||
status: "failed",
|
||||
output: null,
|
||||
@@ -416,8 +425,8 @@ export class GeminiAamosClient implements AamosClient {
|
||||
const locale = options.localeContext ?? this.defaultLocale();
|
||||
const started = Date.now();
|
||||
|
||||
const imageParts = await this.fetchImageParts(imageUrls, this.cfg.timeoutMs);
|
||||
const estimatedCostUsd = imageParts.length * costEstimatePerImage;
|
||||
const imageCount = Math.min(imageUrls.length, 6);
|
||||
const estimatedCostUsd = imageCount * costEstimatePerImage;
|
||||
if (await this.isOverBudget(estimatedCostUsd)) {
|
||||
return {
|
||||
status: "failed",
|
||||
@@ -426,6 +435,15 @@ export class GeminiAamosClient implements AamosClient {
|
||||
} as AamosResult<T>;
|
||||
}
|
||||
|
||||
const imageParts = await this.fetchImageParts(imageUrls, this.cfg.timeoutMs);
|
||||
if (imageParts.length === 0) {
|
||||
return {
|
||||
status: "failed",
|
||||
output: null,
|
||||
error: "Global Gemini-dagsbudget är förbrukad.",
|
||||
} as AamosResult<T>;
|
||||
}
|
||||
|
||||
const payload = {
|
||||
contents: [{ parts: [{ text: prompt }, ...imageParts] }],
|
||||
generationConfig: {
|
||||
|
||||
Reference in New Issue
Block a user