-
Notifications
You must be signed in to change notification settings - Fork 51
PM-3786 ai assisted skills suggestions #1725
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
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 was deleted.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -1,11 +1,15 @@ | ||
| import React, { useMemo } from 'react' | ||
| import React, { useMemo, useState } from 'react' | ||
| import PropTypes from 'prop-types' | ||
| import Select from '../../Select' | ||
| import { searchSkills } from '../../../services/skills' | ||
| import cn from 'classnames' | ||
| import styles from './styles.module.scss' | ||
| import { AUTOCOMPLETE_DEBOUNCE_TIME_MS, SKILLS_OPTIONAL_BILLING_ACCOUNT_IDS } from '../../../config/constants' | ||
| import _ from 'lodash' | ||
| import { extractSkillsFromText } from '../../../services/workflowAI' | ||
| import { toastSuccess, toastFailure } from '../../../util/toaster' | ||
| import { OutlineButton } from '../../Buttons' | ||
| import Loader from '../../Loader' | ||
|
|
||
| const fetchSkills = _.debounce((inputValue, callback) => { | ||
| searchSkills(inputValue).then( | ||
|
|
@@ -22,6 +26,8 @@ const fetchSkills = _.debounce((inputValue, callback) => { | |
| }, AUTOCOMPLETE_DEBOUNCE_TIME_MS) | ||
|
|
||
| const SkillsField = ({ readOnly, challenge, onUpdateSkills, embedded }) => { | ||
| const [isLoadingAI, setIsLoadingAI] = useState(false) | ||
|
|
||
| const selectedSkills = useMemo(() => (challenge.skills || []).map(skill => ({ | ||
| label: skill.name, | ||
| value: skill.id | ||
|
|
@@ -31,30 +37,86 @@ const SkillsField = ({ readOnly, challenge, onUpdateSkills, embedded }) => { | |
| const normalizedBillingAccountId = _.isNil(billingAccountId) ? null : String(billingAccountId) | ||
| const skillsRequired = normalizedBillingAccountId ? !SKILLS_OPTIONAL_BILLING_ACCOUNT_IDS.includes(normalizedBillingAccountId) : true | ||
| const showRequiredError = !readOnly && skillsRequired && challenge.submitTriggered && (!selectedSkills || !selectedSkills.length) | ||
|
|
||
| // Check if description exists to show AI button | ||
| const hasDescription = challenge.description && challenge.description.trim().length > 0 | ||
|
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. We need to up this to logical value. Can't find skills from a desc with 1 character, right!? |
||
|
|
||
| const handleAISuggest = async () => { | ||
| if (!hasDescription || isLoadingAI) { | ||
| return | ||
| } | ||
|
|
||
| setIsLoadingAI(true) | ||
| try { | ||
| const result = await extractSkillsFromText(challenge.description) | ||
|
vas3a marked this conversation as resolved.
|
||
| const matches = result.matches || [] | ||
|
|
||
| if (matches.length === 0) { | ||
| toastFailure('No Skills Found', 'No matching standardized skills found based on the description.') | ||
| } else { | ||
| // Merge with existing skills, avoiding duplicates | ||
| const existingSkillIds = new Set((challenge.skills || []).map(s => s.id)) | ||
| const newSkills = matches.filter(skill => !existingSkillIds.has(skill.id)) | ||
|
|
||
| if (newSkills.length === 0) { | ||
| toastSuccess('Skills Already Added', 'All suggested skills are already in your selection.') | ||
| } else { | ||
| const updatedSkills = [...(challenge.skills || []), ...newSkills] | ||
| onUpdateSkills(updatedSkills) | ||
| toastSuccess('Skills Added', `${newSkills.length} skill(s) were added from AI suggestions.`) | ||
| } | ||
| } | ||
| } catch (error) { | ||
| console.error('AI skill extraction error:', error) | ||
|
vas3a marked this conversation as resolved.
|
||
| toastFailure('Error', 'Failed to extract skills. Please try again or add skills manually.') | ||
| } finally { | ||
| setIsLoadingAI(false) | ||
| } | ||
| } | ||
|
|
||
| if (embedded) { | ||
| return ( | ||
| <div className={styles.embeddedWrapper}> | ||
| <input type='hidden' /> | ||
| {readOnly ? ( | ||
| <div className={styles.embeddedReadOnly}>{existingSkills || '-'}</div> | ||
| ) : ( | ||
| <Select | ||
| id='skill-select' | ||
| isMulti | ||
| simpleValue | ||
| isAsync | ||
| value={selectedSkills} | ||
| onChange={(values) => { | ||
| onUpdateSkills((values || []).map(value => ({ | ||
| name: value.label, | ||
| id: value.value | ||
| }))) | ||
| }} | ||
| cacheOptions | ||
| loadOptions={fetchSkills} | ||
| /> | ||
| )} | ||
| <div className={styles.embeddedContent}> | ||
| {isLoadingAI && ( | ||
| <div className={styles.loadingOverlay}> | ||
| <Loader /> | ||
| <span className={styles.loadingText}>Generating skill suggestions...</span> | ||
| </div> | ||
| )} | ||
| {readOnly ? ( | ||
| <div className={styles.embeddedReadOnly}>{existingSkills || '-'}</div> | ||
| ) : ( | ||
| <> | ||
| <Select | ||
| id='skill-select' | ||
| isMulti | ||
| simpleValue | ||
| isAsync | ||
| value={selectedSkills} | ||
| onChange={(values) => { | ||
| onUpdateSkills((values || []).map(value => ({ | ||
| name: value.label, | ||
| id: value.value | ||
| }))) | ||
| }} | ||
| cacheOptions | ||
| loadOptions={fetchSkills} | ||
| isDisabled={isLoadingAI} | ||
| /> | ||
| {hasDescription && ( | ||
| <OutlineButton | ||
| type='info' | ||
| text='AI Suggest' | ||
| onClick={handleAISuggest} | ||
| disabled={isLoadingAI} | ||
| className={styles.aiSuggestButton} | ||
| /> | ||
| )} | ||
| </> | ||
| )} | ||
| </div> | ||
| {showRequiredError && ( | ||
| <div className={styles.embeddedError}>Select at least one skill</div> | ||
| )} | ||
|
|
@@ -70,25 +132,45 @@ const SkillsField = ({ readOnly, challenge, onUpdateSkills, embedded }) => { | |
| </div> | ||
| <div className={cn(styles.field, styles.col2)}> | ||
| <input type='hidden' /> | ||
| {readOnly ? ( | ||
| <span>{existingSkills}</span> | ||
| ) : ( | ||
| <Select | ||
| id='skill-select' | ||
| isMulti | ||
| simpleValue | ||
| isAsync | ||
| value={selectedSkills} | ||
| onChange={(values) => { | ||
| onUpdateSkills((values || []).map(value => ({ | ||
| name: value.label, | ||
| id: value.value | ||
| }))) | ||
| }} | ||
| cacheOptions | ||
| loadOptions={fetchSkills} | ||
| /> | ||
| )} | ||
| <div className={styles.skillsFieldWrapper}> | ||
| {isLoadingAI && ( | ||
| <div className={styles.loadingOverlay}> | ||
| <Loader /> | ||
| <span className={styles.loadingText}>Generating skill suggestions...</span> | ||
| </div> | ||
| )} | ||
| {readOnly ? ( | ||
| <span>{existingSkills}</span> | ||
| ) : ( | ||
| <> | ||
| <Select | ||
| id='skill-select' | ||
| isMulti | ||
| simpleValue | ||
| isAsync | ||
| value={selectedSkills} | ||
| onChange={(values) => { | ||
| onUpdateSkills((values || []).map(value => ({ | ||
| name: value.label, | ||
| id: value.value | ||
| }))) | ||
| }} | ||
| cacheOptions | ||
| loadOptions={fetchSkills} | ||
| isDisabled={isLoadingAI} | ||
| /> | ||
| {hasDescription && ( | ||
| <OutlineButton | ||
| type='info' | ||
| text='AI Suggest' | ||
| onClick={handleAISuggest} | ||
| disabled={isLoadingAI} | ||
| className={styles.aiSuggestButton} | ||
| /> | ||
| )} | ||
| </> | ||
| )} | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
|
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.