From abf1ec16a276e4c4f51bd962a9560a80b8d47af8 Mon Sep 17 00:00:00 2001 From: Mahmoud Mabrouk Date: Thu, 4 Jan 2024 17:29:53 +0100 Subject: [PATCH] Fix result type conversion in evaluation tables --- .../ABTestingEvaluationTable.tsx | 4 ++++ .../AICritiqueEvaluationTable.tsx | 4 +++- .../CustomCodeRunEvaluationTable.tsx | 4 ++++ .../ExactMatchEvaluationTable.tsx | 4 ++++ .../EvaluationTable/RegexEvaluationTable.tsx | 4 ++++ .../SimilarityMatchEvaluationTable.tsx | 4 ++++ .../SingleModelEvaluationTable.tsx | 3 +++ .../EvaluationTable/WebhookEvaluationTable.tsx | 4 ++++ .../components/Playground/Views/TestView.tsx | 18 +++++++++++------- agenta-web/src/lib/services/api.ts | 6 ++++-- 10 files changed, 45 insertions(+), 10 deletions(-) diff --git a/agenta-web/src/components/EvaluationTable/ABTestingEvaluationTable.tsx b/agenta-web/src/components/EvaluationTable/ABTestingEvaluationTable.tsx index 163e490af8..fb6331e2a8 100644 --- a/agenta-web/src/components/EvaluationTable/ABTestingEvaluationTable.tsx +++ b/agenta-web/src/components/EvaluationTable/ABTestingEvaluationTable.tsx @@ -21,6 +21,7 @@ import {testsetRowToChatMessages} from "@/lib/helpers/testset" import EvaluationVotePanel from "../Evaluations/EvaluationCardView/EvaluationVotePanel" import VariantAlphabet from "../Evaluations/EvaluationCardView/VariantAlphabet" import {ParamsFormWithRun} from "./SingleModelEvaluationTable" +import {PassThrough} from "stream" const {Title} = Typography @@ -238,6 +239,9 @@ const ABTestingEvaluationTable: React.FC = ({ ? testsetRowToChatMessages(evaluation.testset.csvdata[rowIndex], false) : [], ) + if (typeof result !== "string") { + result = result.message + } setRowValue(rowIndex, variant.variantId, result) ;(outputs as KeyValuePair)[variant.variantId] = result diff --git a/agenta-web/src/components/EvaluationTable/AICritiqueEvaluationTable.tsx b/agenta-web/src/components/EvaluationTable/AICritiqueEvaluationTable.tsx index 2dbc2aab3b..5fe2a4674e 100644 --- a/agenta-web/src/components/EvaluationTable/AICritiqueEvaluationTable.tsx +++ b/agenta-web/src/components/EvaluationTable/AICritiqueEvaluationTable.tsx @@ -271,7 +271,9 @@ Answer ONLY with one of the given grading or evaluation options. ? testsetRowToChatMessages(evaluation.testset.csvdata[rowIndex], false) : [], ) - + if (typeof result !== "string") { + result = result.message + } if (variantData[idx].isChatVariant) { result = contentToChatMessageString(result) } diff --git a/agenta-web/src/components/EvaluationTable/CustomCodeRunEvaluationTable.tsx b/agenta-web/src/components/EvaluationTable/CustomCodeRunEvaluationTable.tsx index 711321cf82..46a572f2d3 100644 --- a/agenta-web/src/components/EvaluationTable/CustomCodeRunEvaluationTable.tsx +++ b/agenta-web/src/components/EvaluationTable/CustomCodeRunEvaluationTable.tsx @@ -249,6 +249,10 @@ const CustomCodeRunEvaluationTable: React.FC = ( ? testsetRowToChatMessages(evaluation.testset.csvdata[rowIndex], false) : [], ) + if (typeof result !== "string") { + result = result.message + } + if (variantData[idx].isChatVariant) result = contentToChatMessageString(result) setRowValue(rowIndex, columnName as any, result) diff --git a/agenta-web/src/components/EvaluationTable/ExactMatchEvaluationTable.tsx b/agenta-web/src/components/EvaluationTable/ExactMatchEvaluationTable.tsx index 7f80ba22b4..43d00c8b08 100644 --- a/agenta-web/src/components/EvaluationTable/ExactMatchEvaluationTable.tsx +++ b/agenta-web/src/components/EvaluationTable/ExactMatchEvaluationTable.tsx @@ -192,6 +192,10 @@ const ExactMatchEvaluationTable: React.FC = ({ ? testsetRowToChatMessages(evaluation.testset.csvdata[rowIndex], false) : [], ) + if (typeof result !== "string") { + result = result.message + } + if (variantData[idx].isChatVariant) result = contentToChatMessageString(result) setRowValue(rowIndex, columnName, result) diff --git a/agenta-web/src/components/EvaluationTable/RegexEvaluationTable.tsx b/agenta-web/src/components/EvaluationTable/RegexEvaluationTable.tsx index baa31e5dd5..8bec03d831 100644 --- a/agenta-web/src/components/EvaluationTable/RegexEvaluationTable.tsx +++ b/agenta-web/src/components/EvaluationTable/RegexEvaluationTable.tsx @@ -220,6 +220,10 @@ const RegexEvaluationTable: React.FC = ({ ? testsetRowToChatMessages(evaluation.testset.csvdata[rowIndex], false) : [], ) + if (typeof result !== "string") { + result = result.message + } + if (variantData[idx].isChatVariant) result = contentToChatMessageString(result) const {regexPattern, regexShouldMatch} = form.getFieldsValue() diff --git a/agenta-web/src/components/EvaluationTable/SimilarityMatchEvaluationTable.tsx b/agenta-web/src/components/EvaluationTable/SimilarityMatchEvaluationTable.tsx index 1e294efb83..d19cf3ca63 100644 --- a/agenta-web/src/components/EvaluationTable/SimilarityMatchEvaluationTable.tsx +++ b/agenta-web/src/components/EvaluationTable/SimilarityMatchEvaluationTable.tsx @@ -215,6 +215,10 @@ const SimilarityMatchEvaluationTable: React.FC = ({ ? testsetRowToChatMessages(evaluation.testset.csvdata[rowIndex], false) : [], ) + if (typeof result !== "string") { + result = result.message + } setRowValue(rowIndex, variant.variantId, result) ;(outputs as KeyValuePair)[variant.variantId] = result diff --git a/agenta-web/src/components/EvaluationTable/WebhookEvaluationTable.tsx b/agenta-web/src/components/EvaluationTable/WebhookEvaluationTable.tsx index cd3979f81c..c001c3834a 100644 --- a/agenta-web/src/components/EvaluationTable/WebhookEvaluationTable.tsx +++ b/agenta-web/src/components/EvaluationTable/WebhookEvaluationTable.tsx @@ -199,6 +199,10 @@ const WebhookEvaluationTable: React.FC = ({ ? testsetRowToChatMessages(evaluation.testset.csvdata[rowIndex], false) : [], ) + if (typeof result !== "string") { + result = result.message + } + if (variantData[idx].isChatVariant) result = contentToChatMessageString(result) const {webhookUrl} = form.getFieldsValue() diff --git a/agenta-web/src/components/Playground/Views/TestView.tsx b/agenta-web/src/components/Playground/Views/TestView.tsx index 3509363815..d7ab8ee2ef 100644 --- a/agenta-web/src/components/Playground/Views/TestView.tsx +++ b/agenta-web/src/components/Playground/Views/TestView.tsx @@ -340,13 +340,17 @@ const App: React.FC = ({ variant.baseId || "", isChatVariant ? testItem.chat : [], ) - - setResultForIndex(res.message, index) - setAdditionalDataList((prev) => { - const newDataList = [...prev] - newDataList[index] = {cost: res.cost, latency: res.latency, usage: res.usage} - return newDataList - }) + // check if res is an object or string + if (typeof res === "string") { + setResultForIndex(res, index) + } else { + setResultForIndex(res.message, index) + setAdditionalDataList((prev) => { + const newDataList = [...prev] + newDataList[index] = {cost: res.cost, latency: res.latency, usage: res.usage} + return newDataList + }) + } } catch (e) { setResultForIndex( "The code has resulted in the following error: \n\n --------------------- \n" + diff --git a/agenta-web/src/lib/services/api.ts b/agenta-web/src/lib/services/api.ts index eb72630ba0..30eab1e56b 100644 --- a/agenta-web/src/lib/services/api.ts +++ b/agenta-web/src/lib/services/api.ts @@ -72,8 +72,10 @@ export function restartAppVariantContainer(variantId: string) { * @param inputParametersDict A dictionary of the input parameters to be passed to the variant endpoint * @param inputParamDefinition A list of the parameters that are defined in the openapi.json (these are only part of the input params, the rest is defined by the user in the optparms) * @param optionalParameters The optional parameters (prompt, models, AND DICTINPUTS WHICH ARE TO BE USED TO ADD INPUTS ) - * @param URIPath - * @returns + * @param appId - The ID of the app. + * @param baseId - The base ID. + * @param chatMessages - An optional array of chat messages. + * @returns A Promise that resolves with the response data from the POST request. */ export async function callVariant( inputParametersDict: KeyValuePair,