[Feat]: Evaluations for the trace spans#614
Conversation
|
🧙 Sourcery has finished reviewing your pull request! Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey @AmanAgarwal041 - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider creating a separate component for the logic that fetches and processes evaluation data to improve readability and maintainability.
- The addition of evaluation functionality introduces a dependency on Python and litellm; ensure these dependencies are well-documented for setup.
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| @@ -0,0 +1,55 @@ | |||
| // Environment variables for auto evaluation | |||
| const EVALUATION_CONFIG_ID = process.env.EVALUATION_CONFIG_ID; | |||
There was a problem hiding this comment.
suggestion (code-quality): Prefer object destructuring when accessing and using properties. (use-object-destructuring)
| const EVALUATION_CONFIG_ID = process.env.EVALUATION_CONFIG_ID; | |
| const {EVALUATION_CONFIG_ID} = process.env; |
Explanation
Object destructuring can often remove an unnecessary temporary reference, as well as making your code more succinct.From the Airbnb Javascript Style Guide
| @@ -0,0 +1,55 @@ | |||
| // Environment variables for auto evaluation | |||
| const EVALUATION_CONFIG_ID = process.env.EVALUATION_CONFIG_ID; | |||
| const CRON_ID = process.env.CRON_ID; | |||
There was a problem hiding this comment.
suggestion (code-quality): Prefer object destructuring when accessing and using properties. (use-object-destructuring)
| const CRON_ID = process.env.CRON_ID; | |
| const {CRON_ID} = process.env; |
Explanation
Object destructuring can often remove an unnecessary temporary reference, as well as making your code more succinct.From the Airbnb Javascript Style Guide
| // Environment variables for auto evaluation | ||
| const EVALUATION_CONFIG_ID = process.env.EVALUATION_CONFIG_ID; | ||
| const CRON_ID = process.env.CRON_ID; | ||
| const API_URL = process.env.API_URL; |
There was a problem hiding this comment.
suggestion (code-quality): Prefer object destructuring when accessing and using properties. (use-object-destructuring)
| const API_URL = process.env.API_URL; | |
| const {API_URL} = process.env; |
Explanation
Object destructuring can often remove an unnecessary temporary reference, as well as making your code more succinct.From the Airbnb Javascript Style Guide
| const { fireRequest, isLoading: isLoadingModify } = useFetchWrapper(); | ||
| const { fireRequest: getVaultKeys, isLoading: isLoadingVaultKeys } = | ||
| useFetchWrapper(); |
There was a problem hiding this comment.
suggestion (code-quality): Combine destructure assignments. (combine-object-destructuring)
| const { fireRequest, isLoading: isLoadingModify } = useFetchWrapper(); | |
| const { fireRequest: getVaultKeys, isLoading: isLoadingVaultKeys } = | |
| useFetchWrapper(); | |
| const {fireRequest, isLoading: isLoadingModify, fireRequest: getVaultKeys, isLoading: isLoadingVaultKeys} = useFetchWrapper(); | |
Explanation
Object destructuring can often remove an unnecessary temporary reference, as well as making your code more succinct.From the Airbnb Javascript Style Guide
| if (!validationParam.success) | ||
| return Response.json(validationParam.err, { | ||
| status: 400, | ||
| }); |
There was a problem hiding this comment.
suggestion (code-quality): Use block braces for ifs, whiles, etc. (use-braces)
| if (!validationParam.success) | |
| return Response.json(validationParam.err, { | |
| status: 400, | |
| }); | |
| if (!validationParam.success) { | |
| return Response.json(validationParam.err, { | |
| status: 400, | |
| }); | |
| } | |
Explanation
It is recommended to always use braces and create explicit statement blocks.Using the allowed syntax to just write a single statement can lead to very confusing
situations, especially where subsequently a developer might add another statement
while forgetting to add the braces (meaning that this wouldn't be included in the condition).
| if (validateVaultId) { | ||
| throwIfError( | ||
| !updatedSecretData?.id, | ||
| getMessage().EVALUATION_VAULT_SECRET_NOT_FOUND | ||
| ); | ||
| } else { | ||
| if (!updatedSecretData.id) { | ||
| updatedConfig.vaultId = ""; | ||
| } | ||
| } |
There was a problem hiding this comment.
suggestion (code-quality): Merge else clause's nested if statement into else if (merge-else-if)
| if (validateVaultId) { | |
| throwIfError( | |
| !updatedSecretData?.id, | |
| getMessage().EVALUATION_VAULT_SECRET_NOT_FOUND | |
| ); | |
| } else { | |
| if (!updatedSecretData.id) { | |
| updatedConfig.vaultId = ""; | |
| } | |
| } | |
| if (validateVaultId) { | |
| throwIfError( | |
| !updatedSecretData?.id, | |
| getMessage().EVALUATION_VAULT_SECRET_NOT_FOUND | |
| ); | |
| } | |
| else if (!updatedSecretData.id) { | |
| updatedConfig.vaultId = ""; | |
| } | |
Explanation
Flattening if statements nested within else clauses generates code that iseasier to read and expand upon.
| excludeVaultValue: boolean = true | ||
| ) { | ||
| const query = `SELECT * ${ | ||
| !!excludeVaultValue ? "EXCEPT value" : "" |
There was a problem hiding this comment.
suggestion (code-quality): Invert ternary operator to remove negation (invert-ternary)
| !!excludeVaultValue ? "EXCEPT value" : "" | |
| !excludeVaultValue ? "" : "EXCEPT value" |
Explanation
Negated conditions are more difficult to read than positive ones, so it is bestto avoid them where we can. By inverting the ternary condition and swapping the
expressions we can simplify the code.
| } | ||
| return withAuth( | ||
| async function middleware(request: NextRequest, _next: NextFetchEvent) { | ||
| const pathname = request.nextUrl.pathname; |
There was a problem hiding this comment.
suggestion (code-quality): Prefer object destructuring when accessing and using properties. (use-object-destructuring)
| const pathname = request.nextUrl.pathname; | |
| const {pathname} = request.nextUrl; |
Explanation
Object destructuring can often remove an unnecessary temporary reference, as well as making your code more succinct.From the Airbnb Javascript Style Guide
| if (isAuth || isAllowedRequestWithoutToken || isCronJobRoute) { | ||
| if (isCronJobRoute) { | ||
| const cronJobToken = request.headers.get("X-CRON-JOB"); | ||
| if (cronJobToken) { | ||
| return NextResponse.next(); | ||
| } | ||
| } | ||
| return NextResponse.next(); | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
suggestion (code-quality): Merge nested if conditions (merge-nested-ifs)
| if (isApiPage) { | |
| if (isAuth || isAllowedRequestWithoutToken || isCronJobRoute) { | |
| if (isCronJobRoute) { | |
| const cronJobToken = request.headers.get("X-CRON-JOB"); | |
| if (cronJobToken) { | |
| return NextResponse.next(); | |
| } | |
| } | |
| return NextResponse.next(); | |
| } | |
| } | |
| if (isApiPage && (isAuth || isAllowedRequestWithoutToken || isCronJobRoute)) { | |
| if (isCronJobRoute) { | |
| const cronJobToken = request.headers.get("X-CRON-JOB"); | |
| if (cronJobToken) { | |
| return NextResponse.next(); | |
| } | |
| } | |
| return NextResponse.next(); | |
| } | |
Explanation
Reading deeply nested conditional code is confusing, since you have to keep track of whichconditions relate to which levels. We therefore strive to reduce nesting where
possible, and the situation where two
if conditions can be combined usingand is an easy win.
| parsed_content = json.loads(content) | ||
| return parsed_content |
There was a problem hiding this comment.
suggestion (code-quality): Inline variable that is immediately returned (inline-immediately-returned-variable)
| parsed_content = json.loads(content) | |
| return parsed_content | |
| return json.loads(content) |
Overview:
This PR enables a feature of evaluating your trace spans for Hallucinations, Bias & Toxicity.
You can enable this functionality by creating evaluation config in the settings screen
You can even enable the auto evaluations by proving cron recurring time which will create a cron job and evaluate your traces in the background.
For this it uses the vault feature where you can select your creds to make the evaluations happen
If you don't want the auto evaluations , you can even run evaluations for each trace spans
For evaluations it uses litellm in the background, so you can configure your own provider and models for the evaluations
You also see some dashboard panels in the dashboard page with Number of Hallucinations, Bias & Toxicity detected parameters.
Database config, user profile, evaluation config, api keys have been moved to settings page
This PR also decouples types from other places in one single directory
This PR also decouples server and client helpers to improve the dev experience
Fixes #470
Visuals (If applicable):
Checklist:
[Feat]: ...or[Fix]: ....Summary by Sourcery
Implements trace span evaluations for Hallucinations, Bias, and Toxicity using LiteLLM, enabling users to configure evaluations, schedule automatic evaluations via cron jobs, and view evaluation results on a dashboard. Moves database config, user profile, evaluation config, and API keys to the settings page.
New Features: