Skip to content

Commit

Permalink
Merge pull request #2495 from Agenta-AI/hot-fix/-reset-current-eval-c…
Browse files Browse the repository at this point in the history
…onfig-step-to-index-0-when-opening-modal

Hot Fix: Enhance evaluator configuration button to reset current state on open
  • Loading branch information
bekossy authored Feb 19, 2025
2 parents 86b732f + f19dd69 commit ae1f3b2
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 10 deletions.
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

0 comments on commit ae1f3b2

Please sign in to comment.