モデル
OpenAI互換またはAnthropicのエンドポイントを、ベースURLと必要なAPIキーで設定し、接続をテストします。ローカルのモデルサーバーは起動が必要です。リモートツールは別途データを送信する場合があります。
image_candidate.pyをブラウザーの画像選択規則全体の模倣ではなく、明示した幅の方針として確認します。
OpenAI互換またはAnthropicのエンドポイントを、ベースURLと必要なAPIキーで設定し、接続をテストします。ローカルのモデルサーバーは起動が必要です。リモートツールは別途データを送信する場合があります。
フォルダーを選び、編集前に関連ファイルを読むようアシスタントに依頼します。作業の目的と変更範囲を明確にしてください。
変更内容とコマンド出力を確認します。結果を採用する前にプロジェクトの検証を実行してください。生成コードが自動的にテスト済みになるわけではありません。
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])