Repository navigation
OpenConceptLab/ocl_issues#2908 | One recommendation rule: the OCL AI Assistant decides when it has analysed the current candidates, the score orders the rest #110
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
Open
paynejd
wants to merge
9
commits into
main
Choose a base branch
from
OpenConceptLab/ocl_issues#2908-ai-first-rule
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,467
−575
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
449fe3b
OpenConceptLab/ocl_issues#2908 | Add the recommendation rule: the OCL…
paynejd 525f1e0
OpenConceptLab/ocl_issues#2908 | Show the recommendation in the candi…
paynejd 11c3394
OpenConceptLab/ocl_issues#2908 | AutoMatch proposes by the recommenda…
paynejd de6c38d
OpenConceptLab/ocl_issues#2908 | Codex pass 1: an AI-only run clears …
paynejd 7dbbb12
OpenConceptLab/ocl_issues#2908 | Codex pass 2: the disagreement filte…
paynejd 17f2698
OpenConceptLab/ocl_issues#2908 | Codex pass 3: closing an older analy…
paynejd 6e713b6
OpenConceptLab/ocl_issues#2908 | Simplify: AI_DISAGREEMENTS is privat…
paynejd e5e5ce6
OpenConceptLab/ocl_issues#2908 | merge main (AutoMatch dialog, OpenCo…
paynejd 2d51c45
OpenConceptLab/ocl_issues#2908 | merge main (Mapper settings checkpoi…
snyaggarwal 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| import React from 'react' | ||
| import { useTranslation } from 'react-i18next'; | ||
| import Chip from '@mui/material/Chip' | ||
| import CircularProgress from '@mui/material/CircularProgress' | ||
| import IconButton from '@mui/material/IconButton' | ||
| import Link from '@mui/material/Link' | ||
| import Tooltip from '@mui/material/Tooltip' | ||
| import Typography from '@mui/material/Typography' | ||
| import AssistantIcon from '@mui/icons-material/Assistant'; | ||
|
|
||
| import { getScoreDetails } from './viewBuilders.js' | ||
|
|
||
| // How the grid and the candidates panel put a row's recommendation | ||
| // (getRowRecommendation, OpenConceptLab/ocl_issues#2908) into words. | ||
|
|
||
| const codeOf = view => view?.conceptDefinition?.id || view?.conceptDefinition?.reference?.code | ||
| const outputOf = recommendation => recommendation?.analysis?.output || recommendation?.analysis | ||
| // The code the OCL AI Assistant named, also when it isn't one of the candidates. | ||
| const pickCodeOf = recommendation => codeOf(recommendation?.pick) || outputOf(recommendation)?.primary_candidate?.canonical_reference?.code | ||
|
|
||
| const CONFIDENCES = ['high', 'medium', 'low'] | ||
| const describeConfidence = (t, recommendation) => { | ||
| const confidence = recommendation?.confidence?.toLowerCase() | ||
| return CONFIDENCES.includes(confidence) ? t(`map_project.ai_confidence_${confidence}`) : null | ||
| } | ||
|
|
||
| const describeTopScore = (t, top, candidatesScore) => { | ||
| if(!top) return t('map_project.ai_no_top_score') | ||
| const { qualityBucket, rerankScore } = getScoreDetails({candidate: top.candidate, conceptRow: top.conceptRow}, candidatesScore) | ||
| return t('map_project.ai_top_score', {code: codeOf(top), bucket: t(`map_project.${qualityBucket}`), score: rerankScore}) | ||
| } | ||
|
|
||
| const describePickRank = (t, recommendation) => recommendation.pickRank ? | ||
| t('map_project.ai_pick_rank', {code: pickCodeOf(recommendation), rank: recommendation.pickRank}) : | ||
| t('map_project.ai_pick_unscored', {code: pickCodeOf(recommendation)}) | ||
|
|
||
| const describeVerdict = (t, recommendation) => { | ||
| const code = pickCodeOf(recommendation) | ||
| const confidence = describeConfidence(t, recommendation) | ||
| const withConfidence = text => confidence ? `${text} (${confidence})` : text | ||
| switch(recommendation?.verdict) { | ||
| case 'RECOMMEND': return code ? withConfidence(t('map_project.ai_summary_recommend', {code})) : t('map_project.ai_summary_no_pick') | ||
| case 'CONDITIONAL': return code ? withConfidence(t('map_project.ai_summary_conditional', {code})) : t('map_project.ai_summary_no_pick') | ||
| case 'REJECT': return t('map_project.ai_summary_reject') | ||
| case 'INSUFFICIENT': return t('map_project.ai_summary_insufficient') | ||
| default: return '' | ||
| } | ||
| } | ||
|
|
||
| const describeRelation = (t, recommendation) => { | ||
| switch(recommendation?.agreement) { | ||
| case 'agrees': return t('map_project.ai_summary_agree') | ||
| case 'different_pick': return recommendation.pickRank ? | ||
| t('map_project.ai_summary_differ_rank', {rank: recommendation.pickRank}) : | ||
| t('map_project.ai_summary_differ_unscored') | ||
| case 'no_match': | ||
| case 'not_enough': return t('map_project.ai_summary_no_proposal') | ||
| case 'out_of_date': return t('map_project.ai_out_of_date_help') | ||
| case 'pick_not_candidate': return t('map_project.ai_pick_not_candidate_help') | ||
| default: return '' | ||
| } | ||
| } | ||
|
|
||
| // The status label, also the column's value for sorting and filtering. | ||
| export const getAIStatusLabel = (t, status, recommendation) => { | ||
| if(!status) return '' | ||
| const label = t(`map_project.ai_status_${status}`) | ||
| return recommendation?.conditional && ['agrees', 'different_pick'].includes(status) ? | ||
| `${label} (${t('map_project.ai_conditional')})` : label | ||
| } | ||
|
|
||
| const STATUS_COLORS = { | ||
| agrees: 'primary', | ||
| different_pick: 'warning', | ||
| pick_not_candidate: 'warning', | ||
| no_match: 'error', | ||
| not_enough: 'error', | ||
| } | ||
|
|
||
| // The tooltip names the other side: the top score, and where the pick ranks. | ||
| const getStatusTooltip = (t, status, recommendation, candidatesScore) => { | ||
| if(status === 'out_of_date') return t('map_project.ai_out_of_date_help') | ||
| if(status === 'pick_not_candidate') return t('map_project.ai_pick_not_candidate_help') | ||
| const lines = [describeTopScore(t, recommendation?.top, candidatesScore)] | ||
| if(status === 'different_pick') lines.push(describePickRank(t, recommendation)) | ||
| const confidence = describeConfidence(t, recommendation) | ||
| if(confidence) lines.push(confidence) | ||
| return lines.map(line => <div key={line}>{line}</div>) | ||
| } | ||
|
|
||
| /** | ||
| * The grid's "OCL AI Assistant" cell: running, failed (click to retry), or | ||
| * the agreement state, with the other side in its tooltip. | ||
| */ | ||
| export const AIAssistantStatusCell = ({ status, recommendation, candidatesScore, onRetry }) => { | ||
| const { t } = useTranslation(); | ||
| if(!status) return null | ||
| if(status === 'running') | ||
| return ( | ||
| <Tooltip title={t('map_project.ai_recommendation_running')}> | ||
| <span style={{display: 'inline-flex', alignItems: 'center', gap: '6px', fontSize: '13px'}}> | ||
| <CircularProgress size={14} /> | ||
| {getAIStatusLabel(t, status)} | ||
| </span> | ||
| </Tooltip> | ||
| ) | ||
| if(status === 'failed') | ||
| return ( | ||
| <Tooltip title={t('map_project.ai_recommendation_failed_retry')}> | ||
| <IconButton size='small' sx={{padding: '4px', fontSize: '13px', borderRadius: '8px'}} onClick={event => { event.stopPropagation(); onRetry?.() }}> | ||
| <AssistantIcon color='error' fontSize='small' sx={{marginRight: '4px'}} /> | ||
| {getAIStatusLabel(t, status)} | ||
| </IconButton> | ||
| </Tooltip> | ||
| ) | ||
| return ( | ||
| <Tooltip title={getStatusTooltip(t, status, recommendation, candidatesScore)}> | ||
| <Chip | ||
| size='small' | ||
| label={getAIStatusLabel(t, status, recommendation)} | ||
| color={STATUS_COLORS[status] || 'default'} | ||
| variant='outlined' | ||
| /> | ||
| </Tooltip> | ||
| ) | ||
| } | ||
|
|
||
| /** | ||
| * The candidates panel's summary line: the OCL AI Assistant's verdict in plain | ||
| * words, its pick and the top score, and whether they differ. Shown whenever | ||
| * the row has an analysis. | ||
| */ | ||
| export const AIAssistantSummary = ({ recommendation, candidatesScore, onReadAnalysis, sx }) => { | ||
| const { t } = useTranslation(); | ||
| if(!recommendation?.verdict) return null | ||
| const text = t('map_project.ai_summary', { | ||
| verdict: describeVerdict(t, recommendation), | ||
| topScore: describeTopScore(t, recommendation.top, candidatesScore), | ||
| relation: describeRelation(t, recommendation), | ||
| }) | ||
| return ( | ||
| <div style={{display: 'flex', alignItems: 'flex-start', gap: '6px', padding: '6px 8px', margin: '4px 0', borderRadius: '8px', backgroundColor: 'rgb(238, 238, 238)', ...sx}} id='ai-assistant-summary'> | ||
| <AssistantIcon color='primary' sx={{fontSize: '1rem', marginTop: '1px'}} /> | ||
| <Typography component='span' sx={{fontSize: 12, lineHeight: 1.4}}> | ||
| {text} | ||
| { | ||
| onReadAnalysis && | ||
| <Link component='button' type='button' underline='hover' onClick={onReadAnalysis} sx={{fontSize: 12, marginLeft: '6px', verticalAlign: 'baseline'}}> | ||
| {t('map_project.read_analysis')} | ||
| </Link> | ||
| } | ||
| </Typography> | ||
| </div> | ||
| ) | ||
| } | ||
Oops, something went wrong.
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 out-of-date tooltip could include the old pick and its rank, as
different_pickdoes, e.g. "Picked CIEL:1065 (rank 3); the candidates changed since, so the score decides".recommendation.pickandpickRankare still set for out-of-date analyses, so the data is already here.