-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fix(images): Generate Non-Square Images #5626
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,9 @@ class GeneratedImage(BaseModel): | |
file_id: str | ||
url: str | ||
revised_prompt: str | ||
width: int | None = None | ||
height: int | None = None | ||
shape: str | None = None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Consider using an enum for shape values instead of string to maintain consistency with ImageShape enum used elsewhere in the codebase Prompt To Fix With AIThis is a comment left during a code review.
Path: backend/onyx/agents/agent_search/dr/sub_agents/image_generation/models.py
Line: 10:10
Comment:
**style:** Consider using an enum for shape values instead of string to maintain consistency with ImageShape enum used elsewhere in the codebase
How can I resolve this? If you propose a fix, please make it concise. |
||
|
||
|
||
# Needed for PydanticType | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,6 +72,9 @@ class ImageGenerationToolDelta(BaseObj): | |
|
||
class ImageGenerationToolHeartbeat(BaseObj): | ||
type: Literal["image_generation_tool_heartbeat"] = "image_generation_tool_heartbeat" | ||
shape: str | None = None | ||
width: int | None = None | ||
height: int | None = None | ||
Comment on lines
+75
to
+77
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Consider using the ImageShape enum from the tool implementation instead of Prompt To Fix With AIThis is a comment left during a code review.
Path: backend/onyx/server/query_and_chat/streaming_models.py
Line: 75:77
Comment:
**style:** Consider using the ImageShape enum from the tool implementation instead of `str | None` for the shape field to ensure type safety and consistency across the codebase
How can I resolve this? If you propose a fix, please make it concise. |
||
|
||
|
||
class CustomToolStart(BaseObj): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,21 @@ | ||
import { useState } from "react"; | ||
import { useMemo, useState } from "react"; | ||
import { FiDownload } from "react-icons/fi"; | ||
import { FullImageModal } from "./FullImageModal"; | ||
import { buildImgUrl } from "./utils"; | ||
|
||
export function InMessageImage({ fileId }: { fileId: string }) { | ||
type InMessageImageProps = { | ||
fileId: string; | ||
width?: number | null; | ||
height?: number | null; | ||
}; | ||
|
||
export function InMessageImage({ fileId, width, height }: InMessageImageProps) { | ||
const [fullImageShowing, setFullImageShowing] = useState(false); | ||
const [imageLoaded, setImageLoaded] = useState(false); | ||
const [naturalDimensions, setNaturalDimensions] = useState<{ | ||
width: number; | ||
height: number; | ||
} | null>(null); | ||
|
||
const handleDownload = async (e: React.MouseEvent) => { | ||
e.stopPropagation(); // Prevent opening the full image modal | ||
|
@@ -26,6 +36,20 @@ export function InMessageImage({ fileId }: { fileId: string }) { | |
} | ||
}; | ||
|
||
const resolvedDimensions = useMemo(() => { | ||
if (width && height) { | ||
return { width, height }; | ||
} | ||
if (naturalDimensions) { | ||
return naturalDimensions; | ||
} | ||
return null; | ||
}, [width, height, naturalDimensions]); | ||
|
||
const aspectRatio = resolvedDimensions | ||
? `${resolvedDimensions.width} / ${resolvedDimensions.height}` | ||
: "1 / 1"; | ||
|
||
return ( | ||
<> | ||
<FullImageModal | ||
|
@@ -34,7 +58,7 @@ export function InMessageImage({ fileId }: { fileId: string }) { | |
onOpenChange={(open) => setFullImageShowing(open)} | ||
/> | ||
|
||
<div className="relative w-full h-full max-w-96 max-h-96 group"> | ||
<div className="relative w-full max-w-96 group" style={{ aspectRatio }}> | ||
{!imageLoaded && ( | ||
<div className="absolute inset-0 bg-background-200 animate-pulse rounded-lg" /> | ||
)} | ||
|
@@ -43,16 +67,25 @@ export function InMessageImage({ fileId }: { fileId: string }) { | |
width={1200} | ||
height={1200} | ||
alt="Chat Message Image" | ||
onLoad={() => setImageLoaded(true)} | ||
onLoad={(event) => { | ||
setImageLoaded(true); | ||
if (!width || !height) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: The condition Prompt To Fix With AIThis is a comment left during a code review.
Path: web/src/app/chat/components/files/images/InMessageImage.tsx
Line: 72:72
Comment:
**logic:** The condition `!width || !height` could be problematic if one dimension is 0 but the other is valid. Consider using `!width && !height` or checking for falsy values more explicitly.
How can I resolve this? If you propose a fix, please make it concise. |
||
const { naturalWidth, naturalHeight } = event.currentTarget; | ||
if (naturalWidth && naturalHeight) { | ||
setNaturalDimensions({ | ||
width: naturalWidth, | ||
height: naturalHeight, | ||
}); | ||
} | ||
} | ||
}} | ||
className={` | ||
object-contain | ||
object-left | ||
overflow-hidden | ||
rounded-lg | ||
w-full | ||
h-full | ||
max-w-96 | ||
max-h-96 | ||
transition-opacity | ||
duration-300 | ||
cursor-pointer | ||
|
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.
logic: Type annotation inconsistency - run_kwargs is declared as
dict[str, str]
butimage_shape_enum.value
could be None, causing a type mismatch if shape is addedPrompt To Fix With AI