@directus-labs/ai-image-generation-operation
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -1,1 +0,37 @@ | ||
import{request as e,log as a}from"directus:api";var r={id:"directus-labs-ai-image-generation",handler:async({apiKey:r,prompt:t,quality:i,size:s})=>{try{const{size:a}=[{label:"square",size:"1024x1024"},{label:"portrait",size:"1024x1792"},{label:"landscape",size:"1792x1024"}].find((e=>e.label==s)),o=await e("https://api.openai.com/v1/images/generations",{method:"POST",headers:{Authorization:`Bearer ${r}`,"Content-Type":"application/json"},body:JSON.stringify({model:"dall-e-3",n:1,prompt:t,quality:i,size:a})});if(200!=o.status)throw new Error("An error occurred when accessing OpenAI");return o.data.data[0].url}catch(e){throw a(e.message),new Error(e.message)}}};export{r as default}; | ||
import { request, log } from 'directus:api'; | ||
var api = { | ||
id: 'directus-labs-ai-image-generation', | ||
handler: async ({ apiKey, prompt, quality, size }) => { | ||
try { | ||
const { size: dimensions } = [ | ||
{ label: 'square', size: '1024x1024' }, | ||
{ label: 'portrait', size: '1024x1792' }, | ||
{ label: 'landscape', size: '1792x1024' }, | ||
].find(d => d.label == size); | ||
const response = await request('https://api.openai.com/v1/images/generations', { | ||
method: 'POST', | ||
headers: { | ||
Authorization: `Bearer ${apiKey}`, | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
model: 'dall-e-3', | ||
n: 1, | ||
prompt, | ||
quality, | ||
size: dimensions | ||
}) | ||
}); | ||
if(response.status != 200) throw new Error('An error occurred when accessing OpenAI') | ||
return response.data.data[0].url | ||
} catch(error) { | ||
log(error.message); | ||
throw new Error(error.message) | ||
} | ||
}, | ||
}; | ||
export { api as default }; |
@@ -1,1 +0,95 @@ | ||
var e={id:"directus-labs-ai-image-generation",name:"AI Image Generation",icon:"draw",description:"Use Open AI's Image Generation API to create new images based on user prompts.",overview:({prompt:e,quality:t,size:a})=>[{label:"Prompt",text:e},{label:"Quality",text:t},{label:"Size",text:a}],options:[{field:"apiKey",name:"OpenAI API Key",type:"string",required:!0,meta:{width:"full",interface:"input"}},{field:"prompt",name:"Prompt",type:"text",required:!0,meta:{width:"full",interface:"textarea"}},{field:"quality",name:"Quality",type:"string",required:!0,meta:{width:"half",interface:"select-dropdown",options:{choices:[{text:"Standard",value:"standard"},{text:"High",value:"hd"}]}}},{field:"size",name:"Size",type:"string",required:!0,meta:{width:"half",interface:"select-dropdown",options:{choices:[{text:"Square",value:"square"},{text:"Portrait",value:"portrait"},{text:"Landscape",value:"landscape"}]}}}]};export{e as default}; | ||
var app = { | ||
id: 'directus-labs-ai-image-generation', | ||
name: 'AI Image Generation', | ||
icon: 'draw', | ||
description: 'Use Open AI\'s Image Generation API to create new images based on user prompts.', | ||
overview: ({ prompt, quality, size }) => [ | ||
{ | ||
label: 'Prompt', | ||
text: prompt, | ||
}, | ||
{ | ||
label: 'Quality', | ||
text: quality, | ||
}, | ||
{ | ||
label: 'Size', | ||
text: size, | ||
}, | ||
], | ||
options: [ | ||
{ | ||
field: 'apiKey', | ||
name: 'OpenAI API Key', | ||
type: 'string', | ||
required: true, | ||
meta: { | ||
width: 'full', | ||
interface: 'input', | ||
options: { | ||
masked: true, | ||
}, | ||
}, | ||
}, | ||
{ | ||
field: 'prompt', | ||
name: 'Prompt', | ||
type: 'text', | ||
required: true, | ||
meta: { | ||
width: 'full', | ||
interface: 'textarea', | ||
}, | ||
}, | ||
{ | ||
field: 'quality', | ||
name: 'Quality', | ||
type: 'string', | ||
required: true, | ||
meta: { | ||
width: 'half', | ||
interface: 'select-dropdown', | ||
options: { | ||
choices: [ | ||
{ | ||
text: 'Standard', | ||
value: 'standard' | ||
}, | ||
{ | ||
text: 'High', | ||
value: 'hd' | ||
}, | ||
] | ||
} | ||
} | ||
}, | ||
{ | ||
field: 'size', | ||
name: 'Size', | ||
type: 'string', | ||
required: true, | ||
meta: { | ||
width: 'half', | ||
interface: 'select-dropdown', | ||
options: { | ||
choices: [ | ||
{ | ||
text: 'Square', | ||
value: 'square' | ||
}, | ||
{ | ||
text: 'Portrait', | ||
value: 'portrait' | ||
}, | ||
{ | ||
text: 'Landscape', | ||
value: 'landscape' | ||
}, | ||
] | ||
} | ||
} | ||
}, | ||
], | ||
}; | ||
export { app as default }; |
@@ -5,3 +5,3 @@ { | ||
"icon": "extension", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"license": "MIT", | ||
@@ -8,0 +8,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
5036
127
0