@activepieces/pieces-common
Advanced tools
Comparing version 0.2.20 to 0.2.21
{ | ||
"name": "@activepieces/pieces-common", | ||
"version": "0.2.20", | ||
"version": "0.2.21", | ||
"type": "commonjs", | ||
@@ -12,5 +12,6 @@ "dependencies": { | ||
"nanoid": "3.3.6", | ||
"openai": "4.47.1", | ||
"openai": "4.67.1", | ||
"replicate": "0.34.1", | ||
"semver": "7.6.0", | ||
"@activepieces/pieces-framework": "0.7.34", | ||
"@activepieces/pieces-framework": "0.7.35", | ||
"@activepieces/shared": "0.10.117", | ||
@@ -17,0 +18,0 @@ "tslib": "2.6.2" |
@@ -14,4 +14,4 @@ import { ServerContext } from '@activepieces/pieces-framework'; | ||
model: string; | ||
quality: string; | ||
size: string; | ||
size?: string; | ||
advancedOptions?: Record<string, unknown>; | ||
}; | ||
@@ -23,3 +23,3 @@ export type AIImageCompletion = { | ||
text: (params: AIChatCompletionsCreateParams) => Promise<AIChatCompletion>; | ||
function: (params: AIChatCompletionsCreateParams & { | ||
function?: (params: AIChatCompletionsCreateParams & { | ||
functions: AIFunctionDefinition[]; | ||
@@ -38,3 +38,2 @@ }) => Promise<AIChatCompletion & { | ||
export type AIChatCompletion = { | ||
id: string; | ||
choices: AIChatMessage[]; | ||
@@ -41,0 +40,0 @@ usage?: AIChatCompletionUsage; |
@@ -20,2 +20,3 @@ "use strict"; | ||
} | ||
const functionCalling = impl.chat.function; | ||
return { | ||
@@ -38,6 +39,6 @@ provider, | ||
}), | ||
function: (params) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
function: functionCalling ? (params) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
var _c; | ||
try { | ||
const response = yield impl.chat.function(params); | ||
const response = yield functionCalling(params); | ||
return response; | ||
@@ -51,3 +52,3 @@ } | ||
} | ||
}), | ||
}) : undefined, | ||
}, | ||
@@ -54,0 +55,0 @@ }; |
@@ -11,10 +11,5 @@ "use strict"; | ||
baseURL: proxyUrl, | ||
defaultHeaders: { | ||
'X-AP-TOTAL-USAGE-BODY-PATH': 'usage.output_tokens+usage.input_tokens', | ||
Authorization: `Bearer ${engineToken}`, | ||
}, | ||
}); | ||
return { | ||
provider: 'ANTHROPIC', | ||
image: undefined, | ||
chat: { | ||
@@ -47,3 +42,2 @@ text: (params) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
created: new Date().getTime(), | ||
id: completion.id, | ||
model: completion.model, | ||
@@ -97,3 +91,2 @@ usage: { | ||
} : null, | ||
id: completion.id, | ||
model: completion.model, | ||
@@ -100,0 +93,0 @@ created: new Date().getTime(), |
@@ -5,2 +5,3 @@ import { Static } from '@sinclair/typebox'; | ||
anthropic: string; | ||
replicate: string; | ||
}; | ||
@@ -12,7 +13,21 @@ export declare const AI_PROVIDERS: ({ | ||
value: "openai"; | ||
models: { | ||
models: ({ | ||
__tag: import("./utils").ModelType; | ||
label: string; | ||
value: string; | ||
types: string[]; | ||
}[]; | ||
supported: ("function" | "text" | "image")[]; | ||
mapper: (mapper: import("./utils").ImageModelMapper | import("./utils").ChatModelMapper) => { | ||
mapper: import("./utils").ImageModelMapper | import("./utils").ChatModelMapper; | ||
__tag: import("./utils").ModelType.IMAGE | import("./utils").ModelType.CHAT; | ||
label: string; | ||
value: string; | ||
supported: ("function" | "text" | "image")[]; | ||
}; | ||
} | { | ||
mapper: import("./utils").ImageModelMapper | import("./utils").ChatModelMapper; | ||
__tag: import("./utils").ModelType.IMAGE | import("./utils").ModelType.CHAT; | ||
label: string; | ||
value: string; | ||
supported: ("function" | "text" | "image")[]; | ||
})[]; | ||
auth: import("./utils").AuthHeader; | ||
@@ -27,5 +42,13 @@ factory: import("..").AIFactory; | ||
models: { | ||
__tag: import("./utils").ModelType; | ||
label: string; | ||
value: string; | ||
types: string[]; | ||
supported: ("function" | "text" | "image")[]; | ||
mapper: (mapper: import("./utils").ImageModelMapper | import("./utils").ChatModelMapper) => { | ||
mapper: import("./utils").ImageModelMapper | import("./utils").ChatModelMapper; | ||
__tag: import("./utils").ModelType.IMAGE | import("./utils").ModelType.CHAT; | ||
label: string; | ||
value: string; | ||
supported: ("function" | "text" | "image")[]; | ||
}; | ||
}[]; | ||
@@ -35,10 +58,26 @@ auth: import("./utils").AuthHeader; | ||
instructionsMarkdown: string; | ||
} | { | ||
logoUrl: string; | ||
defaultBaseUrl: string; | ||
label: "Replicate"; | ||
value: "replicate"; | ||
models: { | ||
mapper: import("./utils").ImageModelMapper | import("./utils").ChatModelMapper; | ||
__tag: import("./utils").ModelType.IMAGE | import("./utils").ModelType.CHAT; | ||
label: string; | ||
value: string; | ||
supported: ("function" | "text" | "image")[]; | ||
}[]; | ||
auth: import("./utils").AuthHeader; | ||
factory: import("..").AIFactory; | ||
instructionsMarkdown: string; | ||
})[]; | ||
export declare const aiProps: (type: 'text' | 'image') => { | ||
provider: import("@activepieces/pieces-framework").DropdownProperty<"openai" | "anthropic", true>; | ||
export declare const aiProps: (supported: 'text' | 'image' | 'function') => { | ||
provider: import("@activepieces/pieces-framework").DropdownProperty<"replicate" | "openai" | "anthropic", true>; | ||
model: import("@activepieces/pieces-framework").DropdownProperty<string, true>; | ||
advancedOptions: import("@activepieces/pieces-framework").DynamicProperties<false>; | ||
}; | ||
export type AiProviderMetadata = (typeof AI_PROVIDERS)[number]; | ||
export declare const AiProvider: import("@sinclair/typebox").TUnion<import("@sinclair/typebox").TLiteral<"openai" | "anthropic">[]>; | ||
export declare const AiProvider: import("@sinclair/typebox").TUnion<import("@sinclair/typebox").TLiteral<"replicate" | "openai" | "anthropic">[]>; | ||
export type AiProvider = Static<typeof AiProvider>; | ||
export * from './utils'; |
@@ -5,9 +5,10 @@ "use strict"; | ||
const tslib_1 = require("tslib"); | ||
const pieces_framework_1 = require("@activepieces/pieces-framework"); | ||
const shared_1 = require("@activepieces/shared"); | ||
const typebox_1 = require("@sinclair/typebox"); | ||
const http_1 = require("../../http"); | ||
const anthropic_1 = require("./anthropic"); | ||
const openai_1 = require("./openai"); | ||
const replicate_1 = require("./replicate"); | ||
const utils_1 = require("./utils"); | ||
const pieces_framework_1 = require("@activepieces/pieces-framework"); | ||
const shared_1 = require("@activepieces/shared"); | ||
const http_1 = require("../../http"); | ||
exports.AI_PROVIDERS_MAKRDOWN = { | ||
@@ -26,2 +27,7 @@ openai: `Follow these instructions to get your OpenAI API Key: | ||
`, | ||
replicate: `Follow these instructions to get your Replicate API Key: | ||
1. Visit the following website: https://replicate.com/account/api-tokens. | ||
2. Once on the website, locate and click on the option to obtain your Replicate API Key. | ||
`, | ||
}; | ||
@@ -34,10 +40,3 @@ exports.AI_PROVIDERS = [ | ||
value: 'openai', | ||
models: [ | ||
{ label: 'gpt-4o', value: 'gpt-4o', types: ['text'] }, | ||
{ label: 'gpt-4o-mini', value: 'gpt-4o-mini', types: ['text'] }, | ||
{ label: 'gpt-4-turbo', value: 'gpt-4-turbo', types: ['text'] }, | ||
{ label: 'gpt-3.5-turbo', value: 'gpt-3.5-turbo', types: ['text'] }, | ||
{ label: 'dall-e-3', value: 'dall-e-3', types: ['image'] }, | ||
{ label: 'dall-e-2', value: 'dall-e-2', types: ['image'] }, | ||
], | ||
models: openai_1.openaiModels, | ||
auth: (0, utils_1.authHeader)({ bearer: true }), | ||
@@ -53,22 +52,6 @@ factory: openai_1.openai, | ||
models: [ | ||
{ | ||
label: 'claude-3-5-sonnet', | ||
value: 'claude-3-5-sonnet-20240620', | ||
types: ['text'], | ||
}, | ||
{ | ||
label: 'claude-3-opus', | ||
value: 'claude-3-opus-20240229', | ||
types: ['text'], | ||
}, | ||
{ | ||
label: 'claude-3-sonnet', | ||
value: 'claude-3-sonnet-20240229', | ||
types: ['text'], | ||
}, | ||
{ | ||
label: 'claude-3-haiku', | ||
value: 'claude-3-haiku-20240307', | ||
types: ['text'], | ||
}, | ||
(0, utils_1.model)({ label: 'claude-3-5-sonnet', value: 'claude-3-5-sonnet-20240620', supported: ['text', 'function'] }), | ||
(0, utils_1.model)({ label: 'claude-3-opus', value: 'claude-3-opus-20240229', supported: ['text', 'function'] }), | ||
(0, utils_1.model)({ label: 'claude-3-sonnet', value: 'claude-3-sonnet-20240229', supported: ['text', 'function'] }), | ||
(0, utils_1.model)({ label: 'claude-3-haiku', value: 'claude-3-haiku-20240307', supported: ['text', 'function'] }), | ||
], | ||
@@ -79,4 +62,14 @@ auth: (0, utils_1.authHeader)({ name: 'x-api-key', bearer: false }), | ||
}, | ||
{ | ||
logoUrl: 'https://cdn.activepieces.com/pieces/replicate.png', | ||
defaultBaseUrl: 'https://api.replicate.com', | ||
label: 'Replicate', | ||
value: 'replicate', | ||
models: replicate_1.replicateModels, | ||
auth: (0, utils_1.authHeader)({ bearer: true }), | ||
factory: replicate_1.replicate, | ||
instructionsMarkdown: exports.AI_PROVIDERS_MAKRDOWN.replicate, | ||
} | ||
]; | ||
const aiProps = (type) => ({ | ||
const aiProps = (supported) => ({ | ||
provider: pieces_framework_1.Property.Dropdown({ | ||
@@ -103,11 +96,11 @@ displayName: 'Provider', | ||
const providerMetadata = exports.AI_PROVIDERS.find((meta) => meta.value === p.provider && | ||
meta.models.some((m) => m.types.includes(type))); | ||
meta.models.some((m) => m.supported.includes(supported))); | ||
if ((0, shared_1.isNil)(providerMetadata)) { | ||
return []; | ||
} | ||
return { | ||
value: providerMetadata.value, | ||
label: providerMetadata.label, | ||
models: providerMetadata.models, | ||
}; | ||
return [{ | ||
value: providerMetadata.value, | ||
label: providerMetadata.label, | ||
models: providerMetadata.models, | ||
}]; | ||
}); | ||
@@ -134,3 +127,3 @@ return { | ||
} | ||
const models = (_b = exports.AI_PROVIDERS.find((p) => p.value === provider)) === null || _b === void 0 ? void 0 : _b.models.filter((m) => m.types.includes(type)); | ||
const models = (_b = exports.AI_PROVIDERS.find((p) => p.value === provider)) === null || _b === void 0 ? void 0 : _b.models.filter((m) => m.supported.includes(supported)); | ||
return { | ||
@@ -142,2 +135,15 @@ disabled: (0, shared_1.isNil)(models), | ||
}), | ||
advancedOptions: pieces_framework_1.Property.DynamicProperties({ | ||
displayName: 'Advanced Options', | ||
required: false, | ||
refreshers: ['provider', 'model'], | ||
props: (_c) => tslib_1.__awaiter(void 0, [_c], void 0, function* ({ model, provider }) { | ||
var _d, _e; | ||
const modelMetadata = (_d = exports.AI_PROVIDERS.find((p) => p.value === provider)) === null || _d === void 0 ? void 0 : _d.models.find((m) => m.value === model); | ||
if ((0, shared_1.isNil)(modelMetadata) || !(0, utils_1.hasMapper)(modelMetadata)) { | ||
return {}; | ||
} | ||
return (_e = modelMetadata.mapper.advancedOptions) !== null && _e !== void 0 ? _e : {}; | ||
}), | ||
}), | ||
}); | ||
@@ -144,0 +150,0 @@ exports.aiProps = aiProps; |
import { AIFactory } from '../..'; | ||
import { ModelType } from '../utils'; | ||
export declare const openai: AIFactory; | ||
export declare const openaiModels: ({ | ||
__tag: ModelType; | ||
label: string; | ||
value: string; | ||
supported: ("function" | "text" | "image")[]; | ||
mapper: (mapper: import("../utils").ImageModelMapper | import("../utils").ChatModelMapper) => { | ||
mapper: import("../utils").ImageModelMapper | import("../utils").ChatModelMapper; | ||
__tag: ModelType.IMAGE | ModelType.CHAT; | ||
label: string; | ||
value: string; | ||
supported: ("function" | "text" | "image")[]; | ||
}; | ||
} | { | ||
mapper: import("../utils").ImageModelMapper | import("../utils").ChatModelMapper; | ||
__tag: ModelType.IMAGE | ModelType.CHAT; | ||
label: string; | ||
value: string; | ||
supported: ("function" | "text" | "image")[]; | ||
})[]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.openai = void 0; | ||
exports.openaiModels = exports.openai = void 0; | ||
const tslib_1 = require("tslib"); | ||
const __1 = require("../.."); | ||
const shared_1 = require("@activepieces/shared"); | ||
const openai_1 = tslib_1.__importDefault(require("openai")); | ||
const __1 = require("../.."); | ||
const utils_1 = require("../utils"); | ||
const pieces_framework_1 = require("@activepieces/pieces-framework"); | ||
const openai = ({ proxyUrl, engineToken }) => { | ||
@@ -12,5 +15,2 @@ const openaiApiVersion = 'v1'; | ||
baseURL: `${proxyUrl}/${openaiApiVersion}`, | ||
defaultHeaders: { | ||
'X-AP-TOTAL-USAGE-BODY-PATH': 'usage.total_tokens', | ||
}, | ||
}); | ||
@@ -21,11 +21,6 @@ return { | ||
generate: (params) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const response = yield sdk.images.generate({ | ||
model: params.model, | ||
prompt: params.prompt, | ||
quality: params.quality, | ||
size: params.size, | ||
response_format: 'b64_json', | ||
}); | ||
const imageBase64 = response.data[0].b64_json; | ||
return imageBase64 ? { image: imageBase64 } : null; | ||
const mapper = findImageMapper(params.model); | ||
const input = yield mapper.encodeInput(params); | ||
const response = yield sdk.images.generate(input); | ||
return mapper.decodeOutput(response); | ||
}), | ||
@@ -55,3 +50,2 @@ }, | ||
created: completion.created, | ||
id: completion.id, | ||
model: completion.model, | ||
@@ -111,3 +105,2 @@ usage: completion.usage && { | ||
created: completion.created, | ||
id: completion.id, | ||
model: completion.model, | ||
@@ -125,2 +118,53 @@ usage: completion.usage && { | ||
exports.openai = openai; | ||
const findImageMapper = (model) => { | ||
var _a; | ||
const mapper = (_a = exports.openaiModels.find(m => m.value === model)) === null || _a === void 0 ? void 0 : _a.mapper; | ||
if ((0, shared_1.isNil)(mapper) || !("__tag" in mapper) || mapper.__tag !== utils_1.ModelType.IMAGE) { | ||
throw new Error(`OpenAI image model ${model} not found`); | ||
} | ||
return mapper; | ||
}; | ||
const openaiImageMapper = (0, utils_1.imageMapper)({ | ||
encodeInput: (params) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
var _a; | ||
return { | ||
model: params.model, | ||
prompt: params.prompt, | ||
quality: (_a = params.advancedOptions) === null || _a === void 0 ? void 0 : _a['quality'], | ||
size: params.size, | ||
response_format: 'b64_json', | ||
}; | ||
}), | ||
decodeOutput: (result) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const response = result; | ||
const imageBase64 = response.data[0].b64_json; | ||
return imageBase64 ? { image: imageBase64 } : null; | ||
}), | ||
advancedOptions: { | ||
quality: pieces_framework_1.Property.StaticDropdown({ | ||
options: { | ||
options: [ | ||
{ label: 'Standard', value: 'standard' }, | ||
{ label: 'HD', value: 'hd' }, | ||
], | ||
disabled: false, | ||
placeholder: 'Select Image Quality', | ||
}, | ||
defaultValue: 'standard', | ||
description: 'Standard images are less detailed and faster to generate, while HD images are more detailed but slower to generate.', | ||
displayName: 'Image Quality', | ||
required: true, | ||
}), | ||
}, | ||
}); | ||
exports.openaiModels = [ | ||
(0, utils_1.model)({ label: 'gpt-4o', value: 'gpt-4o', supported: ['text', 'function'] }), | ||
(0, utils_1.model)({ label: 'gpt-4o-mini', value: 'gpt-4o-mini', supported: ['text', 'function'] }), | ||
(0, utils_1.model)({ label: 'gpt-4-turbo', value: 'gpt-4-turbo', supported: ['text', 'function'] }), | ||
(0, utils_1.model)({ label: 'gpt-3.5-turbo', value: 'gpt-3.5-turbo', supported: ['text'] }), | ||
(0, utils_1.model)({ label: 'dall-e-3', value: 'dall-e-3', supported: ['image'] }) | ||
.mapper(openaiImageMapper), | ||
(0, utils_1.model)({ label: 'dall-e-2', value: 'dall-e-2', supported: ['image'] }) | ||
.mapper(openaiImageMapper), | ||
]; | ||
//# sourceMappingURL=index.js.map |
@@ -0,1 +1,3 @@ | ||
import { DynamicProp } from "@activepieces/pieces-framework"; | ||
import { AIChatCompletion, AIChatCompletionsCreateParams, AIImageCompletion, AIImageGenerateParams } from "../index"; | ||
export declare function authHeader(options: AuthHeaderOptions): AuthHeader; | ||
@@ -14,2 +16,44 @@ export type HeaderValueMapper = (value: string) => string; | ||
}; | ||
export type ModelParameterValue = string | number | boolean; | ||
export type Model = ReturnType<typeof model> | ReturnType<ReturnType<typeof model>["mapper"]>; | ||
export declare enum ModelType { | ||
IMAGE = "image", | ||
CHAT = "chat", | ||
NO_MAPPER = "no-mapper" | ||
} | ||
export declare function model(options: { | ||
label: string; | ||
value: string; | ||
supported: Array<'text' | 'image' | 'function'>; | ||
}): { | ||
__tag: ModelType; | ||
label: string; | ||
value: string; | ||
supported: ("function" | "text" | "image")[]; | ||
mapper: (mapper: ImageModelMapper | ChatModelMapper) => { | ||
mapper: ImageModelMapper | ChatModelMapper; | ||
__tag: ModelType.IMAGE | ModelType.CHAT; | ||
label: string; | ||
value: string; | ||
supported: ("function" | "text" | "image")[]; | ||
}; | ||
}; | ||
export type ModelMapper<T extends ModelType> = T extends ModelType.IMAGE ? ImageModelMapper : T extends ModelType.CHAT ? ChatModelMapper : never; | ||
export interface ImageModelMapper { | ||
__tag: ModelType.IMAGE; | ||
encodeInput: (input: AIImageGenerateParams) => Promise<object>; | ||
decodeOutput: (output: object) => Promise<AIImageCompletion | null>; | ||
advancedOptions?: Record<string, DynamicProp>; | ||
} | ||
export interface ChatModelMapper { | ||
__tag: ModelType.CHAT; | ||
encodeInput: (input: AIChatCompletionsCreateParams) => Promise<object>; | ||
decodeOutput: (output: object) => Promise<AIChatCompletion>; | ||
advancedOptions?: Record<string, DynamicProp>; | ||
} | ||
export declare function imageMapper(mapper: Omit<ImageModelMapper, "__tag">): ImageModelMapper; | ||
export declare function chatMapper(mapper: Omit<ChatModelMapper, "__tag">): ChatModelMapper; | ||
export declare const hasMapper: (m: Model) => m is Model & { | ||
mapper: ModelMapper<ModelType>; | ||
}; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.authHeader = void 0; | ||
exports.hasMapper = exports.chatMapper = exports.imageMapper = exports.model = exports.ModelType = exports.authHeader = void 0; | ||
function authHeader(options) { | ||
@@ -16,2 +16,32 @@ var _a; | ||
}; | ||
var ModelType; | ||
(function (ModelType) { | ||
ModelType["IMAGE"] = "image"; | ||
ModelType["CHAT"] = "chat"; | ||
ModelType["NO_MAPPER"] = "no-mapper"; | ||
})(ModelType || (exports.ModelType = ModelType = {})); | ||
function model(options) { | ||
return { | ||
__tag: ModelType.NO_MAPPER, | ||
label: options.label, | ||
value: options.value, | ||
supported: options.supported, | ||
mapper: function (mapper) { | ||
return Object.assign(Object.assign({}, this), { mapper: mapper, __tag: mapper.__tag }); | ||
}, | ||
}; | ||
} | ||
exports.model = model; | ||
function imageMapper(mapper) { | ||
return Object.assign(Object.assign({}, mapper), { __tag: ModelType.IMAGE }); | ||
} | ||
exports.imageMapper = imageMapper; | ||
function chatMapper(mapper) { | ||
return Object.assign(Object.assign({}, mapper), { __tag: ModelType.CHAT }); | ||
} | ||
exports.chatMapper = chatMapper; | ||
const hasMapper = (m) => { | ||
return m.__tag === ModelType.IMAGE || m.__tag === ModelType.CHAT; | ||
}; | ||
exports.hasMapper = hasMapper; | ||
//# sourceMappingURL=utils.js.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
113372
77
1654
12
3
1
+ Addedreplicate@0.34.1
+ Added@activepieces/pieces-framework@0.7.35(transitive)
+ Addedbase64-js@1.5.1(transitive)
+ Addedbuffer@6.0.3(transitive)
+ Addedevents@3.3.0(transitive)
+ Addedieee754@1.2.1(transitive)
+ Addedopenai@4.67.1(transitive)
+ Addedprocess@0.11.10(transitive)
+ Addedreadable-stream@4.7.0(transitive)
+ Addedreplicate@0.34.1(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedstring_decoder@1.3.0(transitive)
- Removed@activepieces/pieces-framework@0.7.34(transitive)
- Removed@activepieces/shared@0.10.116(transitive)
- Removed@sinclair/typebox@0.31.28(transitive)
- Removedopenai@4.47.1(transitive)
- Removedtslib@1.14.1(transitive)
- Removedweb-streams-polyfill@3.3.3(transitive)
Updatedopenai@4.67.1