@razzium/piece-aimwork-backend 0.0.1
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/.eslintrc.json +33 -0
- package/README.md +7 -0
- package/package.json +7 -0
- package/project.json +45 -0
- package/src/index.ts +105 -0
- package/src/lib/actions/ask-assistant.ts +122 -0
- package/src/lib/actions/extract-structure-data.action.ts +146 -0
- package/src/lib/actions/generate-image.ts +116 -0
- package/src/lib/actions/send-prompt.ts +254 -0
- package/src/lib/actions/text-to-speech.ts +132 -0
- package/src/lib/actions/transcriptions.ts +70 -0
- package/src/lib/actions/translation.ts +54 -0
- package/src/lib/actions/vision-prompt.ts +151 -0
- package/src/lib/common/common.ts +215 -0
- package/tsconfig.json +19 -0
- package/tsconfig.lib.json +11 -0
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": [
|
|
3
|
+
"../../../../.eslintrc.base.json"
|
|
4
|
+
],
|
|
5
|
+
"ignorePatterns": [
|
|
6
|
+
"!**/*"
|
|
7
|
+
],
|
|
8
|
+
"overrides": [
|
|
9
|
+
{
|
|
10
|
+
"files": [
|
|
11
|
+
"*.ts",
|
|
12
|
+
"*.tsx",
|
|
13
|
+
"*.js",
|
|
14
|
+
"*.jsx"
|
|
15
|
+
],
|
|
16
|
+
"rules": {}
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"files": [
|
|
20
|
+
"*.ts",
|
|
21
|
+
"*.tsx"
|
|
22
|
+
],
|
|
23
|
+
"rules": {}
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"files": [
|
|
27
|
+
"*.js",
|
|
28
|
+
"*.jsx"
|
|
29
|
+
],
|
|
30
|
+
"rules": {}
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
}
|
package/README.md
ADDED
package/package.json
ADDED
package/project.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "pieces-aimw",
|
|
3
|
+
"$schema": "../../../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
+
"sourceRoot": "packages/pieces/custom/aimw/src",
|
|
5
|
+
"projectType": "library",
|
|
6
|
+
"release": {
|
|
7
|
+
"version": {
|
|
8
|
+
"generatorOptions": {
|
|
9
|
+
"packageRoot": "dist/{projectRoot}",
|
|
10
|
+
"currentVersionResolver": "git-tag"
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"tags": [],
|
|
15
|
+
"targets": {
|
|
16
|
+
"build": {
|
|
17
|
+
"executor": "@nx/js:tsc",
|
|
18
|
+
"outputs": [
|
|
19
|
+
"{options.outputPath}"
|
|
20
|
+
],
|
|
21
|
+
"options": {
|
|
22
|
+
"outputPath": "dist/packages/pieces/custom/aimw",
|
|
23
|
+
"tsConfig": "packages/pieces/custom/aimw/tsconfig.lib.json",
|
|
24
|
+
"packageJson": "packages/pieces/custom/aimw/package.json",
|
|
25
|
+
"main": "packages/pieces/custom/aimw/src/index.ts",
|
|
26
|
+
"assets": [
|
|
27
|
+
"packages/pieces/custom/aimw/*.md"
|
|
28
|
+
],
|
|
29
|
+
"buildableProjectDepsInPackageJsonType": "dependencies",
|
|
30
|
+
"updateBuildableProjectDepsInPackageJson": true
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"nx-release-publish": {
|
|
34
|
+
"options": {
|
|
35
|
+
"packageRoot": "dist/{projectRoot}"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"lint": {
|
|
39
|
+
"executor": "@nx/eslint:lint",
|
|
40
|
+
"outputs": [
|
|
41
|
+
"{options.outputFile}"
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AuthenticationType,
|
|
3
|
+
HttpMethod,
|
|
4
|
+
createCustomApiCallAction,
|
|
5
|
+
httpClient,
|
|
6
|
+
} from '@activepieces/pieces-common';
|
|
7
|
+
import { PieceAuth, createPiece } from '@activepieces/pieces-framework';
|
|
8
|
+
import { PieceCategory } from '@activepieces/shared';
|
|
9
|
+
import { askAssistant } from './lib/actions/ask-assistant';
|
|
10
|
+
import { generateImage } from './lib/actions/generate-image';
|
|
11
|
+
import { askOpenAI } from './lib/actions/send-prompt';
|
|
12
|
+
import { textToSpeech } from './lib/actions/text-to-speech';
|
|
13
|
+
import { transcribeAction } from './lib/actions/transcriptions';
|
|
14
|
+
import { translateAction } from './lib/actions/translation';
|
|
15
|
+
import { visionPrompt } from './lib/actions/vision-prompt';
|
|
16
|
+
import { baseUrl } from './lib/common/common';
|
|
17
|
+
import { extractStructuredDataAction } from './lib/actions/extract-structure-data.action';
|
|
18
|
+
|
|
19
|
+
export const AI_PROVIDERS_MAKRDOWN = {
|
|
20
|
+
aimw: `Follow these instructions to get your aimw API Key:
|
|
21
|
+
|
|
22
|
+
1. Go to your aimw platform.
|
|
23
|
+
2. Click on User (at bottom of left menu) Settings > Account > API Keys and click on 'Show'.
|
|
24
|
+
3. On 'API Key' section, click on "Create new secret key".
|
|
25
|
+
4. Show & Copy API Key (use shorcut).
|
|
26
|
+
`,
|
|
27
|
+
openai: `Follow these instructions to get your OpenAI API Key:
|
|
28
|
+
|
|
29
|
+
1. Visit the following website: https://platform.openai.com/account/api-keys.
|
|
30
|
+
2. Once on the website, locate and click on the option to obtain your OpenAI API Key.
|
|
31
|
+
|
|
32
|
+
It is strongly recommended that you add your credit card information to your OpenAI account and upgrade to the paid plan **before** generating the API Key. This will help you prevent 429 errors.
|
|
33
|
+
`,
|
|
34
|
+
anthropic: `Follow these instructions to get your Claude API Key:
|
|
35
|
+
|
|
36
|
+
1. Visit the following website: https://console.anthropic.com/settings/keys.
|
|
37
|
+
2. Once on the website, locate and click on the option to obtain your Claude API Key.
|
|
38
|
+
`,
|
|
39
|
+
replicate: `Follow these instructions to get your Replicate API Key:
|
|
40
|
+
|
|
41
|
+
1. Visit the following website: https://replicate.com/account/api-tokens.
|
|
42
|
+
2. Once on the website, locate and click on the option to obtain your Replicate API Key.
|
|
43
|
+
`,
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export const openaiAuth = PieceAuth.SecretText({
|
|
47
|
+
description: AI_PROVIDERS_MAKRDOWN.aimw,
|
|
48
|
+
displayName: 'API Key',
|
|
49
|
+
required: true,
|
|
50
|
+
validate: async (auth) => {
|
|
51
|
+
try {
|
|
52
|
+
await httpClient.sendRequest<{
|
|
53
|
+
data: { id: string }[];
|
|
54
|
+
}>({
|
|
55
|
+
url: `${baseUrl}/models`,
|
|
56
|
+
method: HttpMethod.GET,
|
|
57
|
+
authentication: {
|
|
58
|
+
type: AuthenticationType.BEARER_TOKEN,
|
|
59
|
+
token: auth.auth as string,
|
|
60
|
+
//token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImZjY2Y4NzQyLTUyZWItNDdmZS05YWNjLTFjYzUyZjc2ZDdkYiJ9.NSWnWMO0ERGRU3QT4are2u-fo7R1FJxb2byyIwInTj4",
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
return {
|
|
64
|
+
valid: true,
|
|
65
|
+
};
|
|
66
|
+
} catch (e) {
|
|
67
|
+
return {
|
|
68
|
+
valid: false,
|
|
69
|
+
error: 'Invalid API key',
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
export const openai = createPiece({
|
|
76
|
+
displayName: 'Aimw',
|
|
77
|
+
description: 'Use the many tools AIMW has to offer.',
|
|
78
|
+
minimumSupportedRelease: '0.36.1',
|
|
79
|
+
logoUrl: 'https://applyz-main-bucket.fra1.cdn.digitaloceanspaces.com/aimw/logo.png',
|
|
80
|
+
categories: [PieceCategory.ARTIFICIAL_INTELLIGENCE],
|
|
81
|
+
auth: openaiAuth,
|
|
82
|
+
actions: [
|
|
83
|
+
askOpenAI,
|
|
84
|
+
// askAssistant,
|
|
85
|
+
// generateImage,
|
|
86
|
+
// visionPrompt,
|
|
87
|
+
// textToSpeech,
|
|
88
|
+
// transcribeAction,
|
|
89
|
+
// translateAction,
|
|
90
|
+
// extractStructuredDataAction,
|
|
91
|
+
// createCustomApiCallAction({
|
|
92
|
+
// auth: openaiAuth,
|
|
93
|
+
// baseUrl: () => baseUrl,
|
|
94
|
+
// authMapping: async (auth) => {
|
|
95
|
+
// return {
|
|
96
|
+
// Authorization: `Bearer ${auth}`,
|
|
97
|
+
// };
|
|
98
|
+
// },
|
|
99
|
+
// }),
|
|
100
|
+
],
|
|
101
|
+
authors: [
|
|
102
|
+
'razzium',
|
|
103
|
+
],
|
|
104
|
+
triggers: [],
|
|
105
|
+
});
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createAction,
|
|
3
|
+
Property,
|
|
4
|
+
StoreScope,
|
|
5
|
+
} from '@activepieces/pieces-framework';
|
|
6
|
+
import OpenAI from 'openai';
|
|
7
|
+
import { openaiAuth } from '../..';
|
|
8
|
+
import { sleep } from '../common/common';
|
|
9
|
+
import { z } from 'zod';
|
|
10
|
+
import { propsValidation } from '@activepieces/pieces-common';
|
|
11
|
+
|
|
12
|
+
export const askAssistant = createAction({
|
|
13
|
+
auth: openaiAuth,
|
|
14
|
+
name: 'ask_assistant',
|
|
15
|
+
displayName: 'Ask Assistant',
|
|
16
|
+
description: 'Ask a GPT assistant anything you want!',
|
|
17
|
+
props: {
|
|
18
|
+
assistant: Property.Dropdown({
|
|
19
|
+
displayName: 'Assistant',
|
|
20
|
+
required: true,
|
|
21
|
+
description: 'The assistant which will generate the completion.',
|
|
22
|
+
refreshers: [],
|
|
23
|
+
options: async ({ auth }) => {
|
|
24
|
+
if (!auth) {
|
|
25
|
+
return {
|
|
26
|
+
disabled: true,
|
|
27
|
+
placeholder: 'Enter your API key first',
|
|
28
|
+
options: [],
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
const openai = new OpenAI({
|
|
33
|
+
apiKey: auth as string,
|
|
34
|
+
});
|
|
35
|
+
const assistants = await openai.beta.assistants.list();
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
disabled: false,
|
|
39
|
+
options: assistants.data.map((assistant: any) => {
|
|
40
|
+
return {
|
|
41
|
+
label: assistant.name,
|
|
42
|
+
value: assistant.id,
|
|
43
|
+
};
|
|
44
|
+
}),
|
|
45
|
+
};
|
|
46
|
+
} catch (error) {
|
|
47
|
+
return {
|
|
48
|
+
disabled: true,
|
|
49
|
+
options: [],
|
|
50
|
+
placeholder: "Couldn't load assistants, API key is invalid",
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
}),
|
|
55
|
+
prompt: Property.LongText({
|
|
56
|
+
displayName: 'Question',
|
|
57
|
+
required: true,
|
|
58
|
+
}),
|
|
59
|
+
memoryKey: Property.ShortText({
|
|
60
|
+
displayName: 'Memory Key',
|
|
61
|
+
description:
|
|
62
|
+
'A memory key that will keep the chat history shared across runs and flows. Keep it empty to leave your assistant without memory of previous messages.',
|
|
63
|
+
required: false,
|
|
64
|
+
}),
|
|
65
|
+
},
|
|
66
|
+
async run({ auth, propsValue, store }) {
|
|
67
|
+
await propsValidation.validateZod(propsValue, {
|
|
68
|
+
memoryKey: z.string().max(128).optional(),
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const openai = new OpenAI({
|
|
72
|
+
apiKey: auth,
|
|
73
|
+
});
|
|
74
|
+
const { assistant, prompt, memoryKey } = propsValue;
|
|
75
|
+
const runCheckDelay = 1000;
|
|
76
|
+
let response: any;
|
|
77
|
+
let thread: any;
|
|
78
|
+
|
|
79
|
+
if (memoryKey) {
|
|
80
|
+
// Get existing thread ID or create a new thread for this memory key
|
|
81
|
+
thread = await store.get(memoryKey, StoreScope.PROJECT);
|
|
82
|
+
if (!thread) {
|
|
83
|
+
thread = await openai.beta.threads.create();
|
|
84
|
+
|
|
85
|
+
store.put(memoryKey, thread, StoreScope.PROJECT);
|
|
86
|
+
}
|
|
87
|
+
} else {
|
|
88
|
+
thread = await openai.beta.threads.create();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const message = await openai.beta.threads.messages.create(thread.id, {
|
|
92
|
+
role: 'user',
|
|
93
|
+
content: prompt,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const run = await openai.beta.threads.runs.create(thread.id, {
|
|
97
|
+
assistant_id: assistant,
|
|
98
|
+
});
|
|
99
|
+
// Wait at least 400ms for inference to finish before checking to save requests
|
|
100
|
+
await sleep(400);
|
|
101
|
+
|
|
102
|
+
while (!response) {
|
|
103
|
+
const runCheck = await openai.beta.threads.runs.retrieve(
|
|
104
|
+
thread.id,
|
|
105
|
+
run.id
|
|
106
|
+
);
|
|
107
|
+
if (runCheck.status == 'completed') {
|
|
108
|
+
const messages = await openai.beta.threads.messages.list(thread.id);
|
|
109
|
+
// Return only messages that are newer than the user's latest message
|
|
110
|
+
response = messages.data.splice(
|
|
111
|
+
0,
|
|
112
|
+
messages.data.findIndex((m) => m.id == message.id)
|
|
113
|
+
);
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
await sleep(runCheckDelay);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return response;
|
|
121
|
+
},
|
|
122
|
+
});
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { openaiAuth } from '../../';
|
|
2
|
+
import { createAction, Property } from '@activepieces/pieces-framework';
|
|
3
|
+
import OpenAI from 'openai';
|
|
4
|
+
import { notLLMs } from '../common/common';
|
|
5
|
+
|
|
6
|
+
export const extractStructuredDataAction = createAction({
|
|
7
|
+
auth: openaiAuth,
|
|
8
|
+
name: 'extract-structured-data',
|
|
9
|
+
displayName: 'Extract Structured Data from Text',
|
|
10
|
+
description: 'Returns structured data from provided unstructured text.',
|
|
11
|
+
props: {
|
|
12
|
+
model: Property.Dropdown({
|
|
13
|
+
displayName: 'Model',
|
|
14
|
+
required: true,
|
|
15
|
+
refreshers: [],
|
|
16
|
+
defaultValue: 'gpt-3.5-turbo',
|
|
17
|
+
options: async ({ auth }) => {
|
|
18
|
+
if (!auth) {
|
|
19
|
+
return {
|
|
20
|
+
disabled: true,
|
|
21
|
+
placeholder: 'Enter your API key first',
|
|
22
|
+
options: [],
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
const openai = new OpenAI({
|
|
27
|
+
apiKey: auth as string,
|
|
28
|
+
});
|
|
29
|
+
const response = await openai.models.list();
|
|
30
|
+
// We need to get only LLM models
|
|
31
|
+
const models = response.data.filter((model) => !notLLMs.includes(model.id));
|
|
32
|
+
return {
|
|
33
|
+
disabled: false,
|
|
34
|
+
options: models.map((model) => {
|
|
35
|
+
return {
|
|
36
|
+
label: model.id,
|
|
37
|
+
value: model.id,
|
|
38
|
+
};
|
|
39
|
+
}),
|
|
40
|
+
};
|
|
41
|
+
} catch (error) {
|
|
42
|
+
return {
|
|
43
|
+
disabled: true,
|
|
44
|
+
options: [],
|
|
45
|
+
placeholder: "Couldn't load models, API key is invalid",
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
}),
|
|
50
|
+
text: Property.LongText({
|
|
51
|
+
displayName: 'Unstructured Text',
|
|
52
|
+
required: true,
|
|
53
|
+
}),
|
|
54
|
+
params: Property.Array({
|
|
55
|
+
displayName: 'Data Definition',
|
|
56
|
+
required: true,
|
|
57
|
+
properties: {
|
|
58
|
+
propName: Property.ShortText({
|
|
59
|
+
displayName: 'Name',
|
|
60
|
+
description:
|
|
61
|
+
'Provide the name of the value you want to extract from the unstructured text. The name should be unique and short. ',
|
|
62
|
+
required: true,
|
|
63
|
+
}),
|
|
64
|
+
propDescription: Property.LongText({
|
|
65
|
+
displayName: 'Description',
|
|
66
|
+
description:
|
|
67
|
+
'Brief description of the data, this hints for the AI on what to look for',
|
|
68
|
+
required: false,
|
|
69
|
+
}),
|
|
70
|
+
propDataType: Property.StaticDropdown({
|
|
71
|
+
displayName: 'Data Type',
|
|
72
|
+
description: 'Type of parameter.',
|
|
73
|
+
required: true,
|
|
74
|
+
defaultValue: 'string',
|
|
75
|
+
options: {
|
|
76
|
+
disabled: false,
|
|
77
|
+
options: [
|
|
78
|
+
{ label: 'Text', value: 'string' },
|
|
79
|
+
{ label: 'Number', value: 'number' },
|
|
80
|
+
{ label: 'Boolean', value: 'boolean' },
|
|
81
|
+
],
|
|
82
|
+
},
|
|
83
|
+
}),
|
|
84
|
+
propIsRequired: Property.Checkbox({
|
|
85
|
+
displayName: 'Fail if Not present?',
|
|
86
|
+
required: true,
|
|
87
|
+
defaultValue: false,
|
|
88
|
+
}),
|
|
89
|
+
},
|
|
90
|
+
}),
|
|
91
|
+
},
|
|
92
|
+
async run(context) {
|
|
93
|
+
const { model, text } = context.propsValue;
|
|
94
|
+
const paramInputArray = context.propsValue.params as ParamInput[];
|
|
95
|
+
const functionParams: Record<string, unknown> = {};
|
|
96
|
+
const requiredFunctionParams: string[] = [];
|
|
97
|
+
for (const param of paramInputArray) {
|
|
98
|
+
functionParams[param.propName] = {
|
|
99
|
+
type: param.propDataType,
|
|
100
|
+
description: param.propDescription ?? param.propName,
|
|
101
|
+
};
|
|
102
|
+
if (param.propIsRequired) {
|
|
103
|
+
requiredFunctionParams.push(param.propName);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const prompt = 'Extract the following data from the provided text'
|
|
107
|
+
const openai = new OpenAI({
|
|
108
|
+
apiKey: context.auth,
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const response = await openai.chat.completions.create({
|
|
112
|
+
model: model,
|
|
113
|
+
messages: [{ role: 'user', content: text }],
|
|
114
|
+
tools: [
|
|
115
|
+
{
|
|
116
|
+
type: 'function',
|
|
117
|
+
function: {
|
|
118
|
+
name: 'extract_structured_data',
|
|
119
|
+
description: prompt,
|
|
120
|
+
parameters: {
|
|
121
|
+
type: 'object',
|
|
122
|
+
properties: functionParams,
|
|
123
|
+
required: requiredFunctionParams,
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const toolCallsResponse = response.choices[0].message.tool_calls;
|
|
131
|
+
if (toolCallsResponse) {
|
|
132
|
+
return JSON.parse(toolCallsResponse[0].function.arguments);
|
|
133
|
+
} else {
|
|
134
|
+
throw new Error(JSON.stringify({
|
|
135
|
+
message: "OpenAI couldn't extract the fields from the above text."
|
|
136
|
+
}));
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
interface ParamInput {
|
|
142
|
+
propName: string;
|
|
143
|
+
propDescription: string;
|
|
144
|
+
propDataType: string;
|
|
145
|
+
propIsRequired: boolean;
|
|
146
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { createAction, Property } from '@activepieces/pieces-framework';
|
|
2
|
+
import OpenAI from 'openai';
|
|
3
|
+
import { openaiAuth } from '../..';
|
|
4
|
+
|
|
5
|
+
export const generateImage = createAction({
|
|
6
|
+
auth: openaiAuth,
|
|
7
|
+
name: 'generate_image',
|
|
8
|
+
displayName: 'Generate Image',
|
|
9
|
+
description: 'Generate an image using text-to-image models',
|
|
10
|
+
props: {
|
|
11
|
+
model: Property.Dropdown({
|
|
12
|
+
displayName: 'Model',
|
|
13
|
+
required: true,
|
|
14
|
+
description: 'The model which will generate the image.',
|
|
15
|
+
defaultValue: 'dall-e-3',
|
|
16
|
+
refreshers: [],
|
|
17
|
+
options: async () => {
|
|
18
|
+
return {
|
|
19
|
+
options: [
|
|
20
|
+
{
|
|
21
|
+
label: 'dall-e-3',
|
|
22
|
+
value: 'dall-e-3',
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
label: 'dall-e-2',
|
|
26
|
+
value: 'dall-e-2',
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
}),
|
|
32
|
+
prompt: Property.LongText({
|
|
33
|
+
displayName: 'Prompt',
|
|
34
|
+
required: true,
|
|
35
|
+
}),
|
|
36
|
+
resolution: Property.Dropdown({
|
|
37
|
+
displayName: 'Resolution',
|
|
38
|
+
description: 'The resolution to generate the image in.',
|
|
39
|
+
required: false,
|
|
40
|
+
refreshers: ['model'],
|
|
41
|
+
defaultValue: '1024x1024',
|
|
42
|
+
options: async ({ model }) => {
|
|
43
|
+
let options = [
|
|
44
|
+
{
|
|
45
|
+
label: '1024x1024',
|
|
46
|
+
value: '1024x1024',
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
label: '512x512',
|
|
50
|
+
value: '512x512',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
label: '256x256',
|
|
54
|
+
value: '256x256',
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
if (model == 'dall-e-3')
|
|
58
|
+
options = [
|
|
59
|
+
{
|
|
60
|
+
label: '1024x1024',
|
|
61
|
+
value: '1024x1024',
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
label: '1024x1792',
|
|
65
|
+
value: '1024x1792',
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
label: '1792x1024',
|
|
69
|
+
value: '1792x1024',
|
|
70
|
+
},
|
|
71
|
+
];
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
options: options,
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
}),
|
|
78
|
+
quality: Property.Dropdown({
|
|
79
|
+
displayName: 'Quality',
|
|
80
|
+
required: false,
|
|
81
|
+
description: 'Standard is faster, HD has better details.',
|
|
82
|
+
defaultValue: 'standard',
|
|
83
|
+
refreshers: [],
|
|
84
|
+
options: async () => {
|
|
85
|
+
return {
|
|
86
|
+
options: [
|
|
87
|
+
{
|
|
88
|
+
label: 'standard',
|
|
89
|
+
value: 'standard',
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
label: 'hd',
|
|
93
|
+
value: 'hd',
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
};
|
|
97
|
+
},
|
|
98
|
+
}),
|
|
99
|
+
},
|
|
100
|
+
async run({ auth, propsValue }) {
|
|
101
|
+
const openai = new OpenAI({
|
|
102
|
+
apiKey: auth,
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
const { quality, resolution, model, prompt } = propsValue;
|
|
106
|
+
|
|
107
|
+
const image = await openai.images.generate({
|
|
108
|
+
model: model,
|
|
109
|
+
prompt: prompt,
|
|
110
|
+
quality: quality as any,
|
|
111
|
+
size: resolution as any,
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
return image;
|
|
115
|
+
},
|
|
116
|
+
});
|