feat/image-generation - #1078
Conversation
There was a problem hiding this comment.
Code Review
This pull request implements an image generation and iterative editing feature using Firebase AI. It introduces a React component (ImageGenerationView) for the UI and a service file (service.ts) to handle chat sessions, image generation, and multi-turn image editing with the Gemini model. The review feedback suggests adding a loading guard to prevent duplicate submissions, resolving an incomplete TODO comment, and improving the robustness of Base64 extraction from file uploads.
…ttened and lost; fix: missing `await` typo from official documentation snippets. Add: comment about memory accumulation
| prompt: string, | ||
| file?: File | ||
| ): Promise<ImageGenerationResult> { | ||
| const messagePayload: (string | Part)[] = [prompt]; |
There was a problem hiding this comment.
Quick tip on TypeScript style: you can omit the explicit (string | Part)[] type definition here. Since you're initializing the array inline with [prompt], TypeScript's type inference engine can infer that this is a string[].
As a general rule of thumb, letting the compiler infer types when initializing variables keeps our code cleaner and reduces boilerplate. We only need to explicitly write the type if we plan to push non-string Part objects into this array later in the execution flow.
There was a problem hiding this comment.
Thank you for this comment. Context for follow up question - I kept the explicit (string | Part) [] since I push a non-string object later in the same function. Specifically, messagePayload.push(awaitfileToGenerativePart(file)) a few lines down pushes a Part and not a string. I believe if I omit the annotation, ts would infer the string[] from [prompt] alone and that .push() call would fail to compile. Would your comment still apply? LMK what you think
Adds an image-generation feature to ai-samples, covering all 4 capabilities from the Firebase AI Logic docs: text-to-image, interleaved text + image, single-turn image editing, and iterative multi-turn editing via chat.