Skip to content

Commit cc601f3

Browse files
author
Andrei Bratu
committed
qa pass
1 parent 5d153a8 commit cc601f3

1 file changed

Lines changed: 30 additions & 15 deletions

File tree

src/evals/run.ts

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,12 @@ export async function runEval<
157157
if (function_ === undefined) {
158158
// TODO: trigger run when updated API is available
159159
process.stdout.write(
160-
`${CYAN}\nRunning '${hlFile.name}' ${_.capitalize(hlFile.type)} over the Dataset '${hlDataset.name}'${RESET}\n`,
160+
`${CYAN}\nRunning '${hlFile.name}' ${_.capitalize(hlFile.type)} over the '${hlDataset.name}' Dataset${RESET}\n`,
161161
);
162162
} else {
163163
// Running the evaluation locally
164164
process.stdout.write(
165-
`${CYAN}\nRunning '${hlFile.name}' ${_.capitalize(hlFile.type)} over the Dataset '${hlDataset.name}' locally...${RESET}\n\n`,
165+
`${CYAN}\nRunning '${hlFile.name}' ${_.capitalize(hlFile.type)} over the '${hlDataset.name}' Dataset locally...${RESET}\n\n`,
166166
);
167167
}
168168

@@ -609,39 +609,54 @@ async function resolveFile<I extends Record<string, unknown> & { message?: any[]
609609
client: HumanloopClient,
610610
fileConfig: FileEvalConfig<I, O>,
611611
): Promise<[EvaluatedFile, FileEvalConfig<I, O>["callable"]]> {
612-
const version = fileConfig.version;
613-
const path = fileConfig.path;
614612
const fileId = fileConfig.id;
613+
const path = fileConfig.path;
614+
const versionId = fileConfig.versionId;
615+
const environment = fileConfig.environment;
615616
const callable = getFileCallable(fileConfig);
617+
const version = fileConfig.version;
616618

617-
if (version && !path && !fileId) {
619+
if (callable && !path && !fileId) {
618620
throw new HumanloopRuntimeError(
619-
`You are trying to create a new version of the File by passing the ${version} argument. You must pass either the file.path or file.fileId argument.`,
621+
`You are trying to create a new version of the File by passing the ${callable} argument. You must pass either the \`file.path\` or \`file.fileId\` argument and provide proper \`file.version\` for upserting the File.`,
620622
);
621623
}
622624
let hlFile = await safeGetDefaultFileVersion(client, fileConfig);
623-
if (fileConfig.version) {
624-
return [hlFile as unknown as EvaluatedFile, getFileCallable(fileConfig)];
625-
}
626-
const versionId = fileConfig.version;
627-
const environment = fileConfig.environment;
628625

629-
if (!versionId && !environment) {
630-
return [await upsertFile(client, fileConfig), callable];
626+
if ((versionId || environment) && (callable || version)) {
627+
throw new HumanloopRuntimeError(
628+
"You are trying to create a local Evaluation while requesting a specific File version by version ID or environment.",
629+
);
631630
}
632631

633632
if (callable) {
634-
throw new HumanloopRuntimeError(
635-
"You cannot request local evaluation while requesting a specific File version by version ID or environment",
633+
// User responsibility to provide adequate file.version for upserting the file
634+
console.info(
635+
`${CYAN}Upserting a new File version based on \`file.version\`. Will use provided callable for generating Logs.${RESET}\n`,
636636
);
637+
try {
638+
return [await upsertFile(client, fileConfig), callable];
639+
} catch (error: any) {
640+
throw new HumanloopRuntimeError(
641+
`Error upserting File. Please ensure \`file.version\` is valid: ${error.toString()}`,
642+
);
643+
}
644+
}
645+
646+
if (!versionId && !environment) {
647+
// Return default version of the file
648+
return [hlFile as unknown as EvaluatedFile, undefined];
637649
}
638650

639651
if (!fileId && (versionId || environment)) {
640652
throw new HumanloopRuntimeError(
641653
"You must provide the `file.id` when addressing a file by version ID or environment",
642654
);
643655
}
656+
657+
// Use version_id or environment to retrieve specific version of the File
644658
const subclient = getSubclient(client, fileConfig);
659+
// Let backend handle case where both or none of version_id and environment are provided
645660
return [await subclient.get(fileId!, { versionId, environment }), undefined];
646661
}
647662

0 commit comments

Comments
 (0)