A programming framework for agentic AI
FEAT: Add missing OpenAI-compatible models (GPT-4.5, Claude models) (#6120)
EeS2754eda6116c
diff --git a/python/packages/autogen-core/src/autogen_core/models/_model_client.py b/python/packages/autogen-core/src/autogen_core/models/_model_client.pyindex ab014ad45..efe8627b1 100644--- a/python/packages/autogen-core/src/autogen_core/models/_model_client.py+++ b/python/packages/autogen-core/src/autogen_core/models/_model_client.py@@ -18,6 +18,7 @@ class ModelFamily:This namespace class holds constants for the model families that AutoGen understands. Other families definitely exist and can be represented by a string, however, AutoGen will treat them as unknown."""+ GPT_45 = "gpt-45"GPT_4O = "gpt-4o"O1 = "o1"O3 = "o3"@@ -36,6 +37,7 @@ class ModelFamily:UNKNOWN = "unknown"ANY: TypeAlias = Literal[+ "gpt-45","gpt-4o","o1","o3",diff --git a/python/packages/autogen-ext/src/autogen_ext/models/openai/_model_info.py b/python/packages/autogen-ext/src/autogen_ext/models/openai/_model_info.pyindex 20a4177ff..c36ea42bf 100644--- a/python/packages/autogen-ext/src/autogen_ext/models/openai/_model_info.py+++ b/python/packages/autogen-ext/src/autogen_ext/models/openai/_model_info.py@@ -9,6 +9,7 @@ _MODEL_POINTERS = {"o1": "o1-2024-12-17","o1-preview": "o1-preview-2024-09-12","o1-mini": "o1-mini-2024-09-12",+ "gpt-4.5-preview": "gpt-4.5-preview-2025-02-27","gpt-4o": "gpt-4o-2024-08-06","gpt-4o-mini": "gpt-4o-mini-2024-07-18","gpt-4-turbo": "gpt-4-turbo-2024-04-09",@@ -17,6 +18,12 @@ _MODEL_POINTERS = {"gpt-4-32k": "gpt-4-32k-0613","gpt-3.5-turbo": "gpt-3.5-turbo-0125","gpt-3.5-turbo-16k": "gpt-3.5-turbo-16k-0613",+ "claude-3-haiku": "claude-3-haiku-20240307",+ "claude-3-sonnet": "claude-3-sonnet-20240229",+ "claude-3-opus": "claude-3-opus-20240229",+ "claude-3.5-haiku": "claude-3-5-haiku-20241022",+ "claude-3.5-sonnet": "claude-3-5-sonnet-20241022",+ "claude-3.7-sonnet": "claude-3-7-sonnet-20250219",}_MODEL_INFO: Dict[str, ModelInfo] = {@@ -48,6 +55,13 @@ _MODEL_INFO: Dict[str, ModelInfo] = {"family": ModelFamily.O1,"structured_output": False,},+ "gpt-4.5-preview-2025-02-27": {+ "vision": True,+ "function_calling": True,+ "json_output": True,+ "family": ModelFamily.GPT_45,+ "structured_output": True,+ },"gpt-4o-2024-11-20": {"vision": True,"function_calling": True,@@ -188,6 +202,48 @@ _MODEL_INFO: Dict[str, ModelInfo] = {"family": ModelFamily.GEMINI_2_0_FLASH,"structured_output": True,},+ "claude-3-haiku-20240307": {+ "vision": True,+ "function_calling": True,+ "json_output": False, # Update this when Anthropic supports structured output+ "family": ModelFamily.CLAUDE_3_HAIKU,+ "structured_output": False,+ },+ "claude-3-sonnet-20240229": {+ "vision": True,+ "function_calling": True,+ "json_output": False, # Update this when Anthropic supports structured output+ "family": ModelFamily.CLAUDE_3_SONNET,+ "structured_output": False,+ },+ "claude-3-opus-20240229": {+ "vision": True,+ "function_calling": True,+ "json_output": False, # Update this when Anthropic supports structured output+ "family": ModelFamily.CLAUDE_3_OPUS,+ "structured_output": False,+ },+ "claude-3-5-haiku-20241022": {+ "vision": True,+ "function_calling": True,+ "json_output": False, # Update this when Anthropic supports structured output+ "family": ModelFamily.CLAUDE_3_5_HAIKU,+ "structured_output": False,+ },+ "claude-3-5-sonnet-20241022": {+ "vision": True,+ "function_calling": True,+ "json_output": False, # Update this when Anthropic supports structured output+ "family": ModelFamily.CLAUDE_3_5_SONNET,+ "structured_output": False,+ },+ "claude-3-7-sonnet-20250219": {+ "vision": True,+ "function_calling": True,+ "json_output": False, # Update this when Anthropic supports structured output+ "family": ModelFamily.CLAUDE_3_7_SONNET,+ "structured_output": False,+ },}_MODEL_TOKEN_LIMITS: Dict[str, int] = {@@ -195,6 +251,7 @@ _MODEL_TOKEN_LIMITS: Dict[str, int] = {"o1-2024-12-17": 200000,"o1-preview-2024-09-12": 128000,"o1-mini-2024-09-12": 128000,+ "gpt-4.5-preview-2025-02-27": 128000,"gpt-4o-2024-11-20": 128000,"gpt-4o-2024-08-06": 128000,"gpt-4o-2024-05-13": 128000,@@ -214,9 +271,17 @@ _MODEL_TOKEN_LIMITS: Dict[str, int] = {"gemini-1.5-flash-8b": 1048576,"gemini-1.5-pro": 2097152,"gemini-2.0-flash": 1048576,+ "gemini-2.0-flash-lite-preview-02-05": 1048576,+ "claude-3-haiku-20240307": 50000,+ "claude-3-sonnet-20240229": 40000,+ "claude-3-opus-20240229": 20000,+ "claude-3-5-haiku-20241022": 50000,+ "claude-3-5-sonnet-20241022": 40000,+ "claude-3-7-sonnet-20250219": 20000,}GEMINI_OPENAI_BASE_URL = "https://generativelanguage.googleapis.com/v1beta/openai/"+ANTHROPIC_OPENAI_BASE_URL = "https://api.anthropic.com/v1/"def resolve_model(model: str) -> str:diff --git a/python/packages/autogen-ext/src/autogen_ext/models/openai/_openai_client.py b/python/packages/autogen-ext/src/autogen_ext/models/openai/_openai_client.pyindex d77c98eeb..f1bf51c44 100644--- a/python/packages/autogen-ext/src/autogen_ext/models/openai/_openai_client.py+++ b/python/packages/autogen-ext/src/autogen_ext/models/openai/_openai_client.py@@ -1408,6 +1408,11 @@ class OpenAIChatCompletionClient(BaseOpenAIChatCompletionClient, Component[OpenAcopied_args["base_url"] = _model_info.GEMINI_OPENAI_BASE_URLif "api_key" not in copied_args and "GEMINI_API_KEY" in os.environ:copied_args["api_key"] = os.environ["GEMINI_API_KEY"]+ if copied_args["model"].startswith("claude-"):+ if "base_url" not in copied_args:+ copied_args["base_url"] = _model_info.ANTHROPIC_OPENAI_BASE_URL+ if "api_key" not in copied_args and "ANTHROPIC_API_KEY" in os.environ:+ copied_args["api_key"] = os.environ["ANTHROPIC_API_KEY"]client = _openai_client_from_config(copied_args)create_args = _create_args_from_config(copied_args)