Skip to content

Commit b931387

Browse files
committed
feat: export ChatCompletion, Response, ResponseUsage from openai.types
Fixes #2680 Added exports for major types from openai.types module for easier access: - ChatCompletion (from openai.types.chat) - Response (from openai.types.responses) - ResponseUsage (from openai.types.responses) This allows users to import these commonly used types directly: from openai.types import ChatCompletion, Response, ResponseUsage
1 parent f94256d commit b931387

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/openai/types/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
from .image import Image as Image
77
from .model import Model as Model
88
from .video import Video as Video
9+
from .chat import ChatCompletion as ChatCompletion
10+
from .responses import Response as Response
11+
from .responses import ResponseUsage as ResponseUsage
912
from .shared import (
1013
Metadata as Metadata,
1114
AllModels as AllModels,

tests/test_type_exports.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""Tests for type exports from openai.types.
2+
3+
Verifies that major types are exported from openai.types for easier access.
4+
Relates to issue #2680: Major types are not exposed in openai.types
5+
"""
6+
7+
import pytest
8+
9+
10+
class TestTypeExports:
11+
"""Test that major types are exported from openai.types."""
12+
13+
def test_chat_completion_exported(self) -> None:
14+
"""Verify ChatCompletion is exported from openai.types (fixes #2680)."""
15+
from openai.types import ChatCompletion
16+
from openai.types.chat import ChatCompletion as ChatCompletionOriginal
17+
18+
assert ChatCompletion is ChatCompletionOriginal
19+
20+
def test_response_exported(self) -> None:
21+
"""Verify Response is exported from openai.types (fixes #2680)."""
22+
from openai.types import Response
23+
from openai.types.responses import Response as ResponseOriginal
24+
25+
assert Response is ResponseOriginal
26+
27+
def test_response_usage_exported(self) -> None:
28+
"""Verify ResponseUsage is exported from openai.types (fixes #2680)."""
29+
from openai.types import ResponseUsage
30+
from openai.types.responses import ResponseUsage as ResponseUsageOriginal
31+
32+
assert ResponseUsage is ResponseUsageOriginal
33+
34+
def test_types_can_be_used_for_type_hints(self) -> None:
35+
"""Verify that imported types can be used for type hints."""
36+
from openai.types import ChatCompletion, Response, ResponseUsage
37+
38+
def process_chat_completion(completion: ChatCompletion) -> None:
39+
pass
40+
41+
def process_response(response: Response) -> None:
42+
pass
43+
44+
def process_usage(usage: ResponseUsage) -> None:
45+
pass
46+
47+
# If we get here without errors, the types work for hints
48+
assert True

0 commit comments

Comments
 (0)