Skip to content

Commit

Permalink
feat: redesigned prompt testing page
Browse files Browse the repository at this point in the history
  • Loading branch information
Goldziher committed Jan 8, 2024
1 parent 9ec86bb commit 1083f44
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 55 deletions.
7 changes: 4 additions & 3 deletions frontend/public/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,14 @@
"continueButtonText": "Continue",
"createConfig": "Create Configuration",
"createPromptConfigTitle": "New Model Configuration",
"credits": "Credits Left: ",
"credits": "Free Credits Left: ",
"duration": "Duration",
"durationTooltip": "Duration: Total time for complete output. Output streams automatically, with the first response occurring almost immediately.",
"finishReason": "Finish Reason",
"message": "Message",
"messageContent": "Prompt Template",
"modelResponse": "Model Response",
"modelResponse": "Model Response",
"modelType": "Model",
"modelVendor": "Provider",
"noVariablesHeadline": "The template has no variables - add as necessary or click on run test",
Expand Down Expand Up @@ -139,11 +140,11 @@
"saveButtonText": "Save",
"saveMessage": "Add Message",
"skipAndSaveButtonText": "Skip Testing and Save",
"testInputs": "Test Inputs",
"testName": "Test Name",
"testResults": "Test Results",
"totalCost": "Total Cost",
"variables": "Variables",
"variablesTooltip": "Required test inputs. Please add the values for the template variables.",
"variablesTooltip": "Required test inputs. Please add the values for the template variables. Variables are values defined inside '{'} in the template",
"wrapVariable": "use '{ '} to wrap a variable"
},
"createProject": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export default function PromptConfigCreateWizard({
setTemplateVariables={handleTemplateVariablesChange}
applicationId={applicationId}
projectId={projectId}
projectCredits={project?.credits}
projectCredits={project?.credits ?? '1'}
modelType={store.modelType}
modelVendor={store.modelVendor}
parameters={store.parameters}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useTranslations } from 'next-intl';
import { ChevronRight, PlayFill, Record, Repeat } from 'react-bootstrap-icons';
import { PlayFill, Record, Repeat } from 'react-bootstrap-icons';

import { CardHeaderWithTooltip } from '@/components/card-header-with-tooltip';
import { PromptContentDisplay } from '@/components/prompt-display-components/prompt-content-display';
Expand Down Expand Up @@ -42,19 +42,17 @@ export function PromptConfigTestingForm<T extends ModelVendor>({
modelType,
parameters,
promptConfigId,
showPromptTemplateDisplay = true,
}: {
applicationId: string;
handleError: (error: unknown) => void;
messages: ProviderMessageType<T>[];
modelType: ModelType<T>;
modelVendor: T;
parameters: ModelParameters<T>;
projectCredits?: string;
projectCredits: string;
projectId: string;
promptConfigId?: string;
setTemplateVariables: (templateVariables: Record<string, string>) => void;
showPromptTemplateDisplay?: boolean;
templateVariables: Record<string, string>;
}) {
const t = useTranslations('createConfigWizard');
Expand Down Expand Up @@ -121,21 +119,38 @@ export function PromptConfigTestingForm<T extends ModelVendor>({
}
};

const responseContent = modelResponses
.map((message) => message.content)
.join('');

return (
<div
className="flex flex-col justify-evenly"
data-testid="prompt-config-testing-form"
>
{showPromptTemplateDisplay && (
<span className="text-info text-xl text-center pt-2">
{`${t('credits') + projectCredits}$`}
</span>
<div className="flex justify-between">
<PromptContentDisplay
modelVendor={modelVendor}
messages={messages}
/>
)}
<button
disabled={!allExpectedVariablesHaveLength || isRunningTest}
data-testid="run-test-button"
className="btn btn-wide btn-success self-start"
onClick={testFinishReason ? resetState : handleRunTest}
>
{renderButtonIcon()}
{t('runTest')}
</button>
</div>
{expectedVariables.length > 0 && (
<>
<div className="card-divider" />
<CardHeaderWithTooltip
headerText={t('variables')}
headerText={t('testInputs')}
tooltipText={t('variablesTooltip')}
dataTestId="test-inputs-header"
/>
Expand All @@ -149,44 +164,36 @@ export function PromptConfigTestingForm<T extends ModelVendor>({
</div>
</>
)}
<div className="card-section-divider" />
<button
disabled={!allExpectedVariablesHaveLength || isRunningTest}
data-testid="run-test-button"
className="btn btn-wide btn-primary bg-base-content text-base-100 self-center"
onClick={testFinishReason ? resetState : handleRunTest}
>
{renderButtonIcon()}
{t('runTest')}
</button>

{projectCredits && (
<span className="text-neutral-content text-sm text-center pt-2">
{`${t('credits') + projectCredits}$`}
</span>
{responseContent && (
<>
<div className="card-divider" />
<h2 className="card-header">{t('modelResponse')}</h2>
<div className="rounded-dark-card">
<div
className="flex gap-2 pt-5 pb-5 content-center items-center"
data-testid="model-response-container"
>
<span className="text-success">
{responseContent}
</span>
</div>
</div>
</>
)}
{(testRecord ?? testFinishReason) && (
<>
<div className="card-divider" />
<h2 className="card-header">{t('testResults')}</h2>
<div className="rounded-dark-card">
<PromptTestResultTable
modelVendor={modelVendor}
modelType={modelType}
testFinishReason={testFinishReason}
testRecord={testRecord}
/>
</div>
</>
)}
<div className="card-section-divider" />
<h2 className="card-header">{t('testResults')}</h2>
<div className="rounded-dark-card">
<PromptTestResultTable
modelVendor={modelVendor}
modelType={modelType}
testFinishReason={testFinishReason}
testRecord={testRecord}
/>
<div
className="flex gap-2 pl-4 content-center items-center"
data-testid="model-response-container"
>
<ChevronRight className="h-4 w-4" />
<span className="text-info">
{modelResponses
.map((message) => message.content)
.join('')}
</span>
</div>
<div className="card-section-divider" />
</div>
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ export function PromptConfigTesting<T extends ModelVendor>({
setTemplateVariables={setTemplateVariables}
handleError={handleError}
messages={messages}
showPromptTemplateDisplay={false}
/>
<div className="card-divider" />
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export function PromptContentDisplay<T extends ModelVendor>({
</h2>
</div>
<div
className="rounded-data-card"
className="rounded-dark-card"
data-testid="prompt-content-display-messages"
>
{messageContent.map((msg, i) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ export function PromptTestInputs({
}) {
return (
<div data-testid="test-inputs-container">
<div className="grid grid-cols-2 gap-4 min-w-[50%]">
<div className="flex flex-col gap-5">
{expectedVariables.map((variable) => (
<div key={variable} className="form-control">
<input
type="text"
<textarea
className="card-textarea textarea-info bg-neutral placeholder-info"
data-testid={`input-variable-input-${variable}`}
value={templateVariables[variable] ?? ''}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/styles/globals.scss
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ div#__next > div {
}

.rounded-data-card {
@apply mt-3.5 rounded-4xl w-full bg-base-200 py-8 px-16;
@apply mt-3.5 rounded-4xl w-full bg-base-200 px-16;
}
.rounded-dark-card {
@apply mt-3.5 rounded-4xl w-full bg-base-300 py-8 px-16 shadow-xl;
@apply mt-3.5 rounded-4xl w-full bg-base-300 px-16 shadow-xl;
}

.analytics {
Expand Down

0 comments on commit 1083f44

Please sign in to comment.