Skip to content
Open
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
9 changes: 8 additions & 1 deletion app/(main)/evaluations/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
DownloadIcon,
} from "@/app/components/icons";

export default function EvaluationReport() {

Check warning on line 54 in app/(main)/evaluations/[id]/page.tsx

View workflow job for this annotation

GitHub Actions / lint-and-build

Function 'EvaluationReport' has too many statements (36). Maximum allowed is 20
const router = useRouter();
const params = useParams();
const toast = useToast();
Expand Down Expand Up @@ -271,6 +271,10 @@
job.status.toLowerCase() !== "completed" &&
job.status.toLowerCase() !== "failed";

// v2 prompt recommendations require judge-scored traces; v1 runs only
// have cosine similarity and can't be iterated on.
const isJudgedRun = !!scoreObject && isNewScoreObjectV2(scoreObject);

return (
<div className="w-full h-screen flex flex-col bg-bg-secondary">
<div className="flex flex-1 overflow-hidden">
Expand Down Expand Up @@ -356,14 +360,17 @@
onClick={handleIteratePrompt}
disabled={
job.status.toLowerCase() !== "completed" ||
!isJudgedRun ||
isImprovingPrompt ||
isFormatSwitching ||
isResyncing
}
title={
job.status.toLowerCase() !== "completed"
? "Only available for completed evaluations"
: undefined
: !isJudgedRun
? "Prompt iteration requires a judged evaluation run"
: undefined
}
>
{isImprovingPrompt && <Loader size="sm" />}
Expand Down
2 changes: 1 addition & 1 deletion app/api/evaluations/[id]/improve-prompt/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export async function POST(

const { status, data } = await apiClient(
request,
`/api/v1/evaluations/${id}/improve-prompt`,
`/api/v2/evaluations/${id}/improve-prompt`,
{
method: "POST",
body: JSON.stringify(payload),
Expand Down
10 changes: 7 additions & 3 deletions app/api/webhooks/prompt-improvement/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
saveJobSnapshot,
} from "@/app/lib/store/promptImprovementStore";
import { readWebhookSecret } from "@/app/lib/webhookSecret";
import type { PromptImprovementJobPublic } from "@/app/lib/types/promptImprovement";
import type { PromptRecommendationJobPublic } from "@/app/lib/types/promptImprovement";

function isAuthorized(request: NextRequest): boolean {
const secretResult = readWebhookSecret();
Expand All @@ -23,10 +23,14 @@ export async function POST(request: NextRequest) {
}
const body = (await request.json()) as {
success?: boolean;
data?: PromptImprovementJobPublic;
data?: PromptRecommendationJobPublic;
error?: string | null;
};
if (!body.data || !body.data.job_id) {
if (
!body.data ||
!body.data.job_id ||
body.data.recommendation_type !== "prompt"
) {
return NextResponse.json(
{ success: false, error: "invalid_payload" },
{ status: 400 },
Expand Down
2 changes: 2 additions & 0 deletions app/hooks/usePromptImprovement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ function iteratePromptSyncError(code: string): string {
return "Source config is no longer available for this evaluation";
case "traces_not_available":
return "Evaluation traces aren't available yet — try Resync first";
case "not_a_judge_run":
return "Prompt iteration requires a judged evaluation run";
case "invalid_callback_url":
return "Frontend callback URL is invalid. Set NEXT_PUBLIC_APP_URL to a public HTTPS host.";
case "prompt_improvement_enqueue_failed":
Expand Down
5 changes: 3 additions & 2 deletions app/lib/store/promptImprovementStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
*/

import type {
PromptImprovementJobPublic,
PromptImprovementJobSnapshot,
PromptImprovementStoreShape,
PromptRecommendationJobPublic,
SnapshotListener,
} from "@/app/lib/types/promptImprovement";

Expand Down Expand Up @@ -74,7 +74,7 @@ function prune(): void {
}
}

export function saveJobSnapshot(job: PromptImprovementJobPublic): void {
export function saveJobSnapshot(job: PromptRecommendationJobPublic): void {
const snapshot: PromptImprovementJobSnapshot = {
...job,
updated_at: new Date().toISOString(),
Expand All @@ -89,6 +89,7 @@ export function markJobPending(jobId: string): void {
const snapshot: PromptImprovementJobSnapshot = {
job_id: jobId,
status: "PENDING",
recommendation_type: "prompt",
config_version: null,
error_message: null,
updated_at: new Date().toISOString(),
Expand Down
8 changes: 7 additions & 1 deletion app/lib/types/promptImprovement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,22 @@ import type { ConfigVersionPublic } from "@/app/lib/types/configs";

export type PromptImprovementConfigVersion = ConfigVersionPublic;

export interface PromptImprovementJobPublic {
/** Only "prompt" exists today; the backend will widen this to a union as
* more recommendation types (e.g. config) are added. */
export type RecommendationType = "prompt";

export interface PromptRecommendationJobPublic {
job_id: string;
status: PromptImprovementStatus;
recommendation_type: RecommendationType;
config_version: PromptImprovementConfigVersion | null;
error_message: string | null;
}

export interface PromptImprovementJobSnapshot {
job_id: string;
status: PromptImprovementStatus;
recommendation_type: RecommendationType;
config_version: PromptImprovementConfigVersion | null;
error_message: string | null;
updated_at: string;
Expand Down
Loading