-
Couldn't load subscription status.
- Fork 0
Implement AI Module (In-progress) #129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
WalkthroughThis update introduces a comprehensive AI image generation feature alongside significant refactoring and enhancements to the summarization module. It adds new controllers, services, strategies, types, prompts, and validation schemas for image generation, with support for both Gemini and Together AI providers. Summarization now supports streaming, uses an updated client, and improved prompt structures. Supporting scripts, configuration files, and environment variables are also updated or added. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant API_Router
participant ImageGenController
participant ImageGenService
participant Strategy (Gemini/Together)
participant AIProviderAPI
Client->>API_Router: POST /generate/single or /generate/multiple
API_Router->>ImageGenController: validate + route request
ImageGenController->>ImageGenService: generate(request)
ImageGenService->>Strategy: generate(request)
Strategy->>AIProviderAPI: Call AI image generation API
AIProviderAPI-->>Strategy: Return image(s)
Strategy-->>ImageGenService: Return result
ImageGenService-->>ImageGenController: Return result
ImageGenController-->>API_Router: Return image(s)
API_Router-->>Client: Respond with image(s)
sequenceDiagram
participant Client
participant API_Router
participant SummarizationController
participant SummarizationService
participant GoogleGenAI
Client->>API_Router: POST /summarize/stream
API_Router->>SummarizationController: validate + route request
SummarizationController->>SummarizationService: summarizeStream(request)
SummarizationService->>GoogleGenAI: generateContentStream(request)
GoogleGenAI-->>SummarizationService: Stream summary chunks
SummarizationService-->>SummarizationController: Return stream & metadata
SummarizationController-->>API_Router: Respond with streaming summary
API_Router-->>Client: Return summary stream
Possibly related PRs
Poem
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 22
🧹 Nitpick comments (21)
backend/docker-compose.yml (2)
3-3: Pin Postgres image versionUsing
latestcan introduce breaking changes unexpectedly. Recommend specifying a major (or minor) version, e.g.postgres:15-alpine.
6-9: Extract sensitive credentials to environment fileHard-coding DB credentials in
docker-compose.ymlposes maintainability and security risks. Consider movingPOSTGRES_USER,POSTGRES_PASSWORD, andPOSTGRES_DBinto an external.envand referencing them viaenv_fileor${VAR}interpolation.backend/scripts/deploy_test_pg_db.sh (1)
1-1: Add strict mode and cleanup trapWhile using
#!/usr/bin/env bashis more portable, the script should fail fast and ensure the temporaryPGPASS_FILEis removed on errors. For example:#!/usr/bin/env bash +set -euo pipefail +trap 'rm -f "$PGPASS_FILE"' EXITbackend/scripts/test_data.sql (1)
247-261: Optimize metric aggregation with a single CTEUpdating each row with two separate subqueries can be expensive. Consider computing like/share counts in a CTE and performing one join:
WITH counts AS ( SELECT content_id, COUNT(*) FILTER (WHERE interaction_type = 'like') AS likes, COUNT(*) FILTER (WHERE interaction_type = 'share') AS shares FROM user_content_interactions GROUP BY content_id ) UPDATE content c SET likes = counts.likes, shares = counts.shares FROM counts WHERE c.content_id = counts.content_id;backend/src/modules/ai/controllers/summarization.controller.ts (1)
36-40: Reconsider logging timing for streaming responses.Logging
stream.metadata.processingTimefor a streaming response may not provide accurate timing information, as streams are typically processed incrementally. Consider either logging when the stream completes or clarifying what this timing represents.- logger.info('Successfully generated summary stream', { + logger.info('Successfully initiated summary stream', { textLength: requestData.text.length, - processingTime: stream.metadata.processingTime, + initiationTime: stream.metadata.processingTime, model: stream.metadata.model, });backend/src/modules/ai/strategy/generation.strategy.ts (1)
9-13: Consider improving type safety with generic constraints.The interface correctly implements the strategy pattern, but the union return type makes it difficult for consumers to know which response type to expect. Consider using generics or method overloads for better type safety.
export interface ImageGenerationStrategy { - generate( - request: LowerTierImageGenerationRequest | HigherTierImageGenerationRequest - ): Promise<LowerTierImageGenerationResponse | HigherTierImageGenerationResponse>; + generate(request: LowerTierImageGenerationRequest): Promise<LowerTierImageGenerationResponse>; + generate(request: HigherTierImageGenerationRequest): Promise<HigherTierImageGenerationResponse>; + generate( + request: LowerTierImageGenerationRequest | HigherTierImageGenerationRequest + ): Promise<LowerTierImageGenerationResponse | HigherTierImageGenerationResponse>; }backend/src/modules/ai/controllers/generation.controller.ts (1)
3-5: Remove unused imports.Several imports are currently unused due to the placeholder implementation.
Since the methods are not yet implemented, consider removing unused imports until they're actually needed:
-import { createSuccessResponse } from '../../../shared/utils/response'; -import { logger } from '../../../shared/utils/logger'; -import { ImageGenerationResponse } from '../types';backend/.env.sample (1)
30-30: Verify the "Algoria" typo in the comment.The comment was changed from "ALGOLIA" to "Algoria," which appears to be a typo. The service name should remain "Algolia."
-# Algoria Search API +# Algolia Search APIbackend/scripts/config.sh (1)
11-12: Consider removing unused color variables or export them for external use.Static analysis identified
COLOR_CYANandCOLOR_WHITEas unused. Either remove them if not needed or export them if they're intended for use in scripts that source this file.- COLOR_CYAN=$(tput setaf 6) - COLOR_WHITE=$(tput setaf 7)Or export them if intended for external use:
- COLOR_CYAN=$(tput setaf 6) - COLOR_WHITE=$(tput setaf 7) + export COLOR_CYAN=$(tput setaf 6) + export COLOR_WHITE=$(tput setaf 7)Also applies to: 21-22
backend/src/modules/ai/services/imagen/google.service.ts (2)
5-5: Remove unused import.The
Togetherimport from 'together-ai' is not used in this file and should be removed.-import Together from 'together-ai';
38-44: Remove unnecessary null check after constructor.The check
if (!genAI)is unnecessary because theGoogleGenAIconstructor will either return a valid instance or throw an error. It won't return null or undefined.- if (!genAI) { - throw new AppError( - 500, - 'Failed to initialize Google GenAI client. Please check your environment variables.', - APP_ERROR_SOURCE - ); - } - return genAI;backend/src/modules/ai/services/imagen/together.service.ts (3)
3-3: Remove unused import.The
GoogleGenAIimport from '@google/genai' is not used in this file and should be removed.-import { GoogleGenAI } from '@google/genai';
39-45: Remove unnecessary null check after constructor.Similar to the Google service, the check
if (!togetherAI)is unnecessary because the constructor will either return a valid instance or throw an error.- if (!togetherAI) { - throw new AppError( - 500, - 'Failed to initialize Together AI client. Please check your environment variables.', - APP_ERROR_SOURCE - ); - } - return togetherAI;
58-58: Fix typo in TODO comment.- * TODO: Implement Together AI Image Generation Logc + * TODO: Implement Together AI Image Generation Logicbackend/justfile (1)
59-61: Remove redundant argument check.The check for empty
$argis unnecessary since the recipe already has a default value of "default" defined on line 54.- if [ -z "$arg" ]; then \ - arg="default" \ - fibackend/src/modules/ai/services/summarization.service.ts (1)
34-40: Remove unnecessary null check.The check for
!genAIis redundant. If theGoogleGenAIconstructor fails, it will throw an error rather than returning null or undefined.- if (!genAI) { - throw new AppError( - 500, - 'Failed to initialize Google GenAI client. Please check your environment variables.', - APP_ERROR_SOURCE - ); - } -backend/src/modules/ai/types/generation.types.ts (3)
47-57: Remove redundant TODO comment and ensure consistency.The
HigherTierImageGenerationRequestinterface is actually properly implemented and matches the Zod schema structure, so the TODO comment is misleading.Apply this diff to remove the misleading TODO:
-// TODO: Refactor implementation HigherTierImageGenerationRequest export interface HigherTierImageGenerationRequest { prompt: string; options?: { model?: AIGenerationModel; width?: number; height?: number; steps?: number; disable_safety_checker?: boolean; }; }
75-77: Remove the commented export statement.The commented export with the extremely long interface name appears to be leftover code or a joke comment that should be removed.
Apply this diff to clean up the file:
-/** - * export interface ExpensivelyHighForAbsolutelyNoReasonOtherThanToShowOffWeAreAbleToMakeHighQualityImagesFromTheirAPIImageGenerationRequest {} - */
5-18: Consider consolidating the Zod schemas to reduce duplication.Both
LowerTierImageGenerationRequestSchemaandHigherTierImageGenerationRequestSchemaare nearly identical except for the prompt max length. This creates maintenance overhead.Consider creating a factory function to generate schemas with different prompt limits:
+const createImageGenerationRequestSchema = (maxPromptLength: number) => z.object({ + body: z.object({ + prompt: z.string().min(1, 'Prompt must not be empty.').max(maxPromptLength, 'Provided prompt is too long.'), + options: z.object({ + model: z.nativeEnum(AIGenerationModel).optional(), + width: z.number().positive().optional(), + height: z.number().positive().optional(), + steps: z.number().int().positive().optional(), + disable_safety_checker: z.boolean().optional(), + }).optional(), + }), + query: z.object({}).optional(), + params: z.object({}).optional(), +}); + -export const LowerTierImageGenerationRequestSchema = z.object({ - body: z.object({ - prompt: z.string().min(1, 'Prompt must not be empty.').max(1000, 'Provided prompt is too long.'), - options: z.object({ - model: z.nativeEnum(AIGenerationModel).optional(), - width: z.number().positive().optional(), - height: z.number().positive().optional(), - steps: z.number().int().positive().optional(), - disable_safety_checker: z.boolean().optional(), - }).optional(), - }), - query: z.object({}).optional(), - params: z.object({}).optional(), -}); -export const HigherTierImageGenerationRequestSchema = z.object({ - body: z.object({ - prompt: z.string().min(1, 'Prompt must not be empty.').max(10000, 'Provided prompt is too long.'), - options: z.object({ - model: z.nativeEnum(AIGenerationModel).optional(), - width: z.number().positive().optional(), - height: z.number().positive().optional(), - steps: z.number().int().positive().optional(), - disable_safety_checker: z.boolean().optional(), - }).optional(), - }), - query: z.object({}).optional(), - params: z.object({}).optional(), -}); +export const LowerTierImageGenerationRequestSchema = createImageGenerationRequestSchema(1000); +export const HigherTierImageGenerationRequestSchema = createImageGenerationRequestSchema(10000);Also applies to: 20-33
backend/src/modules/ai/types/models.types.ts (2)
9-14: Consider standardizing model naming conventions.The
AIGenerationModelenum has inconsistent naming patterns. Some models use camelCase (TogetherFlux1Dev) while others mix naming styles.Consider standardizing the naming convention:
export enum AIGenerationModel { - Gemini20FlashImageGenPreview = 'gemini-2.0-flash-preview-image-generation', + Gemini20FlashImageGeneration = 'gemini-2.0-flash-preview-image-generation', TogetherFlux1Dev = 'black-forest-labs/FLUX.1-dev', TogetherFlux1Schnell = 'black-forest-labs/FLUX.1-schnell', TogetherFlux1SchnellFree = 'black-forest-labs/FLUX.1-schnell-Free', }Also, verify that the
TogetherFlux1SchnellFreevalue ending with-Freeis correct as it appears inconsistent with the others ending with lowercase.
34-44: Consider breaking down the large ModelConfig interface.The
ModelConfiginterface has grown significantly with many optional fields. This could lead to maintainability issues and unclear usage patterns.Consider breaking this into more focused interfaces:
+export interface BaseModelConfig { + temperature?: number; + topP?: number; + topK?: number; + maxOutputTokens?: number; + stopSequences?: string[]; +} + +export interface SafetyModelConfig { + safetySettings?: SafetySetting[]; +} + +export interface AdvancedModelConfig { + systemInstruction?: string; + thinkingConfig?: ThinkingConfig; + httpOptions?: HttpOptions; +} + -export interface ModelConfig { - safetySettings?: SafetySetting[]; - systemInstruction?: string; - temperature?: number; - topP?: number; - topK?: number; - maxOutputTokens?: number; - stopSequences?: string[]; - thinkingConfig?: ThinkingConfig; - httpOptions?: HttpOptions; -} +export interface ModelConfig extends BaseModelConfig, SafetyModelConfig, AdvancedModelConfig {}This approach provides better composition and clearer separation of concerns.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (26)
backend/.env.sample(2 hunks)backend/docker-compose.yml(1 hunks)backend/justfile(1 hunks)backend/package.json(2 hunks)backend/scripts/config.sh(1 hunks)backend/scripts/deploy_test_pg_db.sh(1 hunks)backend/scripts/test_data.sql(1 hunks)backend/src/modules/ai/config/models.ts(1 hunks)backend/src/modules/ai/config/prompts.ts(1 hunks)backend/src/modules/ai/controllers/generation.controller.ts(1 hunks)backend/src/modules/ai/controllers/summarization.controller.ts(1 hunks)backend/src/modules/ai/routes/generation.routes.ts(1 hunks)backend/src/modules/ai/routes/summarization.routes.ts(1 hunks)backend/src/modules/ai/services/generation.service.ts(1 hunks)backend/src/modules/ai/services/imagen/google.service.ts(1 hunks)backend/src/modules/ai/services/imagen/index.ts(1 hunks)backend/src/modules/ai/services/imagen/together.service.ts(1 hunks)backend/src/modules/ai/services/index.ts(1 hunks)backend/src/modules/ai/services/summarization.service.ts(1 hunks)backend/src/modules/ai/strategy/generation.strategy.ts(1 hunks)backend/src/modules/ai/types/generation.types.ts(1 hunks)backend/src/modules/ai/types/index.ts(1 hunks)backend/src/modules/ai/types/models.types.ts(1 hunks)backend/src/modules/ai/types/summarization.types.ts(2 hunks)backend/src/modules/ai/utils/ai.utils.ts(1 hunks)backend/src/shared/config/environment.ts(3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (8)
backend/src/modules/ai/strategy/generation.strategy.ts (1)
backend/src/modules/ai/types/generation.types.ts (4)
LowerTierImageGenerationRequest(37-39)HigherTierImageGenerationRequest(48-57)LowerTierImageGenerationResponse(42-44)HigherTierImageGenerationResponse(60-67)
backend/src/modules/ai/routes/generation.routes.ts (3)
backend/src/modules/ai/controllers/generation.controller.ts (1)
ImageGenerationController(7-29)backend/src/shared/middleware/validation.middleware.ts (1)
validateRequest(5-26)backend/src/modules/ai/types/generation.types.ts (2)
LowerTierImageGenerationRequestSchema(5-18)HigherTierImageGenerationRequestSchema(20-33)
backend/src/modules/ai/routes/summarization.routes.ts (3)
backend/src/modules/ai/controllers/summarization.controller.ts (1)
SummarizationController(7-47)backend/src/shared/middleware/validation.middleware.ts (1)
validateRequest(5-26)backend/src/modules/ai/types/summarization.types.ts (1)
SummarizationRequestSchema(5-16)
backend/src/modules/ai/services/imagen/together.service.ts (7)
backend/src/modules/ai/strategy/generation.strategy.ts (1)
ImageGenerationStrategy(9-13)backend/src/modules/ai/utils/ai.utils.ts (1)
checkEnvironmentVariables(65-82)backend/src/modules/ai/config/prompts.ts (1)
IMAGE_GENERATION_USER_PROMPT(134-149)backend/src/shared/config/environment.ts (1)
env(29-68)backend/src/shared/errors/index.ts (1)
AppError(1-11)backend/src/modules/ai/types/generation.types.ts (3)
LowerTierImageGenerationRequest(37-39)HigherTierImageGenerationRequest(48-57)LowerTierImageGenerationResponse(42-44)backend/src/shared/utils/logger.ts (1)
logger(28-49)
backend/src/shared/config/environment.ts (1)
backend/src/shared/utils/logger.ts (1)
logger(28-49)
backend/src/modules/ai/config/models.ts (2)
backend/src/modules/ai/types/models.types.ts (2)
ModelConfig(34-44)GenerationModelConfig(51-59)backend/src/modules/ai/config/prompts.ts (1)
SUMMARY_SYSTEM_PROMPT(1-46)
backend/src/modules/ai/services/generation.service.ts (4)
backend/src/modules/ai/strategy/generation.strategy.ts (1)
ImageGenerationStrategy(9-13)backend/src/modules/ai/utils/ai.utils.ts (1)
checkEnvironmentVariables(65-82)backend/src/shared/errors/index.ts (1)
AppError(1-11)backend/src/modules/ai/types/generation.types.ts (3)
LowerTierImageGenerationRequest(37-39)HigherTierImageGenerationRequest(48-57)LowerTierImageGenerationResponse(42-44)
backend/src/modules/ai/utils/ai.utils.ts (2)
backend/src/shared/config/environment.ts (1)
env(29-68)backend/src/shared/errors/index.ts (1)
AppError(1-11)
🪛 Shellcheck (0.10.0)
backend/scripts/config.sh
[warning] 21-21: COLOR_CYAN appears unused. Verify use (or export if used externally).
(SC2034)
[warning] 22-22: COLOR_WHITE appears unused. Verify use (or export if used externally).
(SC2034)
🔇 Additional comments (29)
backend/package.json (1)
39-39:❓ Verification inconclusive
Verify dependency replacement and lockfile update
You’ve replaced
@google/generative-aiwith@google/genaiand addedtogether-ai. Ensure:
- All imports of the old package are removed.
- The lockfile (
package-lock.json/yarn.lock) is updated and committed.- There are no breaking API changes in the new clients.
You can run:
Also applies to: 56-56
🏁 Script executed:
# Check for leftover imports rg '@google/generative-ai' rg 'together-ai' -A2 # Install and verify lockfile npm install git diff --name-only | grep -E 'package-lock.json|yarn.lock'Length of output: 1237
🏁 Script executed:
#!/bin/bash cd backend # 1. Verify no leftover imports of the old package rg '@google/generative-ai' # 2. Confirm together-ai imports are expected rg 'together-ai' -A2 # 3. Install and check lockfile changes npm install git diff --name-only | grep -E 'package-lock.json|yarn.lock'Length of output: 1690
🏁 Script executed:
#!/bin/bash cd backend # 1. Verify that the new Google GenAI client is imported rg '@google/genai' -A2 src/modules/ai/services/imagen # 2. Check for lockfile updates after installation npm install git diff --name-only | grep -E 'package-lock.json|yarn.lock'Length of output: 856
🏁 Script executed:
#!/bin/bash cd backend # Check for lockfile presence and entries if [ -f package-lock.json ]; then echo "Found package-lock.json" echo "🔍 Searching for @google/genai in package-lock.json" grep -C2 '"@google/genai"' package-lock.json || echo "❌ No entry for @google/genai" echo "🔍 Searching for together-ai in package-lock.json" grep -C2 '"together-ai"' package-lock.json || echo "❌ No entry for together-ai" elif [ -f yarn.lock ]; then echo "Found yarn.lock" echo "🔍 Searching for @google/genai and together-ai in yarn.lock" grep -E '(@google/genai|together-ai)' -C2 yarn.lock || echo "❌ No entries found" else echo "❌ No lockfile detected (package-lock.json or yarn.lock)" fiLength of output: 775
Dependency migration verified
- No remaining imports of
@google/generative-aiwere found.- Imports of the new clients (
@google/genaiandtogether-ai) are correctly in place.package-lock.jsonincludes entries for both@google/genaiandtogether-ai, confirming the lockfile was updated and committed.Please perform a manual review (run existing tests or smoke checks) to ensure there are no breaking API changes in the new clients.
backend/src/modules/ai/services/imagen/index.ts (1)
1-2: Barrel exports look correctRe-exporting both strategy implementations provides a clean API boundary. This index file aligns with the PR’s modular design.
backend/src/modules/ai/types/index.ts (1)
3-3: LGTM! Clean addition following established patterns.The new export for generation types follows the existing pattern and enables centralized access to image generation types through the module index.
backend/src/modules/ai/services/index.ts (1)
1-2: LGTM! Good module organization with centralized service exports.This index file follows the established pattern and provides a clean single entry point for importing AI services.
backend/src/modules/ai/routes/summarization.routes.ts (3)
6-6: LGTM! Variable rename improves clarity.Renaming the router variable to
summarizationRouterprovides better clarity and follows naming conventions.
15-19: LGTM! Streaming endpoint follows established patterns.The new
/summarize/streamendpoint correctly:
- Uses the same validation schema as the standard endpoint
- Follows the same route structure pattern
- References the existing
summarizeAsStreamcontroller method
21-21: LGTM! Export updated correctly.The export statement correctly uses the renamed router variable.
backend/src/shared/config/environment.ts (3)
5-5: LGTM! Improved logging consistency.Replacing console.log with structured logging using the logger utility improves consistency and follows logging best practices.
Also applies to: 17-17
20-20: LGTM! Error message clarity improvement.The updated error message provides clearer context about the failure to locate the environment file.
46-46: LGTM! New AI provider environment variables added correctly.The new environment variables properly support the image generation functionality:
googleUseVertexAIuses standard boolean conversion patterntogetherKeyandtogetherBaseUrlsupport the Together AI provider- All additions align with the new AI image generation services
Also applies to: 50-51
backend/src/modules/ai/routes/generation.routes.ts (1)
1-22: LGTM! Well-structured routing implementation.The router setup is clean and follows good practices:
- Appropriate separation of single vs multiple generation endpoints
- Proper validation middleware integration
- Clear tier-based schema validation
- Consistent with Express.js patterns
backend/.env.sample (1)
42-44: LGTM! AI configuration variables properly added.The addition of
GEMINI_API_KEYandTOGETHER_API_KEYenvironment variables correctly supports the new AI image generation and summarization services introduced in this PR.backend/src/modules/ai/types/summarization.types.ts (2)
7-7: LGTM! Improved validation error messages.The validation error messages are now more explicit and user-friendly, clearly indicating the constraints on the text field.
36-53: LGTM! Well-structured streaming interfaces.The new
SummarizationStreamResponseandSummarizationStreamChunkinterfaces provide proper type safety for streaming functionality. The consistent metadata structure across all response types maintains good design patterns.backend/src/modules/ai/services/generation.service.ts (2)
9-24: LGTM! Proper constructor validation and strategy pattern implementation.The constructor correctly validates environment variables for both AI providers and ensures a valid strategy is provided. The error handling with AppError is consistent and informative.
26-41: LGTM! Well-implemented strategy accessors.The getter and setter methods for the strategy are properly implemented with validation in the setter to prevent invalid strategy assignment.
backend/scripts/config.sh (1)
1-54: LGTM! Well-structured logging utility script.The script provides excellent standardized logging functionality with:
- Proper color detection and fallback
- Appropriate use of stderr for warnings and errors
- Consistent timestamp formatting
- Good error handling with
set -eThis will improve consistency across backend shell scripts.
🧰 Tools
🪛 Shellcheck (0.10.0)
[warning] 21-21: COLOR_CYAN appears unused. Verify use (or export if used externally).
(SC2034)
[warning] 22-22: COLOR_WHITE appears unused. Verify use (or export if used externally).
(SC2034)
backend/src/modules/ai/services/imagen/google.service.ts (2)
27-27: Verify the use of preview model as default.The default model is set to
Gemini20FlashImageGenPreviewwhich appears to be a preview version. Please confirm this is the intended default model for production use.
61-67:✅ Verification successful
Verify the Google GenAI API usage.
The code calls
genAI.models.generateImagesbut this API method needs verification. The Google GenAI client might use a different method name or structure.
🌐 Web query:
What is the correct API method for generating images using the @google/genai SDK version 1.4.0?💡 Result:
To generate images using the @google/genai SDK version 1.4.0, you need to use the
generateImagesmethod from the models module of the SDK.The correct syntax for generating images is:
const response = await client.models.generateImages({ model: 'imagen-3.0-generate-002', prompt: 'Your descriptive prompt here', config: { numberOfImages: 1, // Additional configuration options } });This method allows you to create images using Google's Imagen model through the Gemini API. Here are the key components of the image generation process:
- You need to create a client instance first using the GoogleGenAI class and provide your API key.
- The
generateImagesmethod is accessed through the models submodule of the client instance.- You must specify the model to use - 'imagen-3.0-generate-002' is a commonly used option.
- A text prompt is required to guide the image generation.
- Additional configuration parameters can be provided, such as:
numberOfImages: The number of images to generate (1-4 images)[5]aspectRatio: Controls the dimensions of the generated image (options include "1:1", "3:4", "4:3", "9:16", and "16:9")[1]personGeneration: Controls whether people can be generated in images[1]The generated images will be watermarked with SynthID and can be accessed from the response object[1].
Note that for most use cases, you should start with Gemini for image generation, but for specialized tasks where image quality is critical, Imagen is recommended[1].
Citations:
- 1: https://ai.google.dev/gemini-api/docs/image-generation
- 2: https://pypi.org/project/google-genai/
- 3: https://ai.google.dev/gemini-api/docs/libraries
- 4: https://cloud.google.com/vertex-ai/generative-ai/docs/sdks/overview
- 5: https://www.npmjs.com/package/@google/genai
- 6: https://ai.google.dev/gemini-api/docs/migrate
- 7: https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/imagen-api
- 8: https://cloud.google.com/nodejs/docs/reference/vertexai/latest
- 9: https://googleapis.github.io/python-genai/
- 10: https://ai.google.dev/api/generate-content
Google GenAI
generateImagesUsage is Correct
Verified that callinggenAI.models.generateImages({ model, prompt, config })matches the @google/genai SDK v1.4.0 documentation for image generation. No changes required.backend/src/modules/ai/utils/ai.utils.ts (2)
47-63: Well-implemented environment validation.The validation for Together AI environment variables is correctly implemented with clear error messages.
65-82: Clean dispatcher pattern implementation.The environment variable validation dispatcher is well-implemented with proper error handling for unknown providers.
backend/justfile (1)
1-11: Well-structured justfile with good practices.The justfile follows good practices:
- Exports configuration script for consistency
- Provides convenient aliases
- Includes a default recipe that lists available commands
backend/src/modules/ai/services/summarization.service.ts (3)
20-26: Well-structured service initialization.Good practices observed:
- Environment validation at initialization time
- Proper setup of tiktoken encoding for token counting
- Clear default model configuration
45-51: Clean token calculation implementation.The token usage calculation is properly implemented, providing accurate metrics for both prompt and response tokens.
53-120: Excellent refactoring of the summarize method.The updated implementation shows several improvements:
- Clean migration to the new GoogleGenAI client
- Comprehensive error handling with proper error propagation
- Useful metadata tracking (model, processing time, token count)
- Clear documentation of the GenAI parameters
backend/src/modules/ai/config/prompts.ts (2)
1-46: Excellent prompt structure for summarization.The summarization system prompt is well-structured with clear sections, specific requirements, and comprehensive guidelines. The use of XML-like tags improves readability and organization.
71-125: Well-structured image generation system prompt.The image generation system prompt follows good practices with clear sections for core tasks, requirements, guidelines, prohibitions, and quality standards. The structure promotes consistent output quality.
backend/src/modules/ai/types/models.types.ts (2)
6-7: Approve the new AIModel enum addition.The addition of
Gemini15FlashLitefollows consistent naming conventions and extends the existing enum appropriately.
1-1:✅ Verification successful
Verify the Google GenAI import usage.
The import from
@google/genaiintroduces a dependency that should be verified for compatibility and proper usage.
🏁 Script executed:
#!/bin/bash # Description: Verify the @google/genai package usage and version # Expected: Find package.json entry and usage patterns # Check if the package is listed in dependencies cat backend/package.json | jq '.dependencies["@google/genai"]' # Search for usage of the imported types rg -A 3 "HarmBlockMethod|HarmBlockThreshold|HarmCategory" backend/src/Length of output: 5976
Import @google/genai is properly declared and utilized
- backend/package.json lists
"@google/genai": "^1.4.0".- HarmBlockMethod, HarmBlockThreshold, and HarmCategory are imported in
backend/src/modules/ai/types/models.types.tsand consumed inbackend/src/modules/ai/config/models.ts.- No compatibility or usage issues found; no changes required.
| ports: | ||
| - "5433:5433" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix PostgreSQL port mapping
The container’s default Postgres port is 5432, so mapping "5433:5433" won’t expose the database. Change to map host port 5433 to container port 5432:
ports:
- - "5433:5433"
+ - "5433:5432"🤖 Prompt for AI Agents
In backend/docker-compose.yml around lines 11 to 12, the port mapping for
PostgreSQL is incorrect because it maps host port 5433 to container port 5433,
but the container uses the default port 5432. Update the port mapping to
"5433:5432" to expose the container's PostgreSQL service correctly on host port
5433.
| generateImageMultiple = async (req: Request, res: Response, next: NextFunction) => { | ||
| try { | ||
| return []; | ||
| } catch (error) { | ||
| next(error); | ||
| } | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implement the actual multiple image generation logic.
Similar to the single generation method, this placeholder implementation needs to be completed with actual service calls and proper response handling.
generateImageMultiple = async (req: Request, res: Response, next: NextFunction) => {
try {
- return [];
+ const requestData = req.body;
+ const results = await this.service.generateMultiple(requestData);
+
+ logger.info('Successfully generated multiple images', {
+ promptLength: requestData.prompt.length,
+ imageCount: results.length,
+ });
+
+ res.json(createSuccessResponse(results));
} catch (error) {
next(error);
}
};🤖 Prompt for AI Agents
In backend/src/modules/ai/controllers/generation.controller.ts around lines 22
to 28, the generateImageMultiple method currently returns an empty array as a
placeholder. Replace this with the actual logic to generate multiple images by
calling the appropriate service method, handling the request data, and sending
the generated images in the response. Ensure proper error handling by keeping
the try-catch structure and calling next(error) on failure.
| generateImageSingle = async (req: Request, res: Response, next: NextFunction) => { | ||
| try { | ||
| return []; | ||
| } catch (error) { | ||
| next(error); | ||
| } | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implement the actual image generation logic.
The method currently returns an empty array, which doesn't match the expected response type and provides no functionality. The instantiated service should be used to process the request.
generateImageSingle = async (req: Request, res: Response, next: NextFunction) => {
try {
- return [];
+ const requestData = req.body;
+ const result = await this.service.generate(requestData);
+
+ logger.info('Successfully generated single image', {
+ promptLength: requestData.prompt.length,
+ model: result.metadata?.model,
+ });
+
+ res.json(createSuccessResponse(result));
} catch (error) {
next(error);
}
};📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| generateImageSingle = async (req: Request, res: Response, next: NextFunction) => { | |
| try { | |
| return []; | |
| } catch (error) { | |
| next(error); | |
| } | |
| }; | |
| generateImageSingle = async (req: Request, res: Response, next: NextFunction) => { | |
| try { | |
| const requestData = req.body; | |
| const result = await this.service.generate(requestData); | |
| logger.info('Successfully generated single image', { | |
| promptLength: requestData.prompt.length, | |
| model: result.metadata?.model, | |
| }); | |
| res.json(createSuccessResponse(result)); | |
| } catch (error) { | |
| next(error); | |
| } | |
| }; |
🤖 Prompt for AI Agents
In backend/src/modules/ai/controllers/generation.controller.ts around lines 14
to 20, the generateImageSingle method currently returns an empty array instead
of implementing the actual image generation logic. Replace the placeholder
return with code that uses the instantiated image generation service to process
the request data and return the generated image(s) in the response, ensuring the
output matches the expected response type.
| async generate( | ||
| request: LowerTierImageGenerationRequest | HigherTierImageGenerationRequest | ||
| ): Promise<LowerTierImageGenerationResponse | HigherTierImageGenerationRequest> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix the incorrect return type in generate method.
The return type should be LowerTierImageGenerationResponse | HigherTierImageGenerationResponse instead of LowerTierImageGenerationResponse | HigherTierImageGenerationRequest.
async generate(
request: LowerTierImageGenerationRequest | HigherTierImageGenerationRequest
-): Promise<LowerTierImageGenerationResponse | HigherTierImageGenerationRequest> {
+): Promise<LowerTierImageGenerationResponse | HigherTierImageGenerationResponse> {📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| async generate( | |
| request: LowerTierImageGenerationRequest | HigherTierImageGenerationRequest | |
| ): Promise<LowerTierImageGenerationResponse | HigherTierImageGenerationRequest> { | |
| async generate( | |
| request: LowerTierImageGenerationRequest | HigherTierImageGenerationRequest | |
| ): Promise<LowerTierImageGenerationResponse | HigherTierImageGenerationResponse> { |
🤖 Prompt for AI Agents
In backend/src/modules/ai/services/generation.service.ts around lines 43 to 45,
the generate method's return type is incorrectly specified as
LowerTierImageGenerationResponse | HigherTierImageGenerationRequest. Update the
return type to LowerTierImageGenerationResponse |
HigherTierImageGenerationResponse to correctly reflect the possible response
types returned by the method.
| // TODO: Finish implementation for generate method in GeminiImageGenerationService | ||
|
|
||
| } catch (error) { | ||
| if (error instanceof AppError) { | ||
| throw error; | ||
| } else { | ||
| logger.error( | ||
| APP_ERROR_SOURCE, | ||
| 'An unexpected error occurred during image generation.', | ||
| error | ||
| ); | ||
| throw new AppError( | ||
| 500, | ||
| 'An unexpected error occurred during image generation. Please try again later.', | ||
| APP_ERROR_SOURCE | ||
| ); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Complete the implementation or throw an error.
The method has a TODO comment and doesn't return anything, which will cause a runtime error since the return type is a Promise.
The method needs to either:
- Return a proper response object
- Throw an error indicating it's not implemented
Would you like me to help implement the complete logic or create an issue to track this TODO?
🤖 Prompt for AI Agents
In backend/src/modules/ai/services/imagen/google.service.ts around lines 82 to
100, the generate method is incomplete and currently does not return any value,
which will cause a runtime error due to its Promise return type. To fix this,
either implement the full logic to return the expected response object or
explicitly throw a "Not Implemented" error to indicate the method is unfinished.
This ensures the method adheres to its return type contract and prevents runtime
issues.
| const stream = []; | ||
| for await (const chunk of result) { | ||
| const summaryChunk = chunk.text; | ||
|
|
||
| if (!summaryChunk) { | ||
| throw new AppError( | ||
| 500, | ||
| 'Failed to generate summary stream, the model returned an empty response which was unexpected.', | ||
| APP_ERROR_SOURCE | ||
| ); | ||
| } | ||
|
|
||
| logger.debug('Received chunk from summarization stream', { summaryChunk }); | ||
| stream.push(summaryChunk); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider true streaming implementation.
The current implementation collects all chunks in an array before returning, which defeats the purpose of streaming. For true streaming support, consider yielding chunks as they arrive.
Consider implementing an async generator that yields chunks:
async *summarizeStream(request: SummarizationRequest): AsyncGenerator<string, SummarizationStreamResponse> {
const startTime = Date.now();
const modelType = request.options?.model || this.defaultModelType;
// ... setup code ...
const chunks: string[] = [];
for await (const chunk of result) {
const summaryChunk = chunk.text;
if (!summaryChunk) {
throw new AppError(500, 'Empty chunk received', APP_ERROR_SOURCE);
}
chunks.push(summaryChunk);
yield summaryChunk; // Yield chunk immediately
}
// Return metadata after streaming completes
return {
stream: chunks,
metadata: {
model: modelType,
processingTime: Date.now() - startTime,
tokenCount: this.calculateTokenUsage(formattedPrompt, chunks.join(''))
}
};
}This allows the controller to stream responses to the client in real-time.
🤖 Prompt for AI Agents
In backend/src/modules/ai/services/summarization.service.ts around lines 150 to
164, the current code collects all summary chunks into an array before
returning, which prevents true streaming. Refactor the method into an async
generator that yields each chunk as it arrives using "yield summaryChunk" inside
the loop. Accumulate chunks in an array for metadata calculation, then return
the metadata and full stream after iteration completes. This change enables
real-time streaming of summary chunks to the client.
| // TODO: Implement interface LowerTierImageGenerationRequest | ||
| export interface LowerTierImageGenerationRequest { | ||
| prompt: string; | ||
| } | ||
|
|
||
| // TODO: Implement interface LowerTierImageGenerationResponse | ||
| export interface LowerTierImageGenerationResponse { | ||
| prompt: string; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Complete the incomplete interface implementations.
The LowerTierImageGenerationRequest and LowerTierImageGenerationResponse interfaces are marked as TODOs and are incomplete. They don't match the complexity of their corresponding Zod schemas.
Apply this diff to properly implement the interfaces:
-// TODO: Implement interface LowerTierImageGenerationRequest
export interface LowerTierImageGenerationRequest {
prompt: string;
+ options?: {
+ model?: AIGenerationModel;
+ width?: number;
+ height?: number;
+ steps?: number;
+ disable_safety_checker?: boolean;
+ };
}
-// TODO: Implement interface LowerTierImageGenerationResponse
export interface LowerTierImageGenerationResponse {
- prompt: string;
+ imageUrl: string;
+ metadata?: {
+ model: string;
+ processingTime: number;
+ };
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // TODO: Implement interface LowerTierImageGenerationRequest | |
| export interface LowerTierImageGenerationRequest { | |
| prompt: string; | |
| } | |
| // TODO: Implement interface LowerTierImageGenerationResponse | |
| export interface LowerTierImageGenerationResponse { | |
| prompt: string; | |
| } | |
| export interface LowerTierImageGenerationRequest { | |
| prompt: string; | |
| options?: { | |
| model?: AIGenerationModel; | |
| width?: number; | |
| height?: number; | |
| steps?: number; | |
| disable_safety_checker?: boolean; | |
| }; | |
| } | |
| export interface LowerTierImageGenerationResponse { | |
| imageUrl: string; | |
| metadata?: { | |
| model: string; | |
| processingTime: number; | |
| }; | |
| } |
🤖 Prompt for AI Agents
In backend/src/modules/ai/types/generation.types.ts between lines 36 and 44, the
interfaces LowerTierImageGenerationRequest and LowerTierImageGenerationResponse
are incomplete and only contain a prompt string. Update these interfaces to
fully match the corresponding Zod schemas by adding all required properties and
types as defined in those schemas, ensuring the interfaces accurately represent
the expected data structure.
| /** | ||
| * TODO: Refactor this prompt later to be more structured and clear. | ||
| * | ||
| * Similar to the image generation prompt below, this one is also a bit | ||
| * scuffed in terms of how it handles user tiers. It should be handled | ||
| * in the service layer, not passed to the prompt for the AI to figure | ||
| * out whether to generate a high or low resolution image. | ||
| */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Address the architectural concern about user tier handling.
The TODO comments correctly identify that user tier handling should be moved from the prompt layer to the service layer. This is an important architectural decision that affects maintainability and separation of concerns.
The current approach of passing user tier information to the AI prompt creates tight coupling between business logic and AI prompts. Would you like me to help design a service layer solution that handles tier-based logic before prompt generation?
Let me verify how the current tier-based logic is implemented across the codebase:
Also applies to: 127-133
🏁 Script executed:
#!/bin/bash
# Description: Search for user tier handling patterns in the AI module
# Expected: Find current implementations that need refactoring
# Search for tier-related logic in AI services
rg -A 5 -B 5 "tier|Tier" backend/src/modules/ai/
# Search for prompt template usage
rg -A 3 "IMAGE_GENERATION_USER_PROMPT" backend/src/modules/ai/Length of output: 20995
Refactor user-tier logic out of AI prompts
The tier-based branching belongs in the service layer, not embedded in the prompt template. Move all “paid vs. free” resolution decisions into your image-generation services and supply only concrete values to the prompt.
• backend/src/modules/ai/config/prompts.ts
- Remove the
<user_tier>section and any “If paid, generate high-res… if free, generate standard-res…” text fromIMAGE_GENERATION_USER_PROMPT. - Replace with a generic
<resolution>{resolution}</resolution>placeholder and neutral instructions.
export const IMAGE_GENERATION_USER_PROMPT = `
Please generate an image based on the following description.
<image_description>
{description}
</image_description>
-<user_tier>
-{userTier}
-</user_tier>
-<instructions>
-If the user is a paid user, generate a high-resolution image with enhanced quality and detail.
-If the user is a free user, generate a standard resolution image.
-Ensure the image is appropriate and follows content guidelines.
-</instructions>
+<resolution>
+{resolution}
+</resolution>
+<instructions>
+Create an image that accurately represents the provided description, following all content guidelines.
+</instructions>
`;• backend/src/modules/ai/services/imagen/together.service.ts
• backend/src/modules/ai/services/imagen/google.service.ts
- In each
generate()implementation, branch onrequesttype (LowerTier… vs. HigherTier…) to compute aresolutionstring or width/height settings. - Pass this concrete
resolutioninto the prompt template (e.g.prompt.format({ description, resolution, … })) instead ofuserTier.
Optional improvement: Consolidate LowerTier/HigherTier schemas into a single ImageGenerationRequest with a tier enum and shared options, then centralize the tier→resolution mapping in one helper.
This separation will decouple business logic from prompt content and make future changes simpler.
🤖 Prompt for AI Agents
In backend/src/modules/ai/config/prompts.ts around lines 63 to 70, refactor the
IMAGE_GENERATION_USER_PROMPT by removing all user tier references and
conditional text about paid vs. free resolution. Replace these with a generic
resolution placeholder like <resolution>{resolution}</resolution> and neutral
instructions. Then, in
backend/src/modules/ai/services/imagen/together.service.ts and
google.service.ts, move the tier-based logic to the generate() methods by
branching on the request type to determine the concrete resolution string or
dimensions. Pass this resolved value into the prompt formatting instead of user
tier. Optionally, unify tier schemas and centralize tier-to-resolution mapping
in a helper to cleanly separate business logic from prompt content.
| <user_tier> | ||
| {userTier} | ||
| </user_tier> | ||
| Remember to maintain clarity and conciseness while capturing all essential information.`; | ||
| <instructions> | ||
| Create an image that accurately represents the provided description. If the user is a paid user, | ||
| generate a high-resolution image with enhanced quality and detail. If the user is a free user, | ||
| generate a standard resolution image. Ensure the image is appropriate and follows content guidelines. | ||
| </instructions>`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Remove hardcoded tier-based logic from the prompt.
The image generation user prompt contains hardcoded logic for handling paid vs free users, which violates separation of concerns and makes the system less flexible.
Apply this diff to remove tier-specific logic from the prompt:
export const IMAGE_GENERATION_USER_PROMPT = `
Please generate an image based on the following description and user requirements.
<image_description>
{description}
</image_description>
-<user_tier>
-{userTier}
-</user_tier>
<instructions>
-Create an image that accurately represents the provided description. If the user is a paid user,
-generate a high-resolution image with enhanced quality and detail. If the user is a free user,
-generate a standard resolution image. Ensure the image is appropriate and follows content guidelines.
+Create an image that accurately represents the provided description with the specified quality settings.
+Ensure the image is appropriate and follows content guidelines.
</instructions>`;The service layer should handle tier-based resolution and quality decisions before calling the AI service.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| <user_tier> | |
| {userTier} | |
| </user_tier> | |
| Remember to maintain clarity and conciseness while capturing all essential information.`; | |
| <instructions> | |
| Create an image that accurately represents the provided description. If the user is a paid user, | |
| generate a high-resolution image with enhanced quality and detail. If the user is a free user, | |
| generate a standard resolution image. Ensure the image is appropriate and follows content guidelines. | |
| </instructions>`; | |
| export const IMAGE_GENERATION_USER_PROMPT = ` | |
| Please generate an image based on the following description and user requirements. | |
| <image_description> | |
| {description} | |
| </image_description> | |
| <instructions> | |
| Create an image that accurately represents the provided description with the specified quality settings. | |
| Ensure the image is appropriate and follows content guidelines. | |
| </instructions>`; |
🤖 Prompt for AI Agents
In backend/src/modules/ai/config/prompts.ts around lines 141 to 149, the prompt
includes hardcoded logic differentiating image generation instructions based on
user tier, which breaks separation of concerns. Remove any tier-specific
conditions or instructions from the prompt text so it only contains generic
image generation instructions. Instead, ensure that the service layer outside
this prompt handles all decisions related to image resolution and quality based
on user tier before invoking the AI service.
| export interface ImageLora { | ||
| path?: string; | ||
| scale: number; | ||
| } | ||
|
|
||
| export interface GenerationModelConfig { | ||
| steps?: number; | ||
| width?: number; | ||
| height?: number; | ||
| n?: number; | ||
| responseFormat?: string; | ||
| image_loras?: ImageLora[]; | ||
| disableSafetyChecker?: boolean; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add validation constraints to GenerationModelConfig.
The GenerationModelConfig interface lacks validation constraints that could prevent invalid configurations.
Consider adding JSDoc comments with constraints and potentially using branded types:
export interface GenerationModelConfig {
+ /** Number of inference steps (typically 1-100) */
steps?: number;
+ /** Image width in pixels (must be positive, typically 256-2048) */
width?: number;
+ /** Image height in pixels (must be positive, typically 256-2048) */
height?: number;
+ /** Number of images to generate (typically 1-10) */
n?: number;
+ /** Response format (e.g., 'url', 'b64_json') */
responseFormat?: string;
image_loras?: ImageLora[];
disableSafetyChecker?: boolean;
}Consider creating Zod schemas for runtime validation of these configurations.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| export interface ImageLora { | |
| path?: string; | |
| scale: number; | |
| } | |
| export interface GenerationModelConfig { | |
| steps?: number; | |
| width?: number; | |
| height?: number; | |
| n?: number; | |
| responseFormat?: string; | |
| image_loras?: ImageLora[]; | |
| disableSafetyChecker?: boolean; | |
| } | |
| export interface ImageLora { | |
| path?: string; | |
| scale: number; | |
| } | |
| export interface GenerationModelConfig { | |
| /** Number of inference steps (typically 1-100) */ | |
| steps?: number; | |
| /** Image width in pixels (must be positive, typically 256-2048) */ | |
| width?: number; | |
| /** Image height in pixels (must be positive, typically 256-2048) */ | |
| height?: number; | |
| /** Number of images to generate (typically 1-10) */ | |
| n?: number; | |
| /** Response format (e.g., 'url', 'b64_json') */ | |
| responseFormat?: string; | |
| image_loras?: ImageLora[]; | |
| disableSafetyChecker?: boolean; | |
| } |
🤖 Prompt for AI Agents
In backend/src/modules/ai/types/models.types.ts between lines 46 and 59, the
GenerationModelConfig interface lacks validation constraints. Add JSDoc comments
specifying valid ranges or allowed values for each property to document
constraints clearly. Additionally, define branded types if needed to enforce
stricter typing. For runtime validation, create corresponding Zod schemas that
validate the shape and constraints of GenerationModelConfig objects before use.
NOTE: I would more than likely consider this a draft PR, still working on a couple fixes and making sure its ready for use.
Summary by CodeRabbit
New Features
Improvements
Bug Fixes
Chores