Skip to content
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

feat: use correct branch name in csv urls #220

Merged
merged 6 commits into from Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/deploy_prod.yml
Expand Up @@ -22,6 +22,7 @@ jobs:
AIO_RUNTIME_APIHOST: 'https://adobeioruntime.net'
FIREFALL_ENDPOINT: 'https://firefall.adobe.io'
FIREFALL_API_KEY: aem-sidekick-genai-assistant
TARGET_API_KEY: 1a6d085515114ef9a6937de9ab7d61fe
IMS_ENDPOINT: 'https://ims-na1.adobelogin.com'
IMS_CLIENT_ID: aem-genai-assistant
IMS_SERVICE_CLIENT_ID: aem-sidekick-genai-assistant
Expand All @@ -35,7 +36,8 @@ jobs:
run: |
npm install
npm run grammar
npm run prompts
npm run build
npm run lint
npm run test
npm run deploy
npm run deploy
6 changes: 4 additions & 2 deletions .github/workflows/deploy_qa.yml
Expand Up @@ -2,7 +2,7 @@ name: Deploy to QA

on:
pull_request:
branches:
branches:
- main
types: [closed]

Expand All @@ -24,6 +24,7 @@ jobs:
AIO_RUNTIME_APIHOST: 'https://adobeioruntime.net'
FIREFALL_ENDPOINT: 'https://firefall.adobe.io'
FIREFALL_API_KEY: aem-sidekick-genai-assistant
TARGET_API_KEY: 1a6d085515114ef9a6937de9ab7d61fe
IMS_ENDPOINT: 'https://ims-na1.adobelogin.com'
IMS_CLIENT_ID: aem-genai-assistant
IMS_SERVICE_CLIENT_ID: aem-sidekick-genai-assistant
Expand All @@ -37,7 +38,8 @@ jobs:
run: |
npm install
npm run grammar
npm run prompts
npm run build
npm run lint
npm run test
npm run deploy
npm run deploy
3 changes: 2 additions & 1 deletion .github/workflows/pr_test_frontend.yml
Expand Up @@ -20,6 +20,7 @@ jobs:
run: |
npm install
npm run grammar
npm run prompts
npm run build
npm run lint
npm run test
npm run test
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -40,3 +40,4 @@ coverage
# logs folder for aio-run-detached
logs


9 changes: 1 addition & 8 deletions .husky/pre-commit
@@ -1,17 +1,10 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

# If *.prompt files or prompt-index.json file have changed, run prompts
if [ -n "$(git diff --cached --name-only | grep -E 'examples/.*\.prompt$')" ] || [ -n "$(git diff --cached --name-only | grep -E 'examples/prompt-index.json$')" ]; then
npm run prompts
else
echo "No prompt files changed. Skipping 'npm run prompts'"
fi

# If excel or csv files in the examples/ directory have changed, run the zip examples script
if [ -n "$(git diff --cached --name-only | grep -E 'examples/.*\.(csv|xlsx)$')" ]; then
npm run examples
else
else
echo "No excel or csv files changed. Skipping 'npm run examples'"
fi

Expand Down
2 changes: 1 addition & 1 deletion actions/csv/index.js
Expand Up @@ -15,7 +15,7 @@ const { asGenericAction } = require('../GenericAction.js');

async function main({ url }) {
const text = await wretch(url).get().text();
const { data } = Papa.parse(text, {});
const { data } = Papa.parse(text, { skipEmptyLines: true });
return data;
}

Expand Down
12 changes: 6 additions & 6 deletions data/bundled-prompt-templates.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -12,7 +12,7 @@
"build": "REACT_APP_VERSION=$npm_package_version aio app build",
"deploy:app": "npm run grammar && REACT_APP_VERSION=$npm_package_version aio app deploy --no-actions",
"deploy:actions": "aio app deploy --no-web-assets",
"deploy": "npm run grammar && REACT_APP_VERSION=$npm_package_version aio app deploy",
"deploy": "npm run grammar && npm run prompts && REACT_APP_VERSION=$npm_package_version aio app deploy",
"lint": "eslint --quiet 'web-src/src/**/*.js' 'actions/*.js'",
"fix": "eslint --fix --quiet 'web-src/src/**/*.js' 'actions/*.js'",
"test": "jest --collectCoverageFrom='[\"web-src/src/**/*.js\",\"actions/**/*.js\"]' --coverage --passWithNoTests ./actions ./web-src/src ./e2e"
Expand Down
2 changes: 1 addition & 1 deletion prompt-templates/card.prompt
Expand Up @@ -79,7 +79,7 @@ Additional context: [[
{{@target_audience,
label="Target Audience",
description="Choose your audience. For Target, audiences with no description will be unavailable. For CSV, Adobe provides audiences to get you started. To modify audiences publish a CSV file and update the URL in the prompt.",
csv="https://raw.githubusercontent.com/adobe/aem-genai-assistant/data/target-audiences.csv",
csv="https://raw.githubusercontent.com/adobe/aem-genai-assistant/GIT_BRANCH/data/target-audiences.csv",
adobe_target=true,
type=audience
}}
Expand Down
2 changes: 1 addition & 1 deletion prompt-templates/cart-abandonment.prompt
Expand Up @@ -68,7 +68,7 @@ Additional context: [[
{{@target_audience,
label="Target Audience",
description="Choose your audience. For Target, audiences with no description will be unavailable. For CSV, Adobe provides audiences to get you started. To modify audiences publish a CSV file and update the URL in the prompt.",
csv="https://raw.githubusercontent.com/adobe/aem-genai-assistant/settings/data/target-audiences.csv",
csv="https://raw.githubusercontent.com/adobe/aem-genai-assistant/GIT_BRANCH/data/target-audiences.csv",
adobe_target=true,
type=audience
}}
Expand Down
2 changes: 1 addition & 1 deletion prompt-templates/headline.prompt
Expand Up @@ -42,7 +42,7 @@ To ensure the Headlines are effective and meet our objectives, adhere to the fol
{{@target_audience,
label="Target Audience",
description="Choose your audience. For Target, audiences with no description will be unavailable. For CSV, Adobe provides audiences to get you started. To modify audiences publish a CSV file and update the URL in the prompt.",
csv="https://raw.githubusercontent.com/adobe/aem-genai-assistant/settings/data/target-audiences.csv",
csv="https://raw.githubusercontent.com/adobe/aem-genai-assistant/GIT_BRANCH/data/target-audiences.csv",
adobe_target=true,
type=audience
}}
Expand Down
2 changes: 1 addition & 1 deletion prompt-templates/hero.prompt
Expand Up @@ -81,7 +81,7 @@ Additional context: [[
{{@target_audience,
label="Target Audience",
description="Choose your audience. For Target, audiences with no description will be unavailable. For CSV, Adobe provides audiences to get you started. To modify audiences publish a CSV file and update the URL in the prompt.",
csv="https://raw.githubusercontent.com/adobe/aem-genai-assistant/settings/data/target-audiences.csv",
csv="https://raw.githubusercontent.com/adobe/aem-genai-assistant/GIT_BRANCH/data/target-audiences.csv",
adobe_target=true,
type=audience
}}
Expand Down
2 changes: 1 addition & 1 deletion prompt-templates/rewrite.prompt
Expand Up @@ -66,7 +66,7 @@ Additional context: [[
{{@target_audience,
label="Target Audience",
description="Choose your audience. For Target, audiences with no description will be unavailable. For CSV, Adobe provides audiences to get you started. To modify audiences publish a CSV file and update the URL in the prompt.",
csv="https://raw.githubusercontent.com/adobe/aem-genai-assistant/settings/data/target-audiences.csv",
csv="https://raw.githubusercontent.com/adobe/aem-genai-assistant/GIT_BRANCH/data/target-audiences.csv",
adobe_target=true,
type=audience
}}
Expand Down
2 changes: 1 addition & 1 deletion prompt-templates/tile.prompt
Expand Up @@ -80,7 +80,7 @@ Additional context: [[
{{@target_audience,
label="Target Audience",
description="Choose your audience. For Target, audiences with no description will be unavailable. For CSV, Adobe provides audiences to get you started. To modify audiences publish a CSV file and update the URL in the prompt.",
csv="https://raw.githubusercontent.com/adobe/aem-genai-assistant/settings/data/target-audiences.csv",
csv="https://raw.githubusercontent.com/adobe/aem-genai-assistant/GIT_BRANCH/data/target-audiences.csv",
adobe_target=true,
type=audience
}}
Expand Down
20 changes: 17 additions & 3 deletions scripts/prompt-generator.js
Expand Up @@ -12,6 +12,7 @@

const fs = require('fs');
const path = require('path');
const { exec } = require('child_process');

const DATA_DIR = path.join(__dirname, '../data');
const PROMPT_TEMPLATES_DIR = path.join(__dirname, '../prompt-templates');
Expand Down Expand Up @@ -64,6 +65,18 @@ const createBundledPromptTemplates = (promptIndex) => {
return bundledPromptTemplates;
};

const getGitBranchName = async () => {
return new Promise((resolve) => {
exec('git branch --show-current', (err, stdout, stderr) => {
if (err) {
console.error(`Error: ${err}`);
return 'main';
}
resolve(stdout.replace(/(\r\n|\n|\r)/gm, ''));
});
});
};

const startProgram = async () => {
console.log('- Prompt Generator Starting...');
try {
Expand All @@ -77,13 +90,14 @@ const startProgram = async () => {
const bundledPromptTemplates = createBundledPromptTemplates(sortedPromptIndex);

// Add the prompt templates to the target files
promptIndex.forEach((prompt) => {
for await (const prompt of promptIndex) {
console.log(`\t\t* Adding ${prompt.label}`);
// Try to read the prompt template file
// If it fails, log the error and continue
try {
const promptTemplate = fs.readFileSync(path.join(PROMPT_TEMPLATES_DIR, prompt.file), 'utf8');
prompt.template = promptTemplate;
const branchName = await getGitBranchName();
prompt.template = promptTemplate.replace(/GIT_BRANCH/g, branchName);
delete prompt.file;

// Add the prompt to the bundled prompt templates file
Expand All @@ -93,7 +107,7 @@ const startProgram = async () => {
console.log(`\t\t\t! Error: ${err}`);
console.log(`\t\t\t! Skipping ${prompt.label}`);
}
});
}

// Write the prompt templates to the target files
saveBundledPromptTemplates(bundledPromptTemplates);
Expand Down
8 changes: 6 additions & 2 deletions web-src/src/components/AudienceSelector.js
Expand Up @@ -34,6 +34,10 @@ const styles = {
`,
};

export function isTargetEnabled(adobeTarget) {
return /^(true|1|yes)$/i.test(adobeTarget?.toString().trim());
}

export function useGetItemsFromTarget() {
const { targetService } = useApplicationContext();
return useCallback(async () => {
Expand Down Expand Up @@ -93,9 +97,9 @@ export function AudienceSelector({

useEffect(() => {
setItems([]);
if (adobeTarget && !csv) {
if (isTargetEnabled(adobeTarget) && !csv) {
setDataSource(DATA_SOURCES.TARGET);
} else if (csv && !adobeTarget) {
} else if (csv && !isTargetEnabled(adobeTarget)) {
setDataSource(DATA_SOURCES.CSV);
}
if (dataSource === DATA_SOURCES.CSV) {
Expand Down
50 changes: 49 additions & 1 deletion web-src/src/components/AudienceSelector.test.js
Expand Up @@ -11,10 +11,58 @@
*/
import { renderHook, waitFor } from '@testing-library/react';
import { useApplicationContext } from './ApplicationProvider.js';
import { useGetItemsFromTarget } from './AudienceSelector.js';
import { isTargetEnabled, useGetItemsFromTarget } from './AudienceSelector.js';

jest.mock('./ApplicationProvider.js');

describe('isTargetEnabled', () => {
test('returns true for "true" (case insensitive) with or without spaces', () => {
expect(isTargetEnabled('true')).toBe(true);
expect(isTargetEnabled(' TRUE ')).toBe(true);
});

test('returns true for "1" with or without spaces', () => {
expect(isTargetEnabled('1')).toBe(true);
expect(isTargetEnabled(' 1 ')).toBe(true);
});

test('returns true for "yes" (case insensitive) with or without spaces', () => {
expect(isTargetEnabled('yes')).toBe(true);
expect(isTargetEnabled(' YES ')).toBe(true);
});

test('returns false for "false"', () => {
expect(isTargetEnabled('false')).toBe(false);
});

test('returns false for "0"', () => {
expect(isTargetEnabled('0')).toBe(false);
});

test('returns false for "no"', () => {
expect(isTargetEnabled('no')).toBe(false);
});

test('returns false for undefined', () => {
expect(isTargetEnabled(undefined)).toBe(false);
});

test('returns false for null', () => {
expect(isTargetEnabled(null)).toBe(false);
});

test('returns false for non-string values', () => {
expect(isTargetEnabled(123)).toBe(false);
expect(isTargetEnabled({})).toBe(false);
expect(isTargetEnabled([])).toBe(false);
});

test('returns false for string values that do not match "true", "1", or "yes" exactly, even without spaces', () => {
expect(isTargetEnabled('_True')).toBe(false);
expect(isTargetEnabled('Yes.')).toBe(false);
});
});

describe('useGetItemsFromTarget', () => {
it('should return audiences sorted by description and mapped correctly', async () => {
const mockAudiences = [
Expand Down