Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,4 @@
# Mark binary files
*.png binary
*.jpg binary
*.gif binary
*.exe binary
*.dll binary
*.gif binary
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@smythos/sre",
"version": "1.5.66",
"version": "1.5.67",
"description": "Smyth Runtime Environment",
"author": "Alaa-eddine KADDOURI",
"license": "MIT",
Expand Down
45 changes: 13 additions & 32 deletions packages/core/src/Components/ImageGenerator.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ const IMAGE_GEN_COST_MAP = {
},
};

// Imagen 4 cost map - fixed cost per image
const IMAGEN_4_COST_MAP = {
'imagen-4': 0.04, // Standard Imagen 4
'imagen-4-ultra': 0.06, // Imagen 4 Ultra
};

export class ImageGenerator extends Component {
protected configSchema = Joi.object({
model: Joi.string().max(100).required(),
Expand Down Expand Up @@ -344,11 +338,6 @@ const imageGenerator = {

const files: any[] = parseFiles(input, config);

// Imagen models only support image generation, not image editing
if (files.length > 0) {
throw new Error('Google AI Image Generation Error: Image editing is not supported. Imagen models only support image generation.');
}

let args: GenerateImageConfig & {
aspectRatio?: string;
numberOfImages?: number;
Expand All @@ -360,29 +349,21 @@ const imageGenerator = {
personGeneration: config?.data?.personGeneration || 'allow_adult',
};

const response = await llmInference.imageGenRequest({ query: prompt, params: { ...args, agentId: agent.id } });

// Calculate fixed cost for Imagen 4
const modelName = model.replace(BUILT_IN_MODEL_PREFIX, '');
const cost = IMAGEN_4_COST_MAP[modelName];

if (cost && cost > 0) {
// Multiply by number of images generated
const numberOfImages = args.numberOfImages || 1;
const totalCost = cost * numberOfImages;

// Report fixed cost usage
imageGenerator.reportUsage(
{ cost: totalCost },
{
modelEntryName: model,
keySource: model.startsWith(BUILT_IN_MODEL_PREFIX) ? APIKeySource.Smyth : APIKeySource.User,
agentId: agent.id,
teamId: agent.teamId,
}
);
let response;

// Check if files are provided for image editing
if (files.length > 0) {
const validFiles = files.filter((file) => imageGenerator.isValidImageFile('GoogleAI', file.mimetype));
if (validFiles.length === 0) {
throw new Error('Supported image file types are: ' + SUPPORTED_MIME_TYPES_MAP.GoogleAI?.image?.join(', '));
}
response = await llmInference.imageEditRequest({ query: prompt, files: validFiles, params: { ...args, agentId: agent.id } });
} else {
response = await llmInference.imageGenRequest({ query: prompt, params: { ...args, agentId: agent.id } });
}

// Usage reporting is now handled in the GoogleAI connector

let output = response?.data?.[0]?.b64_json;

if (output) {
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/helpers/Conversation.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ export class Conversation extends EventEmitter {
let _content = '';
const reqMethods = this._reqMethods;
const toolsConfig = this._toolsConfig;
//deduplicate tools
toolsConfig.tools = toolsConfig.tools.filter((tool, index, self) => self.findIndex((t) => t.name === tool.name) === index);
const endpoints = this._endpoints;
const baseUrl = this._baseUrl;
const message_id = 'msg_' + randomUUID();
Expand Down
Loading