Files
Flowise/packages/server/src/Interface.Evaluation.ts
T
Henry Heng 5a37227d14 Chore/refractor (#4454)
* markdown files and env examples cleanup

* components update

* update jsonlines description

* server refractor

* update telemetry

* add execute custom node

* add ui refractor

* add username and password authenticate

* correctly retrieve past images in agentflowv2

* disable e2e temporarily

* add existing username and password authenticate

* update migration to default workspace

* update todo

* blob storage migrating

* throw error on agent tool call error

* add missing execution import

* add referral

* chore: add error message when importData is undefined

* migrate api keys to db

* fix: data too long for column executionData

* migrate api keys from json to db at init

* add info on account setup

* update docstore missing fields

---------

Co-authored-by: chungyau97 <chungyau97@gmail.com>
2025-05-27 07:29:42 +01:00

140 lines
3.5 KiB
TypeScript

// Evaluation Related Interfaces
import { Evaluator } from './database/entities/Evaluator'
export interface IDataset {
id: string
name: string
description: string
createdDate: Date
updatedDate: Date
workspaceId?: string
}
export interface IDatasetRow {
id: string
datasetId: string
input: string
output: string
updatedDate: Date
sequenceNo: number
}
export enum EvaluationStatus {
PENDING = 'pending',
COMPLETED = 'completed',
ERROR = 'error'
}
export interface IEvaluation {
id: string
name: string
chatflowId: string
chatflowName: string
datasetId: string
datasetName: string
evaluationType: string
additionalConfig: string //json
average_metrics: string //json
status: string
runDate: Date
workspaceId?: string
}
export interface IEvaluationResult extends IEvaluation {
latestEval: boolean
version: number
}
export interface IEvaluationRun {
id: string
evaluationId: string
input: string
expectedOutput: string
actualOutput: string // JSON
metrics: string // JSON
runDate: Date
llmEvaluators?: string // JSON
evaluators?: string // JSON
errors?: string // JSON
}
export interface IEvaluator {
id: string
name: string
type: string
config: string // JSON
updatedDate: Date
createdDate: Date
workspaceId?: string
}
export class EvaluatorDTO {
id: string
name: string
type: string
measure?: string
operator?: string
value?: string
prompt?: string
evaluatorType?: string
outputSchema?: []
updatedDate: Date
createdDate: Date
static toEntity(body: any): Evaluator {
const newDs = new Evaluator()
Object.assign(newDs, body)
let config: any = {}
if (body.type === 'llm') {
config = {
prompt: body.prompt,
outputSchema: body.outputSchema
}
} else if (body.type === 'text') {
config = {
operator: body.operator,
value: body.value
}
} else if (body.type === 'json') {
config = {
operator: body.operator
}
} else if (body.type === 'numeric') {
config = {
operator: body.operator,
value: body.value,
measure: body.measure
}
} else {
throw new Error('Invalid evaluator type')
}
newDs.config = JSON.stringify(config)
return newDs
}
static fromEntity(entity: Evaluator): EvaluatorDTO {
const newDs = new EvaluatorDTO()
Object.assign(newDs, entity)
const config = JSON.parse(entity.config)
if (entity.type === 'llm') {
newDs.prompt = config.prompt
newDs.outputSchema = config.outputSchema
} else if (entity.type === 'text') {
newDs.operator = config.operator
newDs.value = config.value
} else if (entity.type === 'json') {
newDs.operator = config.operator
newDs.value = config.value
} else if (entity.type === 'numeric') {
newDs.operator = config.operator
newDs.value = config.value
newDs.measure = config.measure
}
delete (newDs as any).config
return newDs
}
static fromEntities(entities: Evaluator[]): EvaluatorDTO[] {
return entities.map((entity) => this.fromEntity(entity))
}
}