@anvia/core 0.26.0 → 1.0.0-rc.1
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/README.md +21 -11
- package/dist/agent/index.d.ts +26 -68
- package/dist/agent/index.js +20 -17
- package/dist/agent-DGYY_onS.d.ts +145 -0
- package/dist/audio-generation/index.d.ts +12 -14
- package/dist/audio-generation/index.js +5 -39
- package/dist/audio-generation/index.js.map +1 -1
- package/dist/{chunk-MRQLEK2B.js → chunk-5XKDW36Z.js} +30 -7
- package/dist/chunk-5XKDW36Z.js.map +1 -0
- package/dist/chunk-6WGGTJE6.js +139 -0
- package/dist/chunk-6WGGTJE6.js.map +1 -0
- package/dist/chunk-A3UBYTJT.js +157 -0
- package/dist/chunk-A3UBYTJT.js.map +1 -0
- package/dist/{chunk-NCPN4SJR.js → chunk-DMPUP4R3.js} +10 -10
- package/dist/chunk-DMPUP4R3.js.map +1 -0
- package/dist/{chunk-MNWK2USR.js → chunk-DZ3CKYTH.js} +29 -5
- package/dist/chunk-DZ3CKYTH.js.map +1 -0
- package/dist/{chunk-CWUJUSOS.js → chunk-FNQB2JEH.js} +1 -1
- package/dist/chunk-FNQB2JEH.js.map +1 -0
- package/dist/chunk-I6G7BC42.js +41 -0
- package/dist/chunk-I6G7BC42.js.map +1 -0
- package/dist/{chunk-BALBBVI3.js → chunk-IL3ZSNJI.js} +2720 -1704
- package/dist/chunk-IL3ZSNJI.js.map +1 -0
- package/dist/chunk-J6GNQART.js +122 -0
- package/dist/chunk-J6GNQART.js.map +1 -0
- package/dist/{chunk-MC3CCKEB.js → chunk-M3IOWB4Y.js} +124 -65
- package/dist/chunk-M3IOWB4Y.js.map +1 -0
- package/dist/chunk-QY5GZ7HR.js +39 -0
- package/dist/chunk-QY5GZ7HR.js.map +1 -0
- package/dist/{chunk-MELYDKWQ.js → chunk-R2LJSQUW.js} +190 -20
- package/dist/chunk-R2LJSQUW.js.map +1 -0
- package/dist/{chunk-WQKHFADH.js → chunk-RFDVKCIE.js} +3 -3
- package/dist/chunk-RFDVKCIE.js.map +1 -0
- package/dist/chunk-RMUBRRSK.js +34 -0
- package/dist/chunk-RMUBRRSK.js.map +1 -0
- package/dist/{chunk-I6XOQ4LK.js → chunk-RXKHOYEH.js} +1 -1
- package/dist/chunk-RXKHOYEH.js.map +1 -0
- package/dist/chunk-XDRSPSR7.js +38 -0
- package/dist/chunk-XDRSPSR7.js.map +1 -0
- package/dist/completion/index.d.ts +5 -36
- package/dist/completion/index.js +4 -5
- package/dist/dynamic-tools-i9woysFa.d.ts +33 -0
- package/dist/embeddings/index.d.ts +2 -2
- package/dist/embeddings/index.js +1 -2
- package/dist/{errors-2moLDuuN.d.ts → errors-CYKUcU89.d.ts} +2 -2
- package/dist/evals/index.d.ts +22 -15
- package/dist/evals/index.js +57 -35
- package/dist/evals/index.js.map +1 -1
- package/dist/extractor/index.d.ts +23 -35
- package/dist/extractor/index.js +7 -21
- package/dist/guardrails/index.d.ts +2 -2
- package/dist/guardrails/index.js +1 -1
- package/dist/image-generation/index.d.ts +12 -14
- package/dist/image-generation/index.js +5 -39
- package/dist/image-generation/index.js.map +1 -1
- package/dist/index-DxB74ybJ.d.ts +349 -0
- package/dist/index.d.ts +20 -17
- package/dist/index.js +31 -36
- package/dist/internal/agent.d.ts +152 -9
- package/dist/internal/agent.js +22 -17
- package/dist/{json-BVPssigK.d.ts → json-Zo7K3xmt.d.ts} +12 -11
- package/dist/loaders/index.d.ts +5 -10
- package/dist/loaders/index.js.map +1 -1
- package/dist/mcp/index.d.ts +4 -4
- package/dist/mcp/index.js.map +1 -1
- package/dist/memory/index.d.ts +4 -4
- package/dist/memory/index.js +6 -7
- package/dist/middleware-KynLg_RW.d.ts +56 -0
- package/dist/observability/index.d.ts +6 -3
- package/dist/observability/index.js.map +1 -1
- package/dist/pipeline/index.d.ts +40 -47
- package/dist/pipeline/index.js +99 -99
- package/dist/pipeline/index.js.map +1 -1
- package/dist/retry-D3Ruy-ba.d.ts +15 -0
- package/dist/skills/index.d.ts +4 -4
- package/dist/skills/index.js +5 -6
- package/dist/streaming/index.js +37 -3
- package/dist/streaming/index.js.map +1 -1
- package/dist/{think-tool-DfCMuO8e.d.ts → think-tool-DZqZj2LV.d.ts} +5 -5
- package/dist/tool/index.d.ts +8 -6
- package/dist/tool/index.js +12 -15
- package/dist/tool-C_8GudXn.d.ts +49 -0
- package/dist/transcription/index.d.ts +14 -16
- package/dist/transcription/index.js +5 -57
- package/dist/transcription/index.js.map +1 -1
- package/dist/type-utils-CtHVDRn_.d.ts +6 -0
- package/dist/{types-G12i56s2.d.ts → types-B3A4YxaA.d.ts} +1 -1
- package/dist/{types-BrLbKnEz.d.ts → types-BBEGKB9m.d.ts} +1 -1
- package/dist/{types-O-abTIin.d.ts → types-DT3nEemY.d.ts} +3 -3
- package/dist/{types-04LqWrmy.d.ts → types-DhQfwiZn.d.ts} +1 -1
- package/dist/{types-JJCxRnaZ.d.ts → types-DulRCYdB.d.ts} +2 -2
- package/dist/{types-BCTRUGex.d.ts → types-p55Jc-sr.d.ts} +1 -1
- package/dist/ui/index.d.ts +1 -1
- package/dist/ui/index.js +1 -1
- package/dist/vector-store/index.d.ts +5 -5
- package/dist/vector-store/index.js +4 -4
- package/package.json +2 -10
- package/dist/agent-x3YTyv5i.d.ts +0 -222
- package/dist/chunk-2ODTMRHP.js +0 -54
- package/dist/chunk-2ODTMRHP.js.map +0 -1
- package/dist/chunk-BALBBVI3.js.map +0 -1
- package/dist/chunk-CWUJUSOS.js.map +0 -1
- package/dist/chunk-DALYP4PX.js +0 -225
- package/dist/chunk-DALYP4PX.js.map +0 -1
- package/dist/chunk-HYUYZEAJ.js +0 -223
- package/dist/chunk-HYUYZEAJ.js.map +0 -1
- package/dist/chunk-I6XOQ4LK.js.map +0 -1
- package/dist/chunk-JI5YZWNT.js +0 -220
- package/dist/chunk-JI5YZWNT.js.map +0 -1
- package/dist/chunk-MC3CCKEB.js.map +0 -1
- package/dist/chunk-MELYDKWQ.js.map +0 -1
- package/dist/chunk-MNWK2USR.js.map +0 -1
- package/dist/chunk-MRQLEK2B.js.map +0 -1
- package/dist/chunk-NCPN4SJR.js.map +0 -1
- package/dist/chunk-OIMLU4SF.js +0 -20
- package/dist/chunk-OIMLU4SF.js.map +0 -1
- package/dist/chunk-Q25IWLBT.js +0 -138
- package/dist/chunk-Q25IWLBT.js.map +0 -1
- package/dist/chunk-UQX6EXWG.js +0 -33
- package/dist/chunk-UQX6EXWG.js.map +0 -1
- package/dist/chunk-WQKHFADH.js.map +0 -1
- package/dist/chunk-XUUY2L2D.js +0 -42
- package/dist/chunk-XUUY2L2D.js.map +0 -1
- package/dist/chunk-YLMDBQO4.js +0 -141
- package/dist/chunk-YLMDBQO4.js.map +0 -1
- package/dist/hooks/index.d.ts +0 -12
- package/dist/hooks/index.js +0 -17
- package/dist/hooks/index.js.map +0 -1
- package/dist/index-BxSbmOMr.d.ts +0 -257
- package/dist/middleware-Dp3d_pxi.d.ts +0 -90
- package/dist/request/index.d.ts +0 -28
- package/dist/request/index.js +0 -25
- package/dist/request/index.js.map +0 -1
- package/dist/tool-Cohdv5GC.d.ts +0 -65
- package/dist/types-D9JpeAPF.d.ts +0 -114
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { V as VectorMetadata, E as EmbeddingModel,
|
|
2
|
-
export { g as SparseVector,
|
|
1
|
+
import { V as VectorMetadata, E as EmbeddingModel, c as EmbedDocumentsOptions, a as EmbeddedDocument, d as EmbedHybridDocumentsOptions, S as SparseEmbeddingModel, e as SparseEmbedding, f as Embedding } from '../types-p55Jc-sr.js';
|
|
2
|
+
export { g as SparseVector, b as VectorMetadataValue } from '../types-p55Jc-sr.js';
|
|
3
3
|
|
|
4
4
|
declare function dotProduct(left: number[], right: number[]): number;
|
|
5
5
|
declare function cosineSimilarity(left: number[], right: number[]): number;
|
package/dist/embeddings/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as CompletionModel, M as Message, U as Usage } from './types-
|
|
2
|
-
import { S as SummaryMemoryCompactorOptions, e as MemoryCompactor } from './types-
|
|
1
|
+
import { C as CompletionModel, M as Message, U as Usage } from './types-B3A4YxaA.js';
|
|
2
|
+
import { S as SummaryMemoryCompactorOptions, e as MemoryCompactor } from './types-BBEGKB9m.js';
|
|
3
3
|
|
|
4
4
|
declare function createSummaryMemoryCompactor(model: CompletionModel, options?: SummaryMemoryCompactorOptions): MemoryCompactor;
|
|
5
5
|
declare function isMemoryCompactionSummary(message: Message): boolean;
|
package/dist/evals/index.d.ts
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
|
+
import { U as Usage, l as JsonValue, C as CompletionModel, M as Message } from '../types-B3A4YxaA.js';
|
|
1
2
|
import { Z as ZodSchema } from '../zod-schema-C7F4clpm.js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { E as EmbeddingModel } from '../types-BCTRUGex.js';
|
|
3
|
+
import { A as Agent } from '../agent-DGYY_onS.js';
|
|
4
|
+
import { l as AgentResponse } from '../index-DxB74ybJ.js';
|
|
5
|
+
import { E as EmbeddingModel } from '../types-p55Jc-sr.js';
|
|
6
6
|
import 'zod';
|
|
7
7
|
import '../guardrails/index.js';
|
|
8
|
-
import '../
|
|
9
|
-
import '../types-
|
|
10
|
-
import '../
|
|
11
|
-
import '../
|
|
12
|
-
import '../types-
|
|
8
|
+
import '../type-utils-CtHVDRn_.js';
|
|
9
|
+
import '../types-BBEGKB9m.js';
|
|
10
|
+
import '../middleware-KynLg_RW.js';
|
|
11
|
+
import '../tool-C_8GudXn.js';
|
|
12
|
+
import '../types-DulRCYdB.js';
|
|
13
|
+
import '@modelcontextprotocol/sdk/client/sse.js';
|
|
14
|
+
import '@modelcontextprotocol/sdk/client/stdio.js';
|
|
15
|
+
import '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
16
|
+
import '../types-DhQfwiZn.js';
|
|
17
|
+
import '../dynamic-tools-i9woysFa.js';
|
|
18
|
+
import '../types-DT3nEemY.js';
|
|
19
|
+
import '../retry-D3Ruy-ba.js';
|
|
13
20
|
|
|
14
21
|
type EvalOutcome<Score = unknown> = {
|
|
15
22
|
outcome: "pass";
|
|
@@ -381,11 +388,11 @@ declare function knowledgeRetention<Input, Output, Expected = unknown, const Nam
|
|
|
381
388
|
}): EvalMetric<Input, Output, number, Expected, Name>;
|
|
382
389
|
type ConversationSource = EvalTurn[] | Message[];
|
|
383
390
|
|
|
384
|
-
type AgentEvalTargetOptions<Input, Output =
|
|
391
|
+
type AgentEvalTargetOptions<Input, Output = AgentResponse, Expected = unknown> = {
|
|
385
392
|
prompt?: ((input: Input, testCase: EvalCase<Input, Expected>) => string | Message) | undefined;
|
|
386
|
-
output?: ((response:
|
|
393
|
+
output?: ((response: AgentResponse, testCase: EvalCase<Input, Expected>) => Output) | undefined;
|
|
387
394
|
};
|
|
388
|
-
declare function agentEvalTarget<Input, Expected = unknown>(agent: Agent, options?: AgentEvalTargetOptions<Input,
|
|
395
|
+
declare function agentEvalTarget<Input, Expected = unknown>(agent: Agent, options?: AgentEvalTargetOptions<Input, AgentResponse, Expected>): EvalTarget<Input, AgentResponse, Expected>;
|
|
389
396
|
declare function agentEvalTarget<Input, Output, Expected = unknown>(agent: Agent, options: AgentEvalTargetOptions<Input, Output, Expected>): EvalTarget<Input, Output, Expected>;
|
|
390
397
|
|
|
391
398
|
type EvalOutputFormat = "pretty" | "json" | "quiet";
|
|
@@ -599,7 +606,7 @@ type DefinedEvalSuite<Cases extends readonly EvalCaseLike[], Output, Metrics ext
|
|
|
599
606
|
target: EvalTarget<EvalCasesInput<Cases>, Output, EvalCasesExpected<Cases>>;
|
|
600
607
|
metrics: Metrics;
|
|
601
608
|
};
|
|
602
|
-
type
|
|
609
|
+
type EvalMetricFactory<Input, Output, Expected = unknown> = {
|
|
603
610
|
defineMetric<const Name extends string = string>(metric: EvalMetric<Input, Output, boolean, Expected, Name> & {
|
|
604
611
|
dataType: "BOOLEAN";
|
|
605
612
|
}): EvalMetric<Input, Output, boolean, Expected, Name>;
|
|
@@ -626,11 +633,11 @@ type EvalSuiteTypeBuilder<Input, Output, Expected = unknown> = {
|
|
|
626
633
|
}): EvalMetric<Input, Output, Score, Expected, Name>;
|
|
627
634
|
};
|
|
628
635
|
declare function defineEvalCases<const Cases extends readonly EvalCaseLike[]>(cases: Cases): Cases;
|
|
629
|
-
declare function defineEvalSuite<Input, Output, Expected = unknown>():
|
|
636
|
+
declare function defineEvalSuite<Input, Output, Expected = unknown>(): EvalMetricFactory<Input, Output, Expected>;
|
|
630
637
|
declare function defineEvalSuite<const Cases extends readonly EvalCaseLike[], const Target extends (input: EvalCasesInput<Cases>, testCase: EvalCase<EvalCasesInput<Cases>, EvalCasesExpected<Cases>>) => unknown, const Metrics extends readonly EvalMetric<EvalCasesInput<Cases>, Awaited<ReturnType<Target>>, unknown, EvalCasesExpected<Cases>, string>[]>(options: DefinedEvalSuite<Cases, Awaited<ReturnType<Target>>, Metrics> & {
|
|
631
638
|
target: Target;
|
|
632
639
|
}): DefinedEvalSuite<Cases, Awaited<ReturnType<Target>>, Metrics> & {
|
|
633
640
|
target: Target;
|
|
634
641
|
};
|
|
635
642
|
|
|
636
|
-
export { type AbstentionCategory, type AbstentionOptions, type AgentEvalTargetOptions, type AnswerRelevancyOptions, type AnyEvalMetric, type ContainsAllOptions, type ContainsAnyOptions, type ContainsListOptions, type ContainsOptions, type DefaultEvalActual, type DefinedEvalSuite, type DoesNotMatchOptions, EvalAssertionError, type EvalCase, type EvalCaseRequirements, type EvalCaseResult, type EvalCasesExpected, type EvalCasesForMetrics, type EvalCasesInput, type EvalCostCalculatorArgs, type EvalCostOptions, type EvalCostSummary, type EvalDataType, type EvalExpectations, type EvalExpectedOutcomes, type EvalExpectedTotals, type EvalMetadata, type EvalMetric, type EvalMetricArgs, type EvalMetricDescriptor, type EvalMetricResult, type EvalMetricResultFor, type EvalMetricScore, EvalOutcome, type EvalOutcomeStatus, type EvalOutputFormat, type EvalOutputWriters, type EvalReportArgs, type EvalReporter, type EvalRunContext, type EvalRunEndArgs, type EvalRunOptions, type EvalRunStartArgs, type EvalScoreDirection, type EvalScoreMap, type EvalScoreProjection, type EvalSuiteResult, type
|
|
643
|
+
export { type AbstentionCategory, type AbstentionOptions, type AgentEvalTargetOptions, type AnswerRelevancyOptions, type AnyEvalMetric, type ContainsAllOptions, type ContainsAnyOptions, type ContainsListOptions, type ContainsOptions, type DefaultEvalActual, type DefinedEvalSuite, type DoesNotMatchOptions, EvalAssertionError, type EvalCase, type EvalCaseRequirements, type EvalCaseResult, type EvalCasesExpected, type EvalCasesForMetrics, type EvalCasesInput, type EvalCostCalculatorArgs, type EvalCostOptions, type EvalCostSummary, type EvalDataType, type EvalExpectations, type EvalExpectedOutcomes, type EvalExpectedTotals, type EvalMetadata, type EvalMetric, type EvalMetricArgs, type EvalMetricDescriptor, type EvalMetricResult, type EvalMetricResultFor, type EvalMetricScore, EvalOutcome, type EvalOutcomeStatus, type EvalOutputFormat, type EvalOutputWriters, type EvalReportArgs, type EvalReporter, type EvalRunContext, type EvalRunEndArgs, type EvalRunOptions, type EvalRunStartArgs, type EvalScoreDirection, type EvalScoreMap, type EvalScoreProjection, type EvalSuiteResult, type EvalTarget, type EvalTargetUsageSelector, type EvalTotals, type EvalTraceCarrier, type EvalTraceRef, type EvalTraceSelector, type EvalTraceSelectorArgs, type EvalTurn, type EvalUsageSummary, type ExactMatchOptions, type FaithfulnessOptions, type GEvalOptions, type GEvalParameter, type GEvalRubric, type HallucinationOptions, type JsonCorrectnessOptions, type KnowledgeRetentionOptions, type LlmJudgeOptions, type LlmScoreMetricScore, type LlmScoreOptions, type MatchesOptions, type MaxLengthOptions, type NotContainsOptions, type PrintEvalResultOptions, type PromptAlignmentOptions, type RequiredFieldsOptions, type RunEvalCliOptions, type RunEvalSuiteOptions, type SelectorOrValue, type SemanticSimilarityOptions, type SummarizationOptions, type TurnRelevancyOptions, type ValueSelector, abstention, agentEvalTarget, answerRelevancy, assertEvalOutcomes, assertEvalTotals, contains, containsAll, containsAny, defaultEvalTraceSelector, defineEvalCases, defineEvalSuite, defineMetric, doesNotMatch, evalExitCode, exactMatch, faithfulness, gEval, hallucination, jsonCorrectness, knowledgeRetention, llmJudge, llmScore, matches, maxLength, notContains, printEvalResult, projectEvalOutcome, promptAlignment, requiredFields, resolveEvalTraceRef, runEvalCli, runEvalSuite, selectPromptOutput, semanticSimilarity, summarization, turnRelevancy };
|
package/dist/evals/index.js
CHANGED
|
@@ -1,30 +1,26 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-JI5YZWNT.js";
|
|
5
|
-
import "../chunk-DALYP4PX.js";
|
|
6
|
-
import "../chunk-BALBBVI3.js";
|
|
2
|
+
cancelAgentApproval
|
|
3
|
+
} from "../chunk-IL3ZSNJI.js";
|
|
7
4
|
import "../chunk-YK4WAAS4.js";
|
|
8
|
-
import "../chunk-
|
|
9
|
-
import "../chunk-
|
|
10
|
-
import "../chunk-
|
|
11
|
-
import "../chunk-2ODTMRHP.js";
|
|
12
|
-
import "../chunk-UQX6EXWG.js";
|
|
13
|
-
import "../chunk-MRQLEK2B.js";
|
|
5
|
+
import "../chunk-6WGGTJE6.js";
|
|
6
|
+
import "../chunk-R2LJSQUW.js";
|
|
7
|
+
import "../chunk-5XKDW36Z.js";
|
|
14
8
|
import {
|
|
15
9
|
cosineSimilarity,
|
|
16
|
-
embedText
|
|
17
|
-
} from "../chunk-MNWK2USR.js";
|
|
18
|
-
import {
|
|
10
|
+
embedText,
|
|
19
11
|
mapWithConcurrency
|
|
20
|
-
} from "../chunk-
|
|
21
|
-
import
|
|
22
|
-
|
|
12
|
+
} from "../chunk-DZ3CKYTH.js";
|
|
13
|
+
import {
|
|
14
|
+
Extractor
|
|
15
|
+
} from "../chunk-J6GNQART.js";
|
|
16
|
+
import "../chunk-I6G7BC42.js";
|
|
17
|
+
import "../chunk-M3IOWB4Y.js";
|
|
18
|
+
import "../chunk-RFDVKCIE.js";
|
|
23
19
|
import {
|
|
24
20
|
Usage
|
|
25
21
|
} from "../chunk-ADH7NNCS.js";
|
|
26
|
-
import "../chunk-
|
|
27
|
-
import "../chunk-
|
|
22
|
+
import "../chunk-A3UBYTJT.js";
|
|
23
|
+
import "../chunk-FNQB2JEH.js";
|
|
28
24
|
|
|
29
25
|
// src/evals/advanced-metrics.ts
|
|
30
26
|
import { z } from "zod";
|
|
@@ -58,7 +54,15 @@ function errorMessage(error) {
|
|
|
58
54
|
|
|
59
55
|
// src/evals/judge.ts
|
|
60
56
|
async function runJudge(args) {
|
|
61
|
-
const
|
|
57
|
+
const extractor = new Extractor({
|
|
58
|
+
model: args.model,
|
|
59
|
+
outputSchema: args.schema,
|
|
60
|
+
instructions: args.instructions
|
|
61
|
+
});
|
|
62
|
+
const result = await extractor.extractResult(args.prompt, {
|
|
63
|
+
temperature: 0,
|
|
64
|
+
retries: args.retries <= 0 ? void 0 : { maxAttempts: Math.trunc(args.retries) + 1 }
|
|
65
|
+
});
|
|
62
66
|
return { data: result.data, usage: result.usage };
|
|
63
67
|
}
|
|
64
68
|
function addUsage(...values) {
|
|
@@ -1119,7 +1123,11 @@ function contentText(content) {
|
|
|
1119
1123
|
function agentEvalTarget(agent, options = {}) {
|
|
1120
1124
|
return async (input, testCase) => {
|
|
1121
1125
|
const prompt = options.prompt?.(input, testCase) ?? String(input);
|
|
1122
|
-
const response = await agent.
|
|
1126
|
+
const response = await agent.generate(prompt);
|
|
1127
|
+
if (response.status === "approval_required") {
|
|
1128
|
+
await cancelAgentApproval(response, "Agent eval targets cannot suspend for tool approval.");
|
|
1129
|
+
throw new Error("Agent eval targets cannot suspend for tool approval.");
|
|
1130
|
+
}
|
|
1123
1131
|
return options.output === void 0 ? response : options.output(response, testCase);
|
|
1124
1132
|
};
|
|
1125
1133
|
}
|
|
@@ -2006,16 +2014,21 @@ function semanticSimilarity(options) {
|
|
|
2006
2014
|
};
|
|
2007
2015
|
}
|
|
2008
2016
|
function llmJudge(options) {
|
|
2009
|
-
const extractor = new
|
|
2010
|
-
options.
|
|
2011
|
-
|
|
2017
|
+
const extractor = new Extractor({
|
|
2018
|
+
model: options.model,
|
|
2019
|
+
outputSchema: options.schema,
|
|
2020
|
+
instructions: options.instructions ?? "Judge the eval case by the requested schema. Submit the judgment using the schema."
|
|
2021
|
+
});
|
|
2012
2022
|
return {
|
|
2013
2023
|
name: options.name ?? "llm_judge",
|
|
2014
2024
|
required: options.required ?? true,
|
|
2015
2025
|
async evaluate(args) {
|
|
2016
2026
|
try {
|
|
2017
|
-
const result = await extractor.
|
|
2018
|
-
await resolveJudgePrompt(options.prompt, args)
|
|
2027
|
+
const result = await extractor.extractResult(
|
|
2028
|
+
await resolveJudgePrompt(options.prompt, args),
|
|
2029
|
+
{
|
|
2030
|
+
retries: evalExtractionRetries(options.retries)
|
|
2031
|
+
}
|
|
2019
2032
|
);
|
|
2020
2033
|
return options.passes(result.data) ? EvalOutcome.pass(result.data, { usage: result.usage }) : EvalOutcome.fail(result.data, { usage: result.usage });
|
|
2021
2034
|
} catch (error) {
|
|
@@ -2026,18 +2039,17 @@ function llmJudge(options) {
|
|
|
2026
2039
|
}
|
|
2027
2040
|
function llmScore(options) {
|
|
2028
2041
|
const criteria = Array.isArray(options.criteria) ? options.criteria.join("\n") : options.criteria;
|
|
2029
|
-
const extractor = new
|
|
2030
|
-
options.model,
|
|
2031
|
-
z2.object({
|
|
2042
|
+
const extractor = new Extractor({
|
|
2043
|
+
model: options.model,
|
|
2044
|
+
outputSchema: z2.object({
|
|
2032
2045
|
score: z2.number(),
|
|
2033
2046
|
feedback: z2.string()
|
|
2034
|
-
})
|
|
2035
|
-
|
|
2036
|
-
options.instructions ?? `Score the eval case against these criteria:
|
|
2047
|
+
}),
|
|
2048
|
+
instructions: options.instructions ?? `Score the eval case against these criteria:
|
|
2037
2049
|
${criteria}
|
|
2038
2050
|
|
|
2039
2051
|
Return a score between 0 and 1 and brief feedback.`
|
|
2040
|
-
)
|
|
2052
|
+
});
|
|
2041
2053
|
return {
|
|
2042
2054
|
name: options.name ?? "llm_score",
|
|
2043
2055
|
required: options.required ?? true,
|
|
@@ -2047,8 +2059,11 @@ Return a score between 0 and 1 and brief feedback.`
|
|
|
2047
2059
|
threshold: options.threshold,
|
|
2048
2060
|
async evaluate(args) {
|
|
2049
2061
|
try {
|
|
2050
|
-
const result = await extractor.
|
|
2051
|
-
await resolveJudgePrompt(options.prompt, args)
|
|
2062
|
+
const result = await extractor.extractResult(
|
|
2063
|
+
await resolveJudgePrompt(options.prompt, args),
|
|
2064
|
+
{
|
|
2065
|
+
retries: evalExtractionRetries(options.retries)
|
|
2066
|
+
}
|
|
2052
2067
|
);
|
|
2053
2068
|
const score = result.data;
|
|
2054
2069
|
if (score.score < 0 || score.score > 1) {
|
|
@@ -2064,6 +2079,13 @@ Return a score between 0 and 1 and brief feedback.`
|
|
|
2064
2079
|
}
|
|
2065
2080
|
};
|
|
2066
2081
|
}
|
|
2082
|
+
function evalExtractionRetries(retries) {
|
|
2083
|
+
const retryCount = Math.max(0, Math.trunc(retries ?? 0));
|
|
2084
|
+
if (retryCount === 0) {
|
|
2085
|
+
return void 0;
|
|
2086
|
+
}
|
|
2087
|
+
return { maxAttempts: retryCount + 1 };
|
|
2088
|
+
}
|
|
2067
2089
|
|
|
2068
2090
|
// src/evals/suite.ts
|
|
2069
2091
|
function defineEvalCases(cases) {
|