@transcend-io/cli 4.107.0 → 4.109.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +103 -3
- package/build/ai/TranscendPromptManager.d.ts +137 -0
- package/build/ai/TranscendPromptManager.d.ts.map +1 -0
- package/build/ai/TranscendPromptManager.js +159 -0
- package/build/ai/TranscendPromptManager.js.map +1 -0
- package/build/ai/index.d.ts +1 -2
- package/build/ai/index.d.ts.map +1 -1
- package/build/ai/index.js +1 -2
- package/build/ai/index.js.map +1 -1
- package/build/cli-create-assessment.js +3 -4
- package/build/cli-create-assessment.js.map +1 -1
- package/build/codecs.d.ts +95 -1
- package/build/codecs.d.ts.map +1 -1
- package/build/codecs.js +56 -2
- package/build/codecs.js.map +1 -1
- package/build/constants.d.ts.map +1 -1
- package/build/constants.js +8 -0
- package/build/constants.js.map +1 -1
- package/build/enums.d.ts +5 -1
- package/build/enums.d.ts.map +1 -1
- package/build/enums.js +4 -0
- package/build/enums.js.map +1 -1
- package/build/graphql/fetchAllActions.js +1 -1
- package/build/graphql/fetchAllActions.js.map +1 -1
- package/build/graphql/fetchAllAttributeKeys.js +1 -1
- package/build/graphql/fetchAllAttributeKeys.js.map +1 -1
- package/build/graphql/fetchAllBusinessEntities.js +1 -1
- package/build/graphql/fetchAllBusinessEntities.js.map +1 -1
- package/build/graphql/fetchAssessmentTemplates.js +1 -1
- package/build/graphql/fetchAssessmentTemplates.js.map +1 -1
- package/build/graphql/fetchAssessments.js +1 -1
- package/build/graphql/fetchAssessments.js.map +1 -1
- package/build/graphql/fetchIdentifiers.js +1 -1
- package/build/graphql/fetchIdentifiers.js.map +1 -1
- package/build/graphql/fetchPromptGroups.d.ts +22 -0
- package/build/graphql/fetchPromptGroups.d.ts.map +1 -0
- package/build/graphql/fetchPromptGroups.js +32 -0
- package/build/graphql/fetchPromptGroups.js.map +1 -0
- package/build/graphql/fetchPromptPartials.d.ts +17 -0
- package/build/graphql/fetchPromptPartials.d.ts.map +1 -0
- package/build/graphql/fetchPromptPartials.js +32 -0
- package/build/graphql/fetchPromptPartials.js.map +1 -0
- package/build/graphql/fetchPromptTemplates.d.ts +17 -0
- package/build/graphql/fetchPromptTemplates.d.ts.map +1 -0
- package/build/graphql/fetchPromptTemplates.js +32 -0
- package/build/graphql/fetchPromptTemplates.js.map +1 -0
- package/build/graphql/fetchPrompts.d.ts +83 -0
- package/build/graphql/fetchPrompts.d.ts.map +1 -0
- package/build/graphql/fetchPrompts.js +55 -0
- package/build/graphql/fetchPrompts.js.map +1 -0
- package/build/graphql/gqls/assessment.js +1 -1
- package/build/graphql/gqls/index.d.ts +1 -0
- package/build/graphql/gqls/index.d.ts.map +1 -1
- package/build/graphql/gqls/index.js +1 -0
- package/build/graphql/gqls/index.js.map +1 -1
- package/build/graphql/gqls/prompt.d.ts +14 -0
- package/build/graphql/gqls/prompt.d.ts.map +1 -0
- package/build/graphql/gqls/prompt.js +183 -0
- package/build/graphql/gqls/prompt.js.map +1 -0
- package/build/graphql/index.d.ts +5 -0
- package/build/graphql/index.d.ts.map +1 -1
- package/build/graphql/index.js +5 -0
- package/build/graphql/index.js.map +1 -1
- package/build/graphql/pullTranscendConfiguration.d.ts.map +1 -1
- package/build/graphql/pullTranscendConfiguration.js +50 -1
- package/build/graphql/pullTranscendConfiguration.js.map +1 -1
- package/build/graphql/syncConfigurationToTranscend.d.ts.map +1 -1
- package/build/graphql/syncConfigurationToTranscend.js +22 -1
- package/build/graphql/syncConfigurationToTranscend.js.map +1 -1
- package/build/graphql/syncDataSilos.js +2 -2
- package/build/graphql/syncDataSilos.js.map +1 -1
- package/build/graphql/syncEnrichers.js +2 -2
- package/build/graphql/syncEnrichers.js.map +1 -1
- package/build/graphql/syncPromptGroups.d.ts +34 -0
- package/build/graphql/syncPromptGroups.d.ts.map +1 -0
- package/build/graphql/syncPromptGroups.js +126 -0
- package/build/graphql/syncPromptGroups.js.map +1 -0
- package/build/graphql/syncPromptPartials.d.ts +32 -0
- package/build/graphql/syncPromptPartials.d.ts.map +1 -0
- package/build/graphql/syncPromptPartials.js +102 -0
- package/build/graphql/syncPromptPartials.js.map +1 -0
- package/build/graphql/syncPromptTemplates.d.ts +32 -0
- package/build/graphql/syncPromptTemplates.d.ts.map +1 -0
- package/build/graphql/syncPromptTemplates.js +102 -0
- package/build/graphql/syncPromptTemplates.js.map +1 -0
- package/build/graphql/syncPrompts.d.ts +32 -0
- package/build/graphql/syncPrompts.d.ts.map +1 -0
- package/build/graphql/syncPrompts.js +102 -0
- package/build/graphql/syncPrompts.js.map +1 -0
- package/build/helpers/index.d.ts +0 -1
- package/build/helpers/index.d.ts.map +1 -1
- package/build/helpers/index.js +0 -1
- package/build/helpers/index.js.map +1 -1
- package/build/tests/TranscendPromptManager.test.d.ts +2 -0
- package/build/tests/TranscendPromptManager.test.d.ts.map +1 -0
- package/build/tests/{TranscendAiPrompt.test.js → TranscendPromptManager.test.js} +25 -13
- package/build/tests/TranscendPromptManager.test.js.map +1 -0
- package/build/tsbuildinfo +1 -1
- package/package.json +3 -5
- package/build/ai/TranscendAiPrompt.d.ts +0 -59
- package/build/ai/TranscendAiPrompt.d.ts.map +0 -1
- package/build/ai/TranscendAiPrompt.js +0 -130
- package/build/ai/TranscendAiPrompt.js.map +0 -1
- package/build/ai/createHandlebarsWithHelpers.d.ts +0 -25
- package/build/ai/createHandlebarsWithHelpers.d.ts.map +0 -1
- package/build/ai/createHandlebarsWithHelpers.js +0 -125
- package/build/ai/createHandlebarsWithHelpers.js.map +0 -1
- package/build/helpers/getVariablesFromHandlebarsTemplate.d.ts +0 -10
- package/build/helpers/getVariablesFromHandlebarsTemplate.d.ts.map +0 -1
- package/build/helpers/getVariablesFromHandlebarsTemplate.js +0 -108
- package/build/helpers/getVariablesFromHandlebarsTemplate.js.map +0 -1
- package/build/tests/TranscendAiPrompt.test.d.ts +0 -2
- package/build/tests/TranscendAiPrompt.test.d.ts.map +0 -1
- package/build/tests/TranscendAiPrompt.test.js.map +0 -1
- package/build/tests/getVariablesFromHandlebars.test.d.ts +0 -2
- package/build/tests/getVariablesFromHandlebars.test.d.ts.map +0 -1
- package/build/tests/getVariablesFromHandlebars.test.js +0 -61
- package/build/tests/getVariablesFromHandlebars.test.js.map +0 -1
package/README.md
CHANGED
|
@@ -125,6 +125,7 @@
|
|
|
125
125
|
- [Authentication](#authentication-28)
|
|
126
126
|
- [Arguments](#arguments-28)
|
|
127
127
|
- [Usage](#usage-29)
|
|
128
|
+
- [Prompt Manager](#prompt-manager)
|
|
128
129
|
- [Proxy usage](#proxy-usage)
|
|
129
130
|
|
|
130
131
|
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
|
@@ -351,7 +352,11 @@ The API key permissions for this command vary based on the value to the `resourc
|
|
|
351
352
|
| cookies | Consent Manager Cookie definitions. | View Data Flows | false | [Consent Manager -> Cookies](https://app.transcend.io/consent-manager/cookies/approved) |
|
|
352
353
|
| consentManager | Consent Manager general settings, including domain list. | View Consent Manager | false | [Consent Manager -> Developer Settings](https://app.transcend.io/consent-manager/developer-settings) |
|
|
353
354
|
| assessments | The Transcend assessments | View Assessments | false | [Assessments -> Browse](https://app.transcend.io/assessments/browse) |
|
|
354
|
-
| assessmentTemplates | The Transcend assessment
|
|
355
|
+
| assessmentTemplates | The Transcend assessment templates | View Assessments | false | [Assessments -> Templates](https://app.transcend.io/assessments/templates) |
|
|
356
|
+
| prompts | The Transcend AI prompts | View Prompts | false | [Prompt Manager -> Browse](https://app.transcend.io/prompts/browse) |
|
|
357
|
+
| promptTemplates | The Transcend AI prompt templates | View Prompts | false | [Prompt Manager -> Templates](https://app.transcend.io/prompts/templates) |
|
|
358
|
+
| promptPartials | The Transcend AI prompt partials | View Prompts | false | [Prompt Manager -> Partials](https://app.transcend.io/prompts/partialss) |
|
|
359
|
+
| promptGroups | The Transcend AI prompt groups | View Prompts | false | [Prompt Manager -> Groups](https://app.transcend.io/prompts/groups) |
|
|
355
360
|
|
|
356
361
|
_Note: The scopes for tr-push are comprehensive of the scopes for tr-pull_
|
|
357
362
|
|
|
@@ -469,6 +474,12 @@ Pull in assessments and assessment templates (see [this example](./examples/asse
|
|
|
469
474
|
tr-pull --auth=$TRANSCEND_API_KEY --resources=assessment,assessmentTemplate
|
|
470
475
|
```
|
|
471
476
|
|
|
477
|
+
Pull in prompts, prompt templates, prompt partials and prompt groups (see [this example](./examples/prompts.yml)):
|
|
478
|
+
|
|
479
|
+
```sh
|
|
480
|
+
tr-pull --auth=$TRANSCEND_API_KEY --resources=prompts,promptTemplates,promptPartials,promptGroups
|
|
481
|
+
```
|
|
482
|
+
|
|
472
483
|
Pull everything:
|
|
473
484
|
|
|
474
485
|
```sh
|
|
@@ -522,7 +533,11 @@ The API key needs the following scopes when pushing the various resource types:
|
|
|
522
533
|
| cookies | Consent Manager Cookie definitions. | Manage Data Flows | false | [Consent Manager -> Cookies](https://app.transcend.io/consent-manager/cookies/approved) |
|
|
523
534
|
| consentManager | Consent Manager general settings, including domain list. | Manage Consent Manager Developer Settings | false | [Consent Manager -> Developer Settings](https://app.transcend.io/consent-manager/developer-settings) |
|
|
524
535
|
| assessments | The Transcend assessments | Manage Assessments | false | [Assessments -> Browse](https://app.transcend.io/assessments/browse) |
|
|
525
|
-
| assessmentTemplates | The Transcend assessment
|
|
536
|
+
| assessmentTemplates | The Transcend assessment templates | Manage Assessments | false | [Assessments -> Templates](https://app.transcend.io/assessments/templates) |
|
|
537
|
+
| prompts | The Transcend AI prompts | View Prompts | false | [Prompt Manager -> Browse](https://app.transcend.io/prompts/browse) |
|
|
538
|
+
| promptTemplates | The Transcend AI prompt templates | Manage Prompts | false | [Prompt Manager -> Templates](https://app.transcend.io/prompts/templates) |
|
|
539
|
+
| promptPartials | The Transcend AI prompt partials | Manage Prompts | false | [Prompt Manager -> Partials](https://app.transcend.io/prompts/partialss) |
|
|
540
|
+
| promptGroups | The Transcend AI prompt groups | Manage Prompts | false | [Prompt Manager -> Groups](https://app.transcend.io/prompts/groups) |
|
|
526
541
|
|
|
527
542
|
#### Arguments
|
|
528
543
|
|
|
@@ -1891,7 +1906,7 @@ to grab your encryption and signing keys.
|
|
|
1891
1906
|
Upload consent preferences to partition key `4d1c5daa-90b7-4d18-aa40-f86a43d2c726`
|
|
1892
1907
|
|
|
1893
1908
|
```sh
|
|
1894
|
-
yarn tr-upload-consent-preferences --base64EncryptionKey=$TRANSCEND_CONSENT_ENCRYPTION_KEY
|
|
1909
|
+
yarn tr-upload-consent-preferences --base64EncryptionKey=$TRANSCEND_CONSENT_ENCRYPTION_KEY --base64SigningKey=$TRANSCEND_CONSENT_SIGNING_KEY --partition=4d1c5daa-90b7-4d18-aa40-f86a43d2c726
|
|
1895
1910
|
```
|
|
1896
1911
|
|
|
1897
1912
|
Upload consent preferences to partition key `4d1c5daa-90b7-4d18-aa40-f86a43d2c726` from file `./consent.csv`
|
|
@@ -2285,6 +2300,91 @@ Configuring additional variables:
|
|
|
2285
2300
|
yarn tr-create-assessment --auth=$TRANSCEND_API_KEY --title="Test" --template="[AI Prompt] Product Manager Notes Parsing" --variables=description:"testt test"
|
|
2286
2301
|
```
|
|
2287
2302
|
|
|
2303
|
+
## Prompt Manager
|
|
2304
|
+
|
|
2305
|
+
If you are integrating Transcend's Prompt Manager into your code, it may look like:
|
|
2306
|
+
|
|
2307
|
+
```ts
|
|
2308
|
+
import * as t from 'io-ts';
|
|
2309
|
+
import { TranscendPromptManager } from '@transcend-io/cli';
|
|
2310
|
+
|
|
2311
|
+
/**
|
|
2312
|
+
* Example prompt integration
|
|
2313
|
+
*/
|
|
2314
|
+
export async function main(): Promise<void> {
|
|
2315
|
+
const promptManager = new TranscendPromptManager({
|
|
2316
|
+
// API key
|
|
2317
|
+
transcendApiKey: process.env.TRANSCEND_API_KEY,
|
|
2318
|
+
// Define the prompts that are stored in Transcend
|
|
2319
|
+
prompts: {
|
|
2320
|
+
test: {
|
|
2321
|
+
// identify by ID
|
|
2322
|
+
id: '30bcaa79-889a-4af3-842d-2e8ba443d36d',
|
|
2323
|
+
// no runtime variables
|
|
2324
|
+
paramCodec: t.type({}),
|
|
2325
|
+
// response is list of strings
|
|
2326
|
+
outputCodec: t.array(t.string),
|
|
2327
|
+
},
|
|
2328
|
+
json: {
|
|
2329
|
+
// identify by title
|
|
2330
|
+
title: 'test',
|
|
2331
|
+
// one runtime variable "test"
|
|
2332
|
+
paramCodec: t.type({ test: t.string }),
|
|
2333
|
+
// runtime is json object
|
|
2334
|
+
outputCodec: t.record(t.string, t.string),
|
|
2335
|
+
// response is stored in <json></json> atg
|
|
2336
|
+
extractFromTag: 'json',
|
|
2337
|
+
},
|
|
2338
|
+
predictProductLine: {
|
|
2339
|
+
// identify by title
|
|
2340
|
+
title: 'Predict Product Line',
|
|
2341
|
+
// runtime parameter for slack channel name
|
|
2342
|
+
paramCodec: t.type({
|
|
2343
|
+
slackChannelName: t.string,
|
|
2344
|
+
}),
|
|
2345
|
+
// response is specific JSON shape
|
|
2346
|
+
outputCodec: t.type({
|
|
2347
|
+
product: t.union([t.string, t.null]),
|
|
2348
|
+
clarification: t.union([t.string, t.null]),
|
|
2349
|
+
}),
|
|
2350
|
+
// response is stored in <json></json> atg
|
|
2351
|
+
extractFromTag: 'json',
|
|
2352
|
+
},
|
|
2353
|
+
},
|
|
2354
|
+
// Optional arguments
|
|
2355
|
+
// transcendUrl: 'https://api.us.transcend.io', // defaults to 'https://api.transcend.io'
|
|
2356
|
+
// requireApproval: false, // defaults to true
|
|
2357
|
+
// cacheDuration: 1000 * 60 * 60, // defaults to undefined, no cache
|
|
2358
|
+
// defaultVariables: { myVariable: 'this is custom', other: [{ name: 'custom' }] }, // defaults to {}
|
|
2359
|
+
// handlebarsOptions: { helpers, templates }, // defaults to {}
|
|
2360
|
+
});
|
|
2361
|
+
|
|
2362
|
+
// Fetch the prompt from Transcend and template any variables
|
|
2363
|
+
// in this case, we template the slack channel name in the LLM prompt
|
|
2364
|
+
const systemPrompt = await promptManager.compilePrompt('predictProductLine', {
|
|
2365
|
+
slackChannelName: channelName,
|
|
2366
|
+
});
|
|
2367
|
+
|
|
2368
|
+
// Pass the prompt into your LLM of choice
|
|
2369
|
+
const response = await openai.createCompletion([
|
|
2370
|
+
{
|
|
2371
|
+
role: 'system',
|
|
2372
|
+
content: systemPrompt,
|
|
2373
|
+
},
|
|
2374
|
+
{
|
|
2375
|
+
role: 'user',
|
|
2376
|
+
content: input,
|
|
2377
|
+
},
|
|
2378
|
+
]);
|
|
2379
|
+
|
|
2380
|
+
// Parsed response as JSON
|
|
2381
|
+
const parsedResponse = promptManager.parseAiResponse(
|
|
2382
|
+
'predictProductLine',
|
|
2383
|
+
response,
|
|
2384
|
+
);
|
|
2385
|
+
}
|
|
2386
|
+
```
|
|
2387
|
+
|
|
2288
2388
|
## Proxy usage
|
|
2289
2389
|
|
|
2290
2390
|
If you are trying to use the cli inside a corporate firewall and need to send traffic through a proxy, you can do so via the `http_proxy` environment variable or the `--httpProxy` flag, with a command like `yarn tr-pull --auth=$TRANSCEND_API_KEY --httpProxy="http://localhost:5051"`.
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import type { Handlebars } from '@transcend-io/handlebars-utils';
|
|
2
|
+
import { Secret } from '@transcend-io/secret-value';
|
|
3
|
+
import * as t from 'io-ts';
|
|
4
|
+
import { HandlebarsInput } from '@transcend-io/handlebars-utils';
|
|
5
|
+
import { TranscendPromptsAndVariables } from '../graphql/fetchPrompts';
|
|
6
|
+
import { GraphQLClient } from 'graphql-request';
|
|
7
|
+
/**
|
|
8
|
+
* An LLM Prompt definition
|
|
9
|
+
*/
|
|
10
|
+
export type TranscendPrompt<TInputParams extends t.Any, TOutputCodec extends t.Any> = ({
|
|
11
|
+
/** ID of the prompt */
|
|
12
|
+
id: string;
|
|
13
|
+
/** Title of the prompt */
|
|
14
|
+
title?: string;
|
|
15
|
+
} | {
|
|
16
|
+
/** ID of the prompt */
|
|
17
|
+
id?: string;
|
|
18
|
+
/** Title of the prompt */
|
|
19
|
+
title: string;
|
|
20
|
+
}) & {
|
|
21
|
+
/** Codec to validate runtime input shape */
|
|
22
|
+
paramCodec: TInputParams;
|
|
23
|
+
/** Codec to validate output response */
|
|
24
|
+
outputCodec: TOutputCodec;
|
|
25
|
+
/**
|
|
26
|
+
* If the output that needs to be parsed is returned within a tag
|
|
27
|
+
* e.g. <tag> or <json> - this is the name of the tag
|
|
28
|
+
*/
|
|
29
|
+
extractFromTag?: string;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Create a regex to extract data from a tag
|
|
33
|
+
*
|
|
34
|
+
* Input:
|
|
35
|
+
* "here is some data <tag>Data</tag>..."
|
|
36
|
+
*
|
|
37
|
+
* @param tagName - Name of tag
|
|
38
|
+
* @returns Data within the tag
|
|
39
|
+
*/
|
|
40
|
+
export declare function createRegexForTag(tagName: string): RegExp;
|
|
41
|
+
/**
|
|
42
|
+
* A class that is capable of loading and insert variables into prompts from
|
|
43
|
+
* Transcend's Prompt Manager
|
|
44
|
+
*/
|
|
45
|
+
export declare class TranscendPromptManager<TPromptNames extends string, TPrompts extends {
|
|
46
|
+
[k in TPromptNames]: TranscendPrompt<t.Any, t.Any>;
|
|
47
|
+
}> {
|
|
48
|
+
/** Prompt definitions */
|
|
49
|
+
prompts: TPrompts;
|
|
50
|
+
/** Prompt name -> content map, populated by call to Transcend API */
|
|
51
|
+
promptContentMap?: {
|
|
52
|
+
[k in TPromptNames]: string;
|
|
53
|
+
};
|
|
54
|
+
/** The GraphQL client that can be used to call Transcend */
|
|
55
|
+
graphQLClient: GraphQLClient;
|
|
56
|
+
/** The set of variables to expose in handlebars context specified at class initiation */
|
|
57
|
+
defaultVariables: {
|
|
58
|
+
[k in string]: unknown;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* The set of variables to expose in handlebars context,
|
|
62
|
+
* merges defaults with calculated variables from the inventory
|
|
63
|
+
*/
|
|
64
|
+
variables: {
|
|
65
|
+
[k in string]: unknown;
|
|
66
|
+
};
|
|
67
|
+
/** Handlebars compiler */
|
|
68
|
+
handlebars: typeof Handlebars;
|
|
69
|
+
/** The Transcend API key */
|
|
70
|
+
transcendApiKey: string | Secret<string>;
|
|
71
|
+
/** API of Transcend to call */
|
|
72
|
+
transcendUrl: string;
|
|
73
|
+
/** When true, throw an error if the prompt is not approved */
|
|
74
|
+
requireApproval: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* The cache duration in ms for how long prompts and associated metadata should be cached
|
|
77
|
+
* When undefined - prompts are cached indefinitely unless explicitly re-requested
|
|
78
|
+
* When 0, prompts and metadata are fetched every time (not recommended)
|
|
79
|
+
* Setting this to be an hour is a good rate that optimizes for performance and keeping up to date
|
|
80
|
+
*/
|
|
81
|
+
cacheDuration?: number;
|
|
82
|
+
/**
|
|
83
|
+
* The last time the metadata was fetched
|
|
84
|
+
*/
|
|
85
|
+
lastUpdatedAt?: Date;
|
|
86
|
+
/**
|
|
87
|
+
* Constructor
|
|
88
|
+
*
|
|
89
|
+
* @param options - Options
|
|
90
|
+
*/
|
|
91
|
+
constructor({ prompts, handlebarsOptions, transcendUrl, transcendApiKey, requireApproval, cacheDuration, defaultVariables, }: {
|
|
92
|
+
/** Prompt definitions to load */
|
|
93
|
+
prompts: TPrompts;
|
|
94
|
+
/** Options for configuring handlebars */
|
|
95
|
+
handlebarsOptions?: HandlebarsInput;
|
|
96
|
+
/** The Transcend API key */
|
|
97
|
+
transcendApiKey: string | Secret<string>;
|
|
98
|
+
/** API of Transcend to call */
|
|
99
|
+
transcendUrl?: string;
|
|
100
|
+
/** When true, throw an error if the prompt is not approved */
|
|
101
|
+
requireApproval?: boolean;
|
|
102
|
+
/** The set of variables to expose in handlebars context specified at class initiation */
|
|
103
|
+
defaultVariables?: {
|
|
104
|
+
[k in string]: unknown;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* The cache duration in ms for how long prompts and associated metadata should be cached
|
|
108
|
+
* When undefined - prompts are cached indefinitely unless explicitly re-requested
|
|
109
|
+
* When 0, prompts and metadata are fetched every time (not recommended)
|
|
110
|
+
* Setting this to be an hour is a good rate that optimizes for performance and keeping up to date
|
|
111
|
+
*/
|
|
112
|
+
cacheDuration?: number;
|
|
113
|
+
});
|
|
114
|
+
/**
|
|
115
|
+
* Fetch prompt metadata from Transcend and cache to the class definition
|
|
116
|
+
*
|
|
117
|
+
* @returns A function that can be used to call the prompt
|
|
118
|
+
*/
|
|
119
|
+
fetchPromptsAndMetadata(): Promise<TranscendPromptsAndVariables>;
|
|
120
|
+
/**
|
|
121
|
+
* Validate the shape of the response from AI
|
|
122
|
+
*
|
|
123
|
+
* @param promptName - Prompt to compile
|
|
124
|
+
* @param params - Runtime parameters
|
|
125
|
+
* @returns Parsed content
|
|
126
|
+
*/
|
|
127
|
+
compilePrompt<TPromptName extends TPromptNames>(promptName: TPromptName, params: t.TypeOf<TPrompts[TPromptName]['paramCodec']>): Promise<string>;
|
|
128
|
+
/**
|
|
129
|
+
* Validate the shape of the response from AI
|
|
130
|
+
*
|
|
131
|
+
* @param promptName - Prompt to parse
|
|
132
|
+
* @param response - AI response as string
|
|
133
|
+
* @returns Parsed content
|
|
134
|
+
*/
|
|
135
|
+
parseAiResponse<TPromptName extends TPromptNames>(promptName: TPromptName, response: string): t.TypeOf<TPrompts[TPromptName]['outputCodec']>;
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=TranscendPromptManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TranscendPromptManager.d.ts","sourceRoot":"","sources":["../../src/ai/TranscendPromptManager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,KAAK,CAAC,MAAM,OAAO,CAAC;AAG3B,OAAO,EACL,eAAe,EAEhB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,4BAA4B,EAE7B,MAAM,yBAAyB,CAAC;AACjC,OAAO,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
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.TranscendPromptManager = exports.createRegexForTag = void 0;
|
|
7
|
+
const type_utils_1 = require("@transcend-io/type-utils");
|
|
8
|
+
const constants_1 = require("../constants");
|
|
9
|
+
const graphql_1 = require("../graphql");
|
|
10
|
+
const handlebars_utils_1 = require("@transcend-io/handlebars-utils");
|
|
11
|
+
const fetchPrompts_1 = require("../graphql/fetchPrompts");
|
|
12
|
+
const keyBy_1 = __importDefault(require("lodash/keyBy"));
|
|
13
|
+
/**
|
|
14
|
+
* Create a regex to extract data from a tag
|
|
15
|
+
*
|
|
16
|
+
* Input:
|
|
17
|
+
* "here is some data <tag>Data</tag>..."
|
|
18
|
+
*
|
|
19
|
+
* @param tagName - Name of tag
|
|
20
|
+
* @returns Data within the tag
|
|
21
|
+
*/
|
|
22
|
+
function createRegexForTag(tagName) {
|
|
23
|
+
return new RegExp(`<${tagName}>([\\s\\S]+?)<\\/${tagName}>`);
|
|
24
|
+
}
|
|
25
|
+
exports.createRegexForTag = createRegexForTag;
|
|
26
|
+
/**
|
|
27
|
+
* A class that is capable of loading and insert variables into prompts from
|
|
28
|
+
* Transcend's Prompt Manager
|
|
29
|
+
*/
|
|
30
|
+
class TranscendPromptManager {
|
|
31
|
+
/**
|
|
32
|
+
* Constructor
|
|
33
|
+
*
|
|
34
|
+
* @param options - Options
|
|
35
|
+
*/
|
|
36
|
+
constructor({ prompts, handlebarsOptions, transcendUrl = constants_1.DEFAULT_TRANSCEND_API, transcendApiKey, requireApproval = true, cacheDuration, defaultVariables = {}, }) {
|
|
37
|
+
this.prompts = prompts;
|
|
38
|
+
this.transcendUrl = transcendUrl;
|
|
39
|
+
this.transcendApiKey = transcendApiKey;
|
|
40
|
+
this.variables = defaultVariables;
|
|
41
|
+
this.defaultVariables = defaultVariables;
|
|
42
|
+
this.graphQLClient = (0, graphql_1.buildTranscendGraphQLClient)(transcendUrl, typeof transcendApiKey === 'object'
|
|
43
|
+
? transcendApiKey.release()
|
|
44
|
+
: transcendApiKey);
|
|
45
|
+
this.requireApproval = requireApproval;
|
|
46
|
+
this.cacheDuration = cacheDuration;
|
|
47
|
+
this.handlebars = (0, handlebars_utils_1.createHandlebarsWithHelpers)(handlebarsOptions);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Fetch prompt metadata from Transcend and cache to the class definition
|
|
51
|
+
*
|
|
52
|
+
* @returns A function that can be used to call the prompt
|
|
53
|
+
*/
|
|
54
|
+
async fetchPromptsAndMetadata() {
|
|
55
|
+
// Determine what to fetch
|
|
56
|
+
const promptDefinitions = (0, type_utils_1.getValues)(this.prompts);
|
|
57
|
+
const promptIds = promptDefinitions
|
|
58
|
+
.map(({ id }) => id)
|
|
59
|
+
.filter((x) => !!x);
|
|
60
|
+
const promptTitles = promptDefinitions
|
|
61
|
+
.map(({ title }) => title)
|
|
62
|
+
.filter((x) => !!x);
|
|
63
|
+
// Fetch prompts and data
|
|
64
|
+
const response = await (0, fetchPrompts_1.fetchPromptsWithVariables)(this.graphQLClient, {
|
|
65
|
+
promptIds,
|
|
66
|
+
promptTitles,
|
|
67
|
+
});
|
|
68
|
+
// Lookup prompts by id/title
|
|
69
|
+
const promptByTitle = (0, keyBy_1.default)(response.prompts, 'title');
|
|
70
|
+
const promptById = (0, keyBy_1.default)(response.prompts, 'id');
|
|
71
|
+
// Update variables
|
|
72
|
+
this.variables = {
|
|
73
|
+
...response.calculatedVariables.reduce((acc, v) => Object.assign(acc, {
|
|
74
|
+
[v.name]: v.data ? JSON.parse(v.data) : v.data,
|
|
75
|
+
}), {}),
|
|
76
|
+
...this.defaultVariables,
|
|
77
|
+
};
|
|
78
|
+
// Create mapping from prompt to content
|
|
79
|
+
this.promptContentMap = (0, type_utils_1.apply)(this.prompts, ({ id, title }) => {
|
|
80
|
+
const result = id
|
|
81
|
+
? promptById[id]
|
|
82
|
+
: title
|
|
83
|
+
? promptByTitle[title]
|
|
84
|
+
: undefined;
|
|
85
|
+
if (!result) {
|
|
86
|
+
throw new Error(`Failed to find prompt with title: "${title}" and id: "${id}"`);
|
|
87
|
+
}
|
|
88
|
+
return result.content;
|
|
89
|
+
});
|
|
90
|
+
// For cache
|
|
91
|
+
this.lastUpdatedAt = new Date();
|
|
92
|
+
return response;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Validate the shape of the response from AI
|
|
96
|
+
*
|
|
97
|
+
* @param promptName - Prompt to compile
|
|
98
|
+
* @param params - Runtime parameters
|
|
99
|
+
* @returns Parsed content
|
|
100
|
+
*/
|
|
101
|
+
async compilePrompt(promptName, params) {
|
|
102
|
+
// Determine if prompts need to be fetched
|
|
103
|
+
if (
|
|
104
|
+
// never been fetched
|
|
105
|
+
!this.lastUpdatedAt ||
|
|
106
|
+
// fetch every run
|
|
107
|
+
this.cacheDuration === 0 ||
|
|
108
|
+
// If cache duration met
|
|
109
|
+
(this.cacheDuration &&
|
|
110
|
+
Date.now() - this.lastUpdatedAt.getTime() > this.cacheDuration)) {
|
|
111
|
+
await this.fetchPromptsAndMetadata();
|
|
112
|
+
}
|
|
113
|
+
// Lookup prompt
|
|
114
|
+
const { promptContentMap } = this;
|
|
115
|
+
if (!promptContentMap) {
|
|
116
|
+
throw new Error('Expected this.promptContentMap to be defined');
|
|
117
|
+
}
|
|
118
|
+
const promptTemplate = promptContentMap[promptName];
|
|
119
|
+
if (!promptContentMap) {
|
|
120
|
+
throw new Error(`Expected this.promptContentMap[${promptName}] to be defined`);
|
|
121
|
+
}
|
|
122
|
+
const promptInput = this.prompts[promptName];
|
|
123
|
+
if (!promptInput) {
|
|
124
|
+
throw new Error(`Expected this.prompts[${promptName}] to be defined`);
|
|
125
|
+
}
|
|
126
|
+
// Validate params
|
|
127
|
+
(0, type_utils_1.decodeCodec)(promptInput.paramCodec, params);
|
|
128
|
+
// Compile prompt and template
|
|
129
|
+
return this.handlebars.compile(promptTemplate)({
|
|
130
|
+
// template in currentDate by default
|
|
131
|
+
currentDate: new Date().toISOString(),
|
|
132
|
+
...this.variables,
|
|
133
|
+
...params,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Validate the shape of the response from AI
|
|
138
|
+
*
|
|
139
|
+
* @param promptName - Prompt to parse
|
|
140
|
+
* @param response - AI response as string
|
|
141
|
+
* @returns Parsed content
|
|
142
|
+
*/
|
|
143
|
+
parseAiResponse(promptName, response) {
|
|
144
|
+
// Look up prompt info
|
|
145
|
+
const promptInput = this.prompts[promptName];
|
|
146
|
+
if (!promptInput) {
|
|
147
|
+
throw new Error(`Expected this.prompts[${promptName}] to be defined`);
|
|
148
|
+
}
|
|
149
|
+
// Extract from tag if needed
|
|
150
|
+
const extracted = promptInput.extractFromTag
|
|
151
|
+
? (createRegexForTag(promptInput.extractFromTag).exec(response) ||
|
|
152
|
+
[])[1] || response
|
|
153
|
+
: response;
|
|
154
|
+
// Parse via codec
|
|
155
|
+
return (0, type_utils_1.decodeCodec)(promptInput.outputCodec, extracted);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
exports.TranscendPromptManager = TranscendPromptManager;
|
|
159
|
+
//# sourceMappingURL=TranscendPromptManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TranscendPromptManager.js","sourceRoot":"","sources":["../../src/ai/TranscendPromptManager.ts"],"names":[],"mappings":";;;;;;AAAA,yDAAyE;AAIzE,4CAAqD;AACrD,wCAAyD;AACzD,qEAGwC;AACxC,0DAGiC;AAEjC,yDAAiC;AAiCjC;;;;;;;;GAQG;AACH,SAAgB,iBAAiB,CAAC,OAAe;IAC/C,OAAO,IAAI,MAAM,CAAC,IAAI,OAAO,oBAAoB,OAAO,GAAG,CAAC,CAAC;AAC/D,CAA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ACjB,GAAG,MAAM;SACV,CAAC,CAAC;IACL,CAAC;IAED;;;;;;OAMG;IACH,eAAe,CACb,UAAuB,EACvB,QAAgB;QAEhB,sBAAsB;QACtB,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAC7C,IAAI,CAAC,WAAW,EAAE;YAChB,MAAM,IAAI,KAAK,CAAC,yBAAyB,UAAU,iBAAiB,CAAC,CAAC;SACvE;QAED,6BAA6B;QAC7B,MAAM,SAAS,GAAG,WAAW,CAAC,cAAc;YAC1C,CAAC,CAAC,CAAC,iBAAiB,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC;gBAC3D,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,QAAQ;YACtB,CAAC,CAAC,QAAQ,CAAC;QAEb,kBAAkB;QAClB,OAAO,IAAA,wBAAW,EAAC,WAAW,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;IACzD,CAAC;CACF;AA5OD,wDA4OC"}
|
package/build/ai/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export declare const json2Csv: any;
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './createHandlebarsWithHelpers';
|
|
2
|
+
export * from './TranscendPromptManager';
|
|
4
3
|
export * from './removeLinks';
|
|
5
4
|
export * from './filterNullishValuesFromObject';
|
|
6
5
|
export * from './getGitFilesThatChanged';
|
package/build/ai/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ai/index.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,QAAQ,KAAQ,CAAC;AAE9B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ai/index.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,QAAQ,KAAQ,CAAC;AAE9B,cAAc,0BAA0B,CAAC;AACzC,cAAc,eAAe,CAAC;AAC9B,cAAc,iCAAiC,CAAC;AAChD,cAAc,0BAA0B,CAAC"}
|
package/build/ai/index.js
CHANGED
|
@@ -17,8 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
exports.json2Csv = void 0;
|
|
18
18
|
const { parse } = require('json2csv');
|
|
19
19
|
exports.json2Csv = parse;
|
|
20
|
-
__exportStar(require("./
|
|
21
|
-
__exportStar(require("./createHandlebarsWithHelpers"), exports);
|
|
20
|
+
__exportStar(require("./TranscendPromptManager"), exports);
|
|
22
21
|
__exportStar(require("./removeLinks"), exports);
|
|
23
22
|
__exportStar(require("./filterNullishValuesFromObject"), exports);
|
|
24
23
|
__exportStar(require("./getGitFilesThatChanged"), exports);
|
package/build/ai/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ai/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAEzB,QAAA,QAAQ,GAAG,KAAK,CAAC;AAE9B,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ai/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAEzB,QAAA,QAAQ,GAAG,KAAK,CAAC;AAE9B,2DAAyC;AACzC,gDAA8B;AAC9B,kEAAgD;AAChD,2DAAyC"}
|
|
@@ -10,12 +10,11 @@ const logger_1 = require("./logger");
|
|
|
10
10
|
const constants_1 = require("./constants");
|
|
11
11
|
const fetchAssessmentTemplates_1 = require("./graphql/fetchAssessmentTemplates");
|
|
12
12
|
const graphql_1 = require("./graphql");
|
|
13
|
-
const
|
|
13
|
+
const handlebars_utils_1 = require("@transcend-io/handlebars-utils");
|
|
14
14
|
const bluebird_1 = require("bluebird");
|
|
15
15
|
const inquirer_1 = require("./helpers/inquirer");
|
|
16
16
|
const parseVariablesFromString_1 = require("./helpers/parseVariablesFromString");
|
|
17
17
|
const syncAssessments_1 = require("./graphql/syncAssessments");
|
|
18
|
-
const ai_1 = require("./ai");
|
|
19
18
|
/**
|
|
20
19
|
* Create a new assessment from an assessment template
|
|
21
20
|
*
|
|
@@ -80,7 +79,7 @@ async function main() {
|
|
|
80
79
|
// Parse out the variables
|
|
81
80
|
const vars = (0, parseVariablesFromString_1.parseVariablesFromString)(variables);
|
|
82
81
|
// Pull the variables out of the template
|
|
83
|
-
const schema = (0,
|
|
82
|
+
const schema = (0, handlebars_utils_1.getVariablesFromHandlebarsTemplate)(assessmentTemplate.content);
|
|
84
83
|
const results = {};
|
|
85
84
|
await (0, bluebird_1.mapSeries)(Object.entries(schema), async ([variable, type]) => {
|
|
86
85
|
// Format from cli option
|
|
@@ -141,7 +140,7 @@ async function main() {
|
|
|
141
140
|
}
|
|
142
141
|
});
|
|
143
142
|
// Create new assessment
|
|
144
|
-
const handlebars = (0,
|
|
143
|
+
const handlebars = (0, handlebars_utils_1.createHandlebarsWithHelpers)();
|
|
145
144
|
const content = handlebars
|
|
146
145
|
.compile(assessmentTemplate.content)(results)
|
|
147
146
|
// remove empty lines
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli-create-assessment.js","sourceRoot":"","sources":["../src/cli-create-assessment.ts"],"names":[],"mappings":";;;;;;AACA,gEAAiC;AACjC,oDAA4B;AAE5B,qCAAkC;AAClC,2CAAoD;AACpD,iFAAiF;AACjF,uCAAwD;AACxD,
|
|
1
|
+
{"version":3,"file":"cli-create-assessment.js","sourceRoot":"","sources":["../src/cli-create-assessment.ts"],"names":[],"mappings":";;;;;;AACA,gEAAiC;AACjC,oDAA4B;AAE5B,qCAAkC;AAClC,2CAAoD;AACpD,iFAAiF;AACjF,uCAAwD;AACxD,qEAGwC;AACxC,uCAAqC;AACrC,iDAI4B;AAC5B,iFAA8E;AAC9E,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