Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 15 additions & 26 deletions genkit-tools/common/src/eval/evaluate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import {
import {
evaluatorName,
generateTestCaseId,
getAction,
getEvalExtractors,
getModelInput,
hasAction,
Expand Down Expand Up @@ -67,6 +66,8 @@ interface FullInferenceSample {

const SUPPORTED_ACTION_TYPES = ['flow', 'model', 'executable-prompt'] as const;
type SupportedActionType = (typeof SUPPORTED_ACTION_TYPES)[number];
const GENERATE_ACTION_UTIL = '/util/generate';

/**
* Starts a new evaluation run. Intended to be used via the reflection API.
*/
Expand Down Expand Up @@ -385,14 +386,16 @@ async function runPromptAction(params: {
promptConfig?: any;
}): Promise<InferenceRunState> {
const { manager, actionRef, sample, context, promptConfig } = { ...params };

const { model: modelFromConfig, ...restOfConfig } = promptConfig ?? {};
const model = await resolveModel({ manager, actionRef, modelFromConfig });
if (!model) {
const { model: modelFromConfig, ...restOfConfig } = promptConfig;
if (!modelFromConfig) {
throw new Error(
'Could not resolve model. Please specify model and try again'
'Missing model: Please specific model for prompt evaluation'
);
}
const model = modelFromConfig.split('/model/').pop();
if (!model) {
throw new Error(`Improper model provided: ${modelFromConfig}`);
}
let state: InferenceRunState;
let renderedPrompt: {
result: GenerateActionOptions;
Expand Down Expand Up @@ -430,11 +433,14 @@ async function runPromptAction(params: {
// Step 2. Run rendered prompt on the model
try {
let modelInput = renderedPrompt.result;
if (restOfConfig) {
modelInput = { ...modelInput, config: restOfConfig };
// Override with runtime specific config
if (Object.keys(restOfConfig ?? {}).length > 0) {
modelInput = { ...modelInput, model, config: restOfConfig };
} else {
modelInput = { ...modelInput, model };
}
const runActionResponse = await manager.runAction({
key: model,
key: GENERATE_ACTION_UTIL,
input: modelInput,
});
const traceIds = runActionResponse.telemetry?.traceId
Expand Down Expand Up @@ -541,23 +547,6 @@ async function gatherEvalInput(params: {
};
}

async function resolveModel(params: {
manager: RuntimeManager;
actionRef: string;
modelFromConfig?: string;
}) {
const { manager, actionRef, modelFromConfig } = { ...params };

// Prefer to use modelFromConfig
if (modelFromConfig) {
return modelFromConfig;
}

const actionData = await getAction({ manager, actionRef });
const promptMetadata = actionData?.metadata?.prompt as any;
return promptMetadata?.model ? `/model/${promptMetadata?.model}` : undefined;
}

function getSpanErrorMessage(span: SpanData): string | undefined {
if (span && span.status?.code === 2 /* SpanStatusCode.ERROR */) {
// It's possible for a trace to have multiple exception events,
Expand Down
2 changes: 1 addition & 1 deletion js/testapps/evals/prompts/hello.prompt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
model: googleai/gemini-2.5-flash
config:
temperature: 0.75
topK: 10
input:
schema:
query: string
Expand Down
Loading