Skip to content

Commit 5b5c1a9

Browse files
committed
Implement 27 and 28
Signed-off-by: David Weik <[email protected]>
1 parent 2805511 commit 5b5c1a9

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## SAS Portal Framework for SAS Viya v1.2.2
4+
5+
- Fix: Prompt Builder now prevents the creation of scoring files with invalid Python package names
6+
- Add: validate-python-package-name utility function
7+
- Change: For variables in a manifested prompt auto trimming was added to remove leading and trailing blanks
8+
39
## SAS Portal Framework for SAS Viya v1.2.1
410

511
- Fix: The SCR Module Scorer object had a bug where it would parse a string beginning with a number as a number and remove the text

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
<script src="./js/utility/get-formatted-datetime.js"></script>
115115
<script src="./js/utility/copy-file.js"></script>
116116
<script src="./js/utility/copy-report.js"></script>
117+
<script src="./js/utility/validate-pyhton-package-name.js"></script>
117118

118119
<!-- Import Object Builder -->
119120
<script src="./js/objects/add-text-objects.js"></script>

js/objects/add-prompt-builder.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ async function addPromptBuilderObject(promptBuilderObject, paneID, promptBuilder
940940
}
941941
scoreCodeInput += promptInputs[i].name;
942942
if (promptInputs[i].name !== 'API_KEY') {
943-
scoreCodeUserPrompt += `${promptInputs[i].name}: {${promptInputs[i].name}}`
943+
scoreCodeUserPrompt += `${promptInputs[i].name}: {str(${promptInputs[i].name}).strip()}`
944944
}
945945
}
946946
// Create the options string for the score code
@@ -991,9 +991,10 @@ async function addPromptBuilderObject(promptBuilderObject, paneID, promptBuilder
991991
for(let i = 0; i < modelVariables.length; i++) {
992992
deleteModelVariable(window.VIYA, promptExperimentRunModel, modelVariables[i].id);
993993
}
994+
let validatedModelName = validateAndCorrectPackageName(promptExperimentRunModelName);
994995
let manifestPromptInputResponseObject = await createModelContent(VIYA, promptExperimentRunModel, promptInputs, 'inputVar.json', 'inputVariables');
995996
let manifestPromptOutputResponseObject = await createModelContent(VIYA, promptExperimentRunModel, outputVars, 'outputVar.json', 'outputVariables');
996-
let manifestPromptScoreCodeResponseObject = await createModelContent(VIYA, promptExperimentRunModel, mainfestPromptScoreCodeBlob, `${promptExperimentRunModelName}.py`, 'score', 'text/x-python');
997+
let manifestPromptScoreCodeResponseObject = await createModelContent(VIYA, promptExperimentRunModel, mainfestPromptScoreCodeBlob, `${validatedModelName.correctedName}.py`, 'score', 'text/x-python');
997998
} else {
998999
promptExperimentResultTargetContainer.innerText = `${promptBuilderInterfaceText?.promptBuilderCreateModelNoBestPrompt}`
9991000
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* A function that checks a string for being a valid Python package name:
3+
* - https://peps.python.org/pep-0508/
4+
* - https://peps.python.org/pep-0008/
5+
* @param {String} name - Potential name of the variable
6+
* @returns {Object} - has two attributes isValid {Boolean} and correctedName {String}
7+
*/
8+
function validateAndCorrectPackageName(inputString) {
9+
// Convert to lowercase and replace invalid characters with hyphens
10+
let correctedName = inputString.toLowerCase().replace(/[^a-z0-9-]/g, '-');
11+
12+
// Remove leading/trailing and consecutive hyphens
13+
correctedName = correctedName.replace(/^-+|-+$/g, '').replace(/-{2,}/g, '-');
14+
15+
// Determine if the original input was already valid
16+
const isValid = inputString === correctedName;
17+
18+
// Handle edge case of an empty corrected name
19+
if (correctedName === '') {
20+
return {
21+
isValid: false,
22+
correctedName: 'invalid-package-name'
23+
};
24+
}
25+
26+
// 5. Return the result object
27+
return {
28+
isValid: isValid,
29+
correctedName: correctedName
30+
};
31+
}

0 commit comments

Comments
 (0)