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: reading and writing prompts using settings api #204

Merged
merged 21 commits into from Mar 8, 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
2 changes: 1 addition & 1 deletion actions/complete/index.js
Expand Up @@ -20,4 +20,4 @@ async function main(params) {
return firefallClient.completion(prompt ?? 'Who are you?', temperature ?? 0.0, model ?? 'gpt-4');
}

exports.main = asAuthAction(asFirefallAction(asGenericAction(main)));
exports.main = asGenericAction(asAuthAction(asFirefallAction(main)));
22 changes: 22 additions & 0 deletions actions/csv/index.js
@@ -0,0 +1,22 @@
/*
* Copyright 2023 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
const wretch = require('wretch');
const Papa = require('papaparse');
const { asGenericAction } = require('../GenericAction.js');

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

exports.main = asGenericAction(main);
2 changes: 1 addition & 1 deletion actions/feedback/index.js
Expand Up @@ -18,4 +18,4 @@ async function main(params) {
return firefallClient.feedback(queryId, sentiment);
}

exports.main = asAuthAction(asFirefallAction(asGenericAction(main)));
exports.main = asGenericAction(asAuthAction(asFirefallAction(main)));
43 changes: 43 additions & 0 deletions actions/target/index.js
@@ -0,0 +1,43 @@
/*
* Copyright 2023 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
const wretch = require('wretch');
const { asGenericAction } = require('../GenericAction.js');

const MIN_DESCRIPTION_LENGTH = 5;

async function main({ __ow_headers: headers, org, TARGET_API_KEY }) {
const { authorization } = headers;
const accessToken = authorization.split(' ')[1];

const json = await wretch(`https://mc.adobe.io/${org}/target/audiences`)
.headers({
'x-api-key': TARGET_API_KEY,
})
.auth(`Bearer ${accessToken}`)
.accept('application/vnd.adobe.target.v3+json')
.get()
.json();

if (!json.audiences) {
throw new Error('Failed to fetch audiences');
}

return json.audiences
.filter((audience) => audience.name && audience.type === 'reusable')
.map((audience) => ({
id: audience.id,
name: audience.name.trim(),
description: audience.description?.length > MIN_DESCRIPTION_LENGTH ? audience.description.trim() : null,
}));
}

exports.main = asGenericAction(main);
10 changes: 10 additions & 0 deletions app.config.yaml
Expand Up @@ -35,3 +35,13 @@ application:
IMS_PRODUCT_CONTEXT: $IMS_PRODUCT_CONTEXT
limits:
timeout: 180000
target:
function: actions/target/index.js
web: true
runtime: nodejs:18
inputs:
TARGET_API_KEY: $TARGET_API_KEY
vtsaplin marked this conversation as resolved.
Show resolved Hide resolved
csv:
function: actions/csv/index.js
web: true
runtime: nodejs:18

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions data/target-audiences.csv
@@ -0,0 +1,12 @@
Universal audience,"Universal audience: This audience includes all people, spanning all backgrounds. While some members are heavy consumers of digital media and highly influenced by social media, other individuals may rely more on traditional media channels. They all place value on experiences and brand alignment in their purchasing decisions",,,
Financial Services,"Financial Services: The average target audience are individuals who seek to manage, invest, and secure their finances efficiently. They value trust, transparency, flexibility, and personalized service. They seek digital solutions for banking, investing, insurance, tax planning, and retirement planning.",,,
Media and Entertainment,"Media and Entertainment: This audience immerses themselves in diverse forms of entertainment, be it music, movies, TV shows, news, sports or books. They value engaging, high-quality content and prefer platforms that offer a broad range of genres and formats.",,,
Retail,"Retail: The target audience here are consumers who value quality, affordability, and convenience in purchasing goods and services. They appreciate a wide array of choices, excellent customer service, easy return policies, and timely delivery.",,,
Travel and Hospitality,"Travel and Hospitality: These individuals enjoy exploring new places, cultures, and cuisines. They value hassle-free booking experiences, quality accommodations, unique experiences, and excellent customer service.",,,
Healthcare,"Healthcare: This audience consists of individuals seeking quality healthcare services and products. They prioritize professional expertise, advanced technology, compassionate care, and accessible health information.",,,
High Tech,"High Tech: These are consumers interested in the latest technology trends and innovations. They value advanced features, reliability, efficiency, and top-notch after-sales support. They seek products and gadgets that improve their work, entertainment, or daily tasks.",,,
Government,"Government: The audience is the general public who are concerned with policies, public services, and civic issues. They value transparency, efficiency, security, and good governance. They seek clear communication and easy access to information and services.",,,
Telecommunication,"Telecommunication: These individuals value strong, reliable, and affordable communication and connectivity solutions. They appreciate innovative features, quality customer service, flexibility on plans and packages, and wide network coverage.",,,
Consumer Goods,"Consumer Goods: These are consumers who value quality, affordability, and accessibility in everyday products. They appreciate brands that offer reliability, innovative features, and responsible manufacturing practices.",,,
Education,"Education: This audience includes lifelong learners who value knowledge and personal growth. They prefer accessible, affordable, and high-quality educational resources and platforms. They value diverse learning methods and continuous skill development.",,,
Manufacturing,"Manufacturing: The target audience here are businesses and consumers who need quality, durable, and affordable products. They appreciate innovation, adherence to safety standards, efficiency, and reliability in both product and service.",,,
21 changes: 16 additions & 5 deletions e2e/WebApp.test.js
Expand Up @@ -19,17 +19,28 @@ import { defaultTheme, Provider } from '@adobe/react-spectrum';
import { ApplicationProvider } from '../web-src/src/components/ApplicationProvider.js';
import { App } from '../web-src/src/components/App.js';
import { CONSENT_KEY } from '../web-src/src/components/ConsentDialog.js';
import { PROMPT_TEMPLATE_STORAGE_KEY } from '../web-src/src/state/PromptTemplatesState.js';

const CONFIG_URL = 'https://localhost:9080/index.html?ref=ref&repo=repo&owner=owner';

const mockConsentKey = CONSENT_KEY;
const mockPromptTemplateStorageKey = PROMPT_TEMPLATE_STORAGE_KEY;

jest.mock('@adobe/exc-app/settings', () => ({
get: jest.fn().mockImplementation(() => Promise.resolve({
settings: {
[mockConsentKey]: true,
},
})),
get: jest.fn().mockImplementation(({ groupId, level, defaultValue }) => {
if (groupId === mockPromptTemplateStorageKey) {
return Promise.resolve({
settings: {
promptTemplates: [],
},
});
}
return Promise.resolve({
settings: {
[mockConsentKey]: true,
},
});
}),
SettingsLevel: jest.fn(),
}));

Expand Down
Binary file removed examples/Templates.zip
Binary file not shown.
1 change: 0 additions & 1 deletion examples/prompt-templates.csv

This file was deleted.

Binary file removed examples/prompt-templates.xlsx
Binary file not shown.
Binary file modified examples/target-audiences.xlsx
Binary file not shown.