jev-recipes 0.9.9 → 0.9.11
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.
|
@@ -2,9 +2,9 @@ import type { FlexibleSchema, LanguageModel, PrepareStepFunction, StopCondition,
|
|
|
2
2
|
import type { RecipeName } from '../../catalog/schema.js';
|
|
3
3
|
import type { ModelRouteResult } from '../../recipes/model-route/index.js';
|
|
4
4
|
import type { RecipeOptions } from '../../src/schema.js';
|
|
5
|
-
import type { BlockedToolOutput, CompletionOptions, CompletionToolOutput, GuardOptions, RecipeToolOptions } from '../shared.js';
|
|
6
|
-
export type { BlockedToolOutput, CompletionEvent, CompletionOptions, CompletionToolOutput, GuardEvent, GuardOptions, RecipeToolOptions, } from '../shared.js';
|
|
7
|
-
export type RecipeTool = Tool<Record<string, unknown>,
|
|
5
|
+
import type { BlockedToolOutput, CompletionOptions, CompletionToolOutput, GuardOptions, RecipeToolOptions, RecipeToolOutput } from '../shared.js';
|
|
6
|
+
export type { BlockedToolOutput, CompletionEvent, CompletionOptions, CompletionToolOutput, GuardEvent, GuardOptions, RecipeToolOptions, RecipeToolOutput, } from '../shared.js';
|
|
7
|
+
export type RecipeTool = Tool<Record<string, unknown>, RecipeToolOutput>;
|
|
8
8
|
export declare function recipeTool(name: RecipeName, options?: RecipeToolOptions): RecipeTool;
|
|
9
9
|
export declare function recipeTools(names: readonly RecipeName[], options?: RecipeToolOptions): Record<string, RecipeTool>;
|
|
10
10
|
export type GuardToolsOptions = GuardOptions & {
|
|
@@ -2,7 +2,7 @@ import { DynamicStructuredTool } from '@langchain/core/tools';
|
|
|
2
2
|
import type { RecipeName } from '../../catalog/schema.js';
|
|
3
3
|
import { COMPLETION_TOOL_INPUT_SCHEMA } from '../shared.js';
|
|
4
4
|
import type { CompletionOptions, GuardOptions, RecipeToolOptions } from '../shared.js';
|
|
5
|
-
export type { BlockedToolOutput, CompletionEvent, CompletionOptions, CompletionToolOutput, GuardEvent, GuardOptions, RecipeToolOptions, } from '../shared.js';
|
|
5
|
+
export type { BlockedToolOutput, CompletionEvent, CompletionOptions, CompletionToolOutput, GuardEvent, GuardOptions, RecipeToolOptions, RecipeToolOutput, } from '../shared.js';
|
|
6
6
|
type JsonSchema = Record<string, unknown>;
|
|
7
7
|
export type RecipeTool = DynamicStructuredTool<JsonSchema>;
|
|
8
8
|
export declare function recipeTool(name: RecipeName, options?: RecipeToolOptions): RecipeTool;
|
|
@@ -5,11 +5,12 @@ import type { RecipeOptions } from '../src/schema.js';
|
|
|
5
5
|
export type RecipeToolOptions = RecipeOptions & {
|
|
6
6
|
description?: string;
|
|
7
7
|
};
|
|
8
|
+
export type RecipeToolOutput = Record<string, unknown> | null;
|
|
8
9
|
export type RecipeToolDefinition = {
|
|
9
10
|
name: RecipeName;
|
|
10
11
|
description: string;
|
|
11
12
|
inputSchema: Record<string, unknown>;
|
|
12
|
-
execute: (input: unknown, signal?: AbortSignal) => Promise<
|
|
13
|
+
execute: (input: unknown, signal?: AbortSignal) => Promise<RecipeToolOutput>;
|
|
13
14
|
};
|
|
14
15
|
export type GuardOptions = RecipeOptions & {
|
|
15
16
|
policy?: string;
|
package/dist/src/batch.d.ts
CHANGED
|
@@ -2,11 +2,4 @@ import type { ResultMetadata } from './schema.js';
|
|
|
2
2
|
export type BatchEvaluation<Item> = ResultMetadata & {
|
|
3
3
|
items: Item[];
|
|
4
4
|
};
|
|
5
|
-
|
|
6
|
-
* Split `items` into chunks of at most `batchSize`, evaluate every chunk
|
|
7
|
-
* concurrently with `evaluate`, and merge the per-item results back into the
|
|
8
|
-
* original order. Token usage is summed across requests; `model` comes from
|
|
9
|
-
* the first response. One chunk is one Jev request, so a caller with 1,000
|
|
10
|
-
* inputs and a batch size of 20 makes 50 requests instead of 1,000.
|
|
11
|
-
*/
|
|
12
|
-
export declare function evaluateInBatches<Input, Item>(items: Input[], batchSize: number, evaluate: (chunk: Input[], offset: number) => Promise<BatchEvaluation<Item>>): Promise<BatchEvaluation<Item>>;
|
|
5
|
+
export declare function evaluateInBatches<Input, Item>(items: Input[], batchSize: number, evaluateBatch: (items: Input[], offset: number) => Promise<BatchEvaluation<Item>>): Promise<BatchEvaluation<Item>>;
|
package/dist/src/batch.js
CHANGED
|
@@ -1,30 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
* Split `items` into chunks of at most `batchSize`, evaluate every chunk
|
|
3
|
-
* concurrently with `evaluate`, and merge the per-item results back into the
|
|
4
|
-
* original order. Token usage is summed across requests; `model` comes from
|
|
5
|
-
* the first response. One chunk is one Jev request, so a caller with 1,000
|
|
6
|
-
* inputs and a batch size of 20 makes 50 requests instead of 1,000.
|
|
7
|
-
*/
|
|
8
|
-
export async function evaluateInBatches(items, batchSize, evaluate) {
|
|
1
|
+
export async function evaluateInBatches(items, batchSize, evaluateBatch) {
|
|
9
2
|
if (!Number.isInteger(batchSize) || batchSize < 1)
|
|
10
3
|
throw new Error('batchSize must be a positive integer.');
|
|
11
|
-
const
|
|
4
|
+
const batches = splitIntoBatches(items, batchSize);
|
|
5
|
+
const batchResults = await Promise.allSettled(batches.map(async ({ items, offset }) => evaluateBatch(items, offset)));
|
|
6
|
+
const firstFailedBatch = batchResults.find((result) => result.status === 'rejected');
|
|
7
|
+
if (firstFailedBatch)
|
|
8
|
+
throw firstFailedBatch.reason;
|
|
9
|
+
const evaluations = batchResults.flatMap((result) => result.status === 'fulfilled' ? [result.value] : []);
|
|
10
|
+
return combineBatchResults(evaluations);
|
|
11
|
+
}
|
|
12
|
+
function splitIntoBatches(items, batchSize) {
|
|
13
|
+
const batches = [];
|
|
12
14
|
for (let offset = 0; offset < items.length; offset += batchSize)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return await evaluate(chunk, offset);
|
|
18
|
-
}
|
|
19
|
-
catch (error) {
|
|
20
|
-
firstFailure ??= { error };
|
|
21
|
-
throw error;
|
|
22
|
-
}
|
|
23
|
-
}));
|
|
24
|
-
// Let request recorders finish before a caller archives this failed batch.
|
|
25
|
-
if (firstFailure)
|
|
26
|
-
throw firstFailure.error;
|
|
27
|
-
const evaluations = settled.flatMap((result) => result.status === 'fulfilled' ? [result.value] : []);
|
|
15
|
+
batches.push({ items: items.slice(offset, offset + batchSize), offset });
|
|
16
|
+
return batches;
|
|
17
|
+
}
|
|
18
|
+
function combineBatchResults(evaluations) {
|
|
28
19
|
return {
|
|
29
20
|
items: evaluations.flatMap((evaluation) => evaluation.items),
|
|
30
21
|
model: evaluations[0]?.model ?? 'none',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jev-recipes",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.11",
|
|
4
4
|
"description": "248 small Jev decisions for JavaScript and TypeScript: route, rerank, gate, grade, compare, and label text for agents, RAG, support, code review, and music. Each returns a typed result with explicit uncertainty. Plug into Vercel AI SDK or LangChain agents, import one recipe, or run the CLI with JSON from any language.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|