Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hot Fix: Enhance evaluator configuration button to reset current state on open #2495

Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,10 @@ const AutoEvaluation = () => {
<Button
icon={<Gauge size={14} />}
className={classes.button}
onClick={() => setIsConfigEvaluatorModalOpen("open")}
onClick={() => {
setIsConfigEvaluatorModalOpen("open")
setCurrent(0)
}}
>
Configure evaluators
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,13 @@ const EvaluatorsModal = ({
.finally(() => setFetchingEvalConfigs(false))
}

const {data} = useVariants(currentApp)({
appId,
onSuccess: (data) => {
if (data?.variants?.length) {
setSelectedVariant(data?.variants[0])
}
},
})
const {data} = useVariants(currentApp)({appId})

useEffect(() => {
if (data?.variants?.length) {
setSelectedVariant(data?.variants[0].variant)
}
}, [data])

useEffect(() => {
Promise.all([fetchAllEvaluators(), fetchAllEvaluatorConfigs(appId), fetchTestsets()]).then(
Expand Down
45 changes: 45 additions & 0 deletions agenta-web/src/lib/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,51 @@ export const safeParse = (str: string, fallback: any = "") => {
}
}

export const extractChatMessages = (testcase: any) => {
if (testcase.messages)
return formatMessages(normalizeMessages(parseStringToJson(testcase.messages)))
if (testcase.chat) return formatMessages(normalizeMessages(parseStringToJson(testcase.chat)))

const filteredEntries = Object.entries(testcase).filter(([key]) => key !== "correct_answer")

for (const [_, value] of filteredEntries) {
const parsedValue = parseStringToJson(value)
if (Array.isArray(parsedValue)) {
return formatMessages(parsedValue)
}
}

return []
}

const parseStringToJson = (value: any) => {
if (typeof value === "string") {
try {
return JSON.parse(value)
} catch {
return value
}
}
return value
}

const normalizeMessages = (messages: any) => {
if (!Array.isArray(messages) && typeof messages === "object") {
return [messages]
}
return messages
}

const formatMessages = (messages: any) => {
if (typeof messages === "object" && !Array.isArray(messages)) {
messages = Object.values(messages)
}

return Array.isArray(messages)
? messages.map(({role, content, id}) => ({role, content, id}))
: []
}

export const getAgentaApiUrl = () => {
const apiUrl = process.env.NEXT_PUBLIC_AGENTA_API_URL

Expand Down
3 changes: 2 additions & 1 deletion agenta-web/src/services/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export async function callVariant(
): Promise<string | FuncResponse | BaseResponse> {
const isChatVariant = Array.isArray(chatMessages) && chatMessages.length > 0
// Separate input parameters into two dictionaries based on the 'input' property
const mainInputParams: Record<string, string> = {} // Parameters with input = true
const mainInputParams: Record<string, any> = {} // Parameters with input = true
const secondaryInputParams: Record<string, string> = {} // Parameters with input = false

for (let key of Object.keys(inputParametersDict)) {
Expand All @@ -118,6 +118,7 @@ export async function callVariant(
if (paramDefinition && !paramDefinition.input) {
secondaryInputParams[key] = inputParametersDict[key]
} else {
// Parse the value if key is "messages"
mainInputParams[key] = inputParametersDict[key]
}
}
Expand Down
Loading