@lingjingai/scriptctl 0.63.5 → 0.63.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/changes/0.63.6.md +5 -0
- package/dist/review-agent.js +36 -49
- package/dist/review-agent.js.map +3 -3
- package/package.json +3 -2
package/dist/review-agent.js
CHANGED
|
@@ -2324,6 +2324,7 @@ import { z as z3 } from "zod";
|
|
|
2324
2324
|
|
|
2325
2325
|
// packages/review-agent/src/models.ts
|
|
2326
2326
|
import { createGoogleGenerativeAI } from "@ai-sdk/google";
|
|
2327
|
+
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
|
2327
2328
|
import { APICallError } from "@ai-sdk/provider";
|
|
2328
2329
|
import { z as z2 } from "zod";
|
|
2329
2330
|
|
|
@@ -2379,44 +2380,41 @@ function reviewRoutes(config) {
|
|
|
2379
2380
|
});
|
|
2380
2381
|
return routes;
|
|
2381
2382
|
}
|
|
2382
|
-
function agentModels(config, onFailure,
|
|
2383
|
-
let
|
|
2384
|
-
return reviewRoutes(config).filter((route) => route.apiKey).map((route) =>
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
const
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
});
|
|
2409
|
-
}
|
|
2410
|
-
return result;
|
|
2411
|
-
} catch (error) {
|
|
2412
|
-
onFailure?.(route, error);
|
|
2413
|
-
throw error;
|
|
2383
|
+
function agentModels(config, onFailure, onUsage) {
|
|
2384
|
+
let calls = 0;
|
|
2385
|
+
return reviewRoutes(config).filter((route) => route.apiKey).map((route) => {
|
|
2386
|
+
const model = route.provider === "google-gemini" ? createGoogleGenerativeAI({ apiKey: route.apiKey, baseURL: route.baseUrl, fetch: proxyFetch })(route.model) : createOpenAICompatible({ name: "doubao", apiKey: route.apiKey, baseURL: route.baseUrl, fetch: proxyFetch })(route.model);
|
|
2387
|
+
const generate = model.doGenerate.bind(model);
|
|
2388
|
+
model.doGenerate = async (options) => {
|
|
2389
|
+
const callKey = `call:${++calls}`;
|
|
2390
|
+
try {
|
|
2391
|
+
const result = await generate(options);
|
|
2392
|
+
const u = result.usage;
|
|
2393
|
+
onUsage?.({
|
|
2394
|
+
call_key: callKey,
|
|
2395
|
+
provider: route.provider,
|
|
2396
|
+
model: route.model,
|
|
2397
|
+
input_tokens: u.inputTokens.total ?? 0,
|
|
2398
|
+
cached_input_tokens: u.inputTokens.cacheRead ?? 0,
|
|
2399
|
+
output_tokens: u.outputTokens.total ?? 0,
|
|
2400
|
+
reasoning_tokens: u.outputTokens.reasoning ?? 0
|
|
2401
|
+
});
|
|
2402
|
+
if (route.provider === "google-gemini" && (["content-filter", "error"].includes(result.finishReason.unified) || ["PROHIBITED_CONTENT", "SAFETY", "RECITATION", "BLOCKLIST", "MALFORMED_FUNCTION_CALL"].includes(result.finishReason.raw ?? ""))) {
|
|
2403
|
+
throw new APICallError({
|
|
2404
|
+
message: `Gemini finishReason=${result.finishReason.raw ?? result.finishReason.unified}`,
|
|
2405
|
+
url: `${route.baseUrl}/models/${route.model}:generateContent`,
|
|
2406
|
+
requestBodyValues: {},
|
|
2407
|
+
isRetryable: false
|
|
2408
|
+
});
|
|
2414
2409
|
}
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2410
|
+
return result;
|
|
2411
|
+
} catch (error) {
|
|
2412
|
+
onFailure?.(route, error);
|
|
2413
|
+
throw error;
|
|
2414
|
+
}
|
|
2415
|
+
};
|
|
2416
|
+
return { id: `${route.provider}/${route.model}`, model, maxRetries: route.maxAttempts - 1 };
|
|
2417
|
+
});
|
|
2420
2418
|
}
|
|
2421
2419
|
var geminiResponse = z2.object({
|
|
2422
2420
|
candidates: z2.array(z2.object({
|
|
@@ -3234,19 +3232,8 @@ async function reviewUnit(doc, episode, video, config, asr) {
|
|
|
3234
3232
|
schema: z6.object({ message: z6.string().describe("\u4E00\u4E24\u53E5\u8BDD\u603B\u7ED3\u672C\u96C6\u5BA1\u6838\u7ED3\u679C") }),
|
|
3235
3233
|
errorStrategy: "warn"
|
|
3236
3234
|
},
|
|
3237
|
-
onStepFinish: (
|
|
3235
|
+
onStepFinish: () => {
|
|
3238
3236
|
steps += 1;
|
|
3239
|
-
const model = step2.model?.modelId ?? step2.response.modelId ?? config.model;
|
|
3240
|
-
const u = step2.usage;
|
|
3241
|
-
usage.push({
|
|
3242
|
-
call_key: `review:ep${episode}:agent:${steps}`,
|
|
3243
|
-
provider: step2.model?.provider?.startsWith("doubao") ? "doubao" : "google-gemini",
|
|
3244
|
-
model,
|
|
3245
|
-
input_tokens: u.inputTokens ?? 0,
|
|
3246
|
-
cached_input_tokens: u.cachedInputTokens ?? 0,
|
|
3247
|
-
output_tokens: u.outputTokens ?? 0,
|
|
3248
|
-
reasoning_tokens: u.reasoningTokens ?? 0
|
|
3249
|
-
});
|
|
3250
3237
|
}
|
|
3251
3238
|
});
|
|
3252
3239
|
steps = response?.steps?.length ?? 0;
|