Skip to content

Commit 4c41388

Browse files
committed
Fix multiple stream_options
1 parent e502983 commit 4c41388

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

posthog/ai/providers/openai/openai.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ def _create_streaming(
8181
start_time = time.time()
8282
usage_stats: Dict[str, int] = {}
8383
accumulated_content = []
84-
stream_options = {"include_usage": True}
85-
response = self._client.chat.completions.create(**kwargs, stream_options=stream_options)
84+
if "stream_options" not in kwargs:
85+
kwargs["stream_options"] = {}
86+
kwargs["stream_options"]["include_usage"] = True
87+
response = super().create(**kwargs)
8688

8789
def generator():
8890
nonlocal usage_stats

posthog/ai/providers/openai/openai_async.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,10 @@ async def _create_streaming(
8282
start_time = time.time()
8383
usage_stats: Dict[str, int] = {}
8484
accumulated_content = []
85-
stream_options = {"include_usage": True}
86-
response = await self._client.chat.completions.create(**kwargs, stream_options=stream_options)
85+
if "stream_options" not in kwargs:
86+
kwargs["stream_options"] = {}
87+
kwargs["stream_options"]["include_usage"] = True
88+
response = await super().create(**kwargs)
8789

8890
async def async_generator():
8991
nonlocal usage_stats, accumulated_content

0 commit comments

Comments
 (0)