Mô hình
Cấu hình endpoint tương thích OpenAI hoặc Anthropic bằng URL cơ sở và khóa API nếu cần. Kiểm tra kết nối. Máy chủ mô hình cục bộ phải đang chạy; công cụ từ xa có thể truyền dữ liệu riêng.
Xem image_candidate.py như một chính sách chiều rộng rõ ràng, không phải mô phỏng mọi quy tắc chọn ảnh của trình duyệt.
Cấu hình endpoint tương thích OpenAI hoặc Anthropic bằng URL cơ sở và khóa API nếu cần. Kiểm tra kết nối. Máy chủ mô hình cục bộ phải đang chạy; công cụ từ xa có thể truyền dữ liệu riêng.
Chọn thư mục và yêu cầu trợ lý đọc các tệp liên quan trước khi chỉnh sửa. Xác định mục tiêu và giới hạn của tác vụ.
Xem lại thay đổi và đầu ra lệnh. Chạy kiểm tra dự án trước khi chấp nhận kết quả; mã được tạo không mặc nhiên đã qua kiểm thử.
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])