-
Notifications
You must be signed in to change notification settings - Fork 297
Use correct resultReason method when fetching eval reason #2089
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,13 +5,18 @@ import { | |||||||||||||
| EvaluationResultsV2Repository, | ||||||||||||||
| } from '../../repositories' | ||||||||||||||
| import { Result } from '../../lib/Result' | ||||||||||||||
| import { EvaluationResultV2 } from '../../constants' | ||||||||||||||
| import { | ||||||||||||||
| EvaluationResultSuccessValue, | ||||||||||||||
| EvaluationResultV2, | ||||||||||||||
| EvaluationV2, | ||||||||||||||
| } from '../../constants' | ||||||||||||||
| import { Issue } from '../../schema/models/types/Issue' | ||||||||||||||
| import { Message as LegacyMessage } from '@latitude-data/constants/legacyCompiler' | ||||||||||||||
| import { assembleTraceWithMessages } from '../../services/tracing/traces/assemble' | ||||||||||||||
| import { adaptCompletionSpanMessagesToLegacy } from '../../services/tracing/spans/fetching/findCompletionSpanFromTrace' | ||||||||||||||
| import { UnprocessableEntityError } from '../../lib/errors' | ||||||||||||||
| import { getHITLSpansByIssue } from './getHITLSpansByIssue' | ||||||||||||||
| import { getEvaluationMetricSpecification } from '../../services/evaluationsV2/specifications' | ||||||||||||||
|
|
||||||||||||||
| export type SpanMessagesWithEvalResultReason = { | ||||||||||||||
| messages: LegacyMessage[] | ||||||||||||||
|
|
@@ -29,10 +34,12 @@ export async function getSpanMessagesAndEvaluationResultsByIssue({ | |||||||||||||
| workspace, | ||||||||||||||
| commit, | ||||||||||||||
| issue, | ||||||||||||||
| existingEvaluations, | ||||||||||||||
| }: { | ||||||||||||||
| workspace: Workspace | ||||||||||||||
| commit: Commit | ||||||||||||||
| issue: Issue | ||||||||||||||
| existingEvaluations: EvaluationV2[] | ||||||||||||||
| }) { | ||||||||||||||
| // Three is enough, as we don't want to overfit or add too many tokens to the prompt | ||||||||||||||
| const spansResult = await getHITLSpansByIssue({ | ||||||||||||||
|
|
@@ -79,30 +86,37 @@ export async function getSpanMessagesAndEvaluationResultsByIssue({ | |||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // There will always be exactly one evaluation result for a span and trace id | ||||||||||||||
| const evaluationResults = evaluationResultsResult.filter( | ||||||||||||||
| const evaluationResult = evaluationResultsResult.find( | ||||||||||||||
| (result) => | ||||||||||||||
| result.evaluatedSpanId === span.id && | ||||||||||||||
| result.evaluatedTraceId === span.traceId, | ||||||||||||||
| )[0] | ||||||||||||||
| ) | ||||||||||||||
|
|
||||||||||||||
| const evaluation = evaluationResult | ||||||||||||||
| ? existingEvaluations.find( | ||||||||||||||
| (e) => e.uuid === evaluationResult.evaluationUuid, | ||||||||||||||
| ) | ||||||||||||||
| : undefined | ||||||||||||||
|
|
||||||||||||||
| messagesAndEvaluationResults.push({ | ||||||||||||||
| messages: adaptCompletionSpanMessagesToLegacy(completionSpan), | ||||||||||||||
| reason: getReasonFromEvaluationResult(evaluationResults), | ||||||||||||||
| reason: getReasonFromEvaluationResult(evaluationResult, evaluation), | ||||||||||||||
| }) | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| return Result.ok(messagesAndEvaluationResults) | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // We need an efficient way of extracting reasons directly from metadata without fetching evaluations | ||||||||||||||
| function getReasonFromEvaluationResult(result: EvaluationResultV2) { | ||||||||||||||
| if (result.error || !result.metadata) { | ||||||||||||||
| function getReasonFromEvaluationResult( | ||||||||||||||
| result: EvaluationResultV2 | undefined, | ||||||||||||||
| evaluation: EvaluationV2 | undefined, | ||||||||||||||
| ): string { | ||||||||||||||
| if (!result || !evaluation || result.error) { | ||||||||||||||
| return '' | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // LLM, Rule, and Human evaluations all have a reason field (required for LLM, optional for Rule/Human) | ||||||||||||||
| if ('reason' in result.metadata && result.metadata.reason) { | ||||||||||||||
| return result.metadata.reason ?? '' | ||||||||||||||
| } | ||||||||||||||
| return '' | ||||||||||||||
| const specification = getEvaluationMetricSpecification(evaluation) | ||||||||||||||
| const resultReason = specification.resultReason as ( | ||||||||||||||
| result: EvaluationResultSuccessValue, | ||||||||||||||
| ) => string | undefined | ||||||||||||||
| return resultReason(result) ?? '' | ||||||||||||||
|
Comment on lines
+118
to
+121
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TS type complaint with this: rule.ts(78, 5): 'pattern' is declared here. |
||||||||||||||
| } | ||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason I might have gotten the "missing completion metadata" issue because I didnt have the
FILES_STORAGE_PATH,FILE_PUBLIC_PATH, andPUBLIC_FILES_STORAGE_PATHenv vars. Adding these created me lots of new files in these folders, so adding them in the gitignore