Switch to gpt-4-vision-preview if baseurl.host includes api.openai.com/ and gpt-4, otherwise strip out any image_url messages.

This commit is contained in:
Joshua Vial 2023-12-11 20:56:20 +13:00
parent b7d90197a9
commit 3d8599617d

View file

@ -42,6 +42,7 @@ def send_with_retries(client, model_name, messages, functions, stream):
kwargs["functions"] = functions
# Check conditions to switch to gpt-4-vision-preview
# TODO if baseurl.host does include api.openai.com/ and gpt-4 then switch the models, if it doesn't then strip out any image_url messages
if client and client.base_url.host != "openrouter.ai" and model_name.startswith("gpt-4"):
if any(isinstance(msg.get("content"), list) and any("image_url" in item for item in msg.get("content") if isinstance(item, dict)) for msg in messages):
kwargs['model'] = "gpt-4-vision-preview"