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
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ const PluginEvalTargetForm = (props: PluginEvalTargetFormProps) => {
};

const handleEvalTargetVersionChange = () => {
const currentMapping = formValues?.evalTargetMapping || {};
const objKeys = Object.keys(currentMapping);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
objKeys.forEach(k => onChange(`evalTargetMapping.${k}`, undefined));
onChange('evalTargetMapping', undefined);
onChange('target_runtime_param', undefined);
};
Expand Down
5 changes: 5 additions & 0 deletions frontend/packages/cozeloop/evaluate-pages/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ const App = () => {
<Route path="evaluators" element={<EvaluatorListPage />} />

<Route path="evaluators/create/llm" element={<EvaluatorCreatePage />} />

<Route
path="evaluators/create/llm/:id"
element={<EvaluatorCreatePage />}
/>
<Route
path="evaluators/create/code"
element={<CodeEvaluatorCreatePage />}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,61 +97,59 @@ function EvaluatorCreatePage() {
})
.catch(e => console.warn(e));

const renderContent = () => (
<>
<Form
initValues={
sourceService.data || {
evaluator_type: EvaluatorType.Prompt,
}
const formContent = (
<Form
initValues={
sourceService.data || {
evaluator_type: EvaluatorType.Prompt,
}
className="flex-1 w-[800px] mx-auto form-default"
ref={formRef}
onValueChange={(values, changeValues) => {
setBlockLeave(true);
}}
>
<div className="h-[28px] mb-3 text-[16px] leading-7 font-medium coz-fg-plus">
{I18n.t('basic_info')}
</div>
<FormInput
label={I18n.t('name')}
field="name"
placeholder={I18n.t('please_input', { field: '' })}
required
maxLength={50}
trigger="blur"
rules={[
{ required: true, message: I18n.t('please_input_name') },
{ max: 50 },
{ validator: sourceNameRuleValidator },
{
asyncValidator: async (_, value: string) => {
if (value) {
const { pass } = await StoneEvaluationApi.CheckEvaluatorName({
workspace_id: spaceID,
name: value,
});
if (pass === false) {
throw new Error(I18n.t('name_already_exists'));
}
}
className="flex-1 w-[800px] mx-auto form-default"
ref={formRef}
onValueChange={(values, changeValues) => {
setBlockLeave(true);
}}
>
<div className="h-[28px] mb-3 text-[16px] leading-7 font-medium coz-fg-plus">
{I18n.t('basic_info')}
</div>
<FormInput
label={I18n.t('name')}
field="name"
placeholder={I18n.t('please_input', { field: '' })}
required
maxLength={50}
trigger="blur"
rules={[
{ required: true, message: I18n.t('please_input_name') },
{ max: 50 },
{ validator: sourceNameRuleValidator },
{
asyncValidator: async (_, value: string) => {
if (value) {
const { pass } = await StoneEvaluationApi.CheckEvaluatorName({
workspace_id: spaceID,
name: value,
});
if (pass === false) {
throw new Error(I18n.t('name_already_exists'));
}
},
}
},
]}
/>
<FormTextArea
label={I18n.t('description')}
field="description"
placeholder={I18n.t('please_input_description')}
fieldStyle={{ paddingTop: 8 }}
maxCount={200}
maxLength={200}
/>
<div className="h-7 mt-[10px]" />
<PromptConfigField refreshEditorModelKey={refreshEditorModelKey} />
</Form>
</>
},
]}
/>
<FormTextArea
label={I18n.t('description')}
field="description"
placeholder={I18n.t('please_input_description')}
fieldStyle={{ paddingTop: 8 }}
maxCount={200}
maxLength={200}
/>
<div className="h-7 mt-[10px]" />
<PromptConfigField refreshEditorModelKey={refreshEditorModelKey} />
</Form>
);

return (
Expand All @@ -169,7 +167,7 @@ function EvaluatorCreatePage() {
) : (
<>
<div className="p-6 pt-[12px] flex-1 overflow-y-auto styled-scrollbar pr-[18px]">
{renderContent()}
{formContent}
</div>
<div className="flex-shrink-0 p-6">
<div className="w-[800px] mx-auto flex flex-row justify-end gap-2">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ export function PromptField({
const afterTemplateSelect = (payload: PromptEvaluator) => {
promptEvaluatorFieldApi.setValue({
...promptEvaluator,
model_config:
formValues?.current_version?.evaluator_content?.prompt_evaluator
?.model_config,
message_list: payload.message_list,
prompt_source_type: PromptSourceType.BuiltinTemplate,
prompt_template_key: payload.prompt_template_key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable @coze-arch/max-line-per-function */
import { useParams } from 'react-router-dom';
import { useRef, useState } from 'react';
import { type ReactNode, useRef, useState } from 'react';

import { useRequest } from 'ahooks';
import { I18n } from '@cozeloop/i18n-adapter';
Expand Down Expand Up @@ -109,6 +109,16 @@ function EvaluatorDetailPage() {
},
);

const formFieldContent = (
<div className={`${!selectedVersion ? '' : 'hidden'}`}>
<PromptConfigField
disabled={guard.data.readonly}
refreshEditorModelKey={refreshEditorModelKey}
/>
<div className="h-6" />
</div>
);

if (service.loading) {
return (
<div className="h-full flex items-center justify-center">
Expand All @@ -117,16 +127,18 @@ function EvaluatorDetailPage() {
);
}

const renderContent = () => {
if (selectedVersion) {
if (versionService.loading) {
return (
<div className="h-full w-full flex items-center justify-center">
<Spin spinning={true} />
</div>
);
}
return (
let evaluatorInfo: null | ReactNode = null;

if (selectedVersion) {
if (versionService.loading) {
evaluatorInfo = (
<div className="h-full w-full flex items-center justify-center">
<Spin spinning={true} />
</div>
);
}
if (!versionService.loading) {
evaluatorInfo = (
<div className="flex-1 max-w-[800px] mx-auto">
<div className="h-[28px] mb-3 text-[16px] leading-7 font-medium coz-fg-plus">
{I18n.t('config_info')}
Expand All @@ -145,27 +157,8 @@ function EvaluatorDetailPage() {
</div>
);
}
}

return (
<Form
initValues={evaluator}
className="flex-1 max-w-[800px] mx-auto"
ref={formRef}
onValueChange={values => {
// Demo 空间且没有管理权限,不保存
if (!isDemoSpace) {
autoSaveService.run(values);
}
}}
>
<PromptConfigField
disabled={guard.data.readonly}
refreshEditorModelKey={refreshEditorModelKey}
/>
<div className="h-6" />
</Form>
);
};
return (
<div className="h-full overflow-hidden flex flex-col">
<Header
Expand Down Expand Up @@ -197,7 +190,20 @@ function EvaluatorDetailPage() {

<div className="flex-1 overflow-hidden flex flex-row">
<div className="flex-1 overflow-y-auto p-6 flex styled-scrollbar pr-[18px]">
{renderContent()}
<Form
initValues={evaluator}
className="flex-1 max-w-[800px] mx-auto"
ref={formRef}
onValueChange={values => {
// Demo 空间且没有管理权限,不保存
if (!isDemoSpace) {
autoSaveService.run(values);
}
}}
>
{formFieldContent}
{evaluatorInfo}
</Form>
</div>
{versionListVisible && evaluator ? (
<VersionListPane
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function EvaluatorListPage() {
if (record.evaluator_type === EvaluatorType.Code) {
navigate(`create/code/${record.evaluator_id}`);
} else {
navigate(`create/${record.evaluator_id}`);
navigate(`create/llm/${record.evaluator_id}`);
}
},
showCancelButton: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ColumnsManage,
RefreshButton,
} from '@cozeloop/evaluate-components';
import { IS_HIDDEN_EXPERIMENT_DETAIL_FILTER } from '@cozeloop/biz-hooks-adapter';
import {
type ColumnEvaluator,
type Experiment,
Expand Down Expand Up @@ -198,5 +199,10 @@ export default function ExperimentContrastTableHeader({
<RefreshButton onRefresh={onRefresh} />
</>
);
return <TableHeader filters={filters} actions={actions} />;
return (
<TableHeader
filters={IS_HIDDEN_EXPERIMENT_DETAIL_FILTER ? null : filters}
actions={actions}
/>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ export default function ExperimentCreatePage() {
// 保存当前步骤的值
if (formRef?.current?.formApi) {
const currentValues = formRef.current.formApi.getValues();
const nextStepValues = calcNextStepRenderValue(
const prevStepValues = calcNextStepRenderValue(
createExperimentValues,
currentValues,
);
setCreateExperimentValues(nextStepValues);
setCreateExperimentValues(prevStepValues);
}

reportStep({
Expand Down Expand Up @@ -194,10 +194,12 @@ export default function ExperimentCreatePage() {

if (values) {
// 更新全局状态,确保包含最新的表单值
setCreateExperimentValues(prev => ({
...prev,
...values,
}));

setCreateExperimentValues(prev => {
const prevStepValues = calcNextStepRenderValue(prev, values);
return prevStepValues;
});

// 设置下一步
goNext();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
type LogicField,
type SemiTableSort,
} from '@cozeloop/evaluate-components';
import { IS_HIDDEN_EXPERIMENT_DETAIL_FILTER } from '@cozeloop/biz-hooks-adapter';
import {
type Experiment,
FieldType,
Expand Down Expand Up @@ -422,7 +423,12 @@ export default function ({
<TableForExperiment<ExperimentItem>
service={service as Service}
heightFull={true}
header={<TableHeader actions={actions} filters={filters} />}
header={
<TableHeader
actions={actions}
filters={IS_HIDDEN_EXPERIMENT_DETAIL_FILTER ? null : filters}
/>
}
pageSizeStorageKey="experiment_detail_page_size"
empty={tableEmpty}
tableProps={tableProps}
Expand Down
Loading