Width-threshold image selection
PixelVeranda puts image-candidate selection code into a Windows AI project conversation. Compare width thresholds and fallback choices with a compatible model endpoint, then inspect the code that decides which URL your own application will use.
import math
def image_candidate(candidates, width, ratio):
if type(width) is not int or not 1 <= width <= 10000 or type(ratio) not in (int, float) or not 0.25 <= ratio <= 8 or not math.isfinite(ratio):
raise ValueError("image.viewport")
if type(candidates) is not list or not 1 <= len(candidates) <= 64:
raise ValueError("image.candidates")
sizes, seen = [], set()
for pair in candidates:
if type(pair) not in (list, tuple) or len(pair) != 2:
raise ValueError("image.pair")
url, pixels = pair
if type(url) is not str or not 1 <= len(url) <= 2048 or any(ord(c) < 32 or ord(c) == 127 for c in url):
raise ValueError("image.url")
if type(pixels) is not int or not 1 <= pixels <= 100000 or pixels in seen:
raise ValueError("image.size")
seen.add(pixels)
sizes.append((pixels, url))
sizes.sort()
target = width*ratio
return next((url for pixels, url in sizes if pixels >= target), sizes[-1][1])
- Project
- Test exact thresholds and largest-candidate fallback, rejecting duplicate widths or invalid numbers without fetching the selected URL.
- Review before applying
- Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.
- Connection
- Base URL, credentials and a reachable server.
import math
def image_candidate(candidates, width, ratio):
if type(width) is not int or not 1 <= width <= 10000 or type(ratio) not in (int, float) or not 0.25 <= ratio <= 8 or not math.isfinite(ratio):
raise ValueError("image.viewport")
if type(candidates) is not list or not 1 <= len(candidates) <= 64:
raise ValueError("image.candidates")
sizes, seen = [], set()
for pair in candidates:
if type(pair) not in (list, tuple) or len(pair) != 2:
raise ValueError("image.pair")
url, pixels = pair
if type(url) is not str or not 1 <= len(url) <= 2048 or any(ord(c) < 32 or ord(c) == 127 for c in url):
raise ValueError("image.url")
if type(pixels) is not int or not 1 <= pixels <= 100000 or pixels in seen:
raise ValueError("image.size")
seen.add(pixels)
sizes.append((pixels, url))
sizes.sort()
target = width*ratio
return next((url for pixels, url in sizes if pixels >= target), sizes[-1][1])
Trace the selected image back to the requirements
An unexpected image URL can be the result of selection logic rather than a broken asset. PixelVeranda gives that investigation a Windows AI coding workspace. Open the project and ask the connected model to inspect candidate data, viewport inputs and the caller that uses the selected URL before proposing a change. Include the observed and expected choices.
For a concrete task, you could review code that chooses the first image wide enough for a requested display size and pixel ratio. Specify what should happen when no candidate is large enough and whether input candidates arrive sorted. Ask for a proposal that makes these decisions explicit rather than relying on convenient input ordering.
Check the patch with exact URL expectations. Run project tests around width thresholds, at the fallback boundary and with invalid candidate data. Inspect how the caller obtains viewport information and handles rejection, then exercise the affected page yourself. The selected URL is one part of image delivery; the proposal should not imply that choosing it proves the final rendered image meets every requirement.
PixelVeranda supports connections to OpenAI-compatible or Anthropic endpoints. Choose an uncensored AI model where available through your service, with context, restrictions and tools dependent on that setup. Keep selection requirements in the conversation and use your application’s results to judge the proposed edits.
Reviewing an image-selection change
What evidence helps explain the wrong candidate?
Provide candidate widths and URLs, the requested display width, pixel ratio and expected choice. Include the code that supplies those values. This makes it possible to distinguish selection logic from incorrect measurements or incomplete candidate data.
Should the function assume candidates are sorted?
Only if the input contract guarantees that order and callers enforce it. Ask the assistant to inspect the source of the list. Test an unsorted example when order is not guaranteed, and review any sorting introduced by the patch.
How should the no-large-enough case behave?
State the fallback policy explicitly, such as selecting the largest available candidate or reporting an error. Then check that exact case in the project. The model should not choose a policy merely because one branch is easier to write.
Does selecting a URL confirm browser delivery quality?
No. Verify the actual page as well as the function’s return value. Layout, measurement and asset availability can affect the result after selection. Keep function fixtures for precise logic and an application check for the user-visible outcome.
PixelVeranda · Updated 2026-10-25