Skip to content

Commit 4b49d32

Browse files
ComeOnOliversjrl
authored andcommitted
Add SUPPORTED_MODELS to OpenAIResponsesChatGenerator (#10844)
Add a SUPPORTED_MODELS class variable listing supported models (gpt-5 series, gpt-4.1 series, gpt-4o series, o-series) to OpenAIResponsesChatGenerator, matching the pattern established in OpenAIChatGenerator (PR #10736). Also add a unit test verifying SUPPORTED_MODELS is a non-empty list of strings. Closes #10743
1 parent 6c995b9 commit 4b49d32

3 files changed

Lines changed: 35 additions & 3 deletions

File tree

haystack/components/generators/chat/openai.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import json
77
import os
88
from datetime import datetime
9-
from typing import Any
9+
from typing import Any, ClassVar
1010

1111
from openai import AsyncOpenAI, AsyncStream, OpenAI, Stream
1212
from openai.lib._pydantic import to_strict_json_schema
@@ -94,7 +94,7 @@ class OpenAIChatGenerator:
9494
```
9595
"""
9696

97-
SUPPORTED_MODELS = [
97+
SUPPORTED_MODELS: ClassVar[list[str]] = [
9898
"gpt-5-mini",
9999
"gpt-5-nano",
100100
"gpt-5",

haystack/components/generators/chat/openai_responses.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import json
66
import os
77
from datetime import datetime
8-
from typing import Any
8+
from typing import Any, ClassVar
99

1010
from openai import AsyncOpenAI, AsyncStream, OpenAI, Stream
1111
from openai.lib._pydantic import to_strict_json_schema
@@ -74,6 +74,31 @@ class OpenAIResponsesChatGenerator:
7474
```
7575
"""
7676

77+
SUPPORTED_MODELS: ClassVar[list[str]] = [
78+
"gpt-5-mini",
79+
"gpt-5-nano",
80+
"gpt-5",
81+
"gpt-5.1",
82+
"gpt-5.2",
83+
"gpt-5.2-pro",
84+
"gpt-5.4",
85+
"gpt-5-pro",
86+
"gpt-4.1",
87+
"gpt-4.1-mini",
88+
"gpt-4.1-nano",
89+
"gpt-4o",
90+
"gpt-4o-mini",
91+
"o1",
92+
"o1-mini",
93+
"o1-pro",
94+
"o3",
95+
"o3-mini",
96+
"o3-pro",
97+
"o4-mini",
98+
]
99+
"""A non-exhaustive list of chat models supported by this component.
100+
See https://platform.openai.com/docs/models for the full list and snapshot IDs."""
101+
77102
def __init__(
78103
self,
79104
*,

test/components/generators/chat/test_openai_responses.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ def __call__(self, chunk: StreamingChunk):
102102

103103

104104
class TestInitialization:
105+
def test_supported_models(self):
106+
"""SUPPORTED_MODELS is a non-empty list of strings."""
107+
models = OpenAIResponsesChatGenerator.SUPPORTED_MODELS
108+
assert isinstance(models, list)
109+
assert len(models) > 0
110+
assert all(isinstance(m, str) for m in models)
111+
105112
def test_init_default(self, monkeypatch):
106113
monkeypatch.setenv("OPENAI_API_KEY", "test-api-key")
107114
component = OpenAIResponsesChatGenerator()

0 commit comments

Comments
 (0)