|
20 | 20 | extract_openai_tool_calls_from_chunk, |
21 | 21 | accumulate_openai_tool_calls, |
22 | 22 | ) |
| 23 | +from posthog.ai.sanitization import sanitize_openai, sanitize_openai_response |
23 | 24 | from posthog.client import Client as PostHogClient |
24 | 25 | from posthog import setup |
25 | 26 |
|
@@ -183,12 +184,15 @@ def _capture_streaming_event( |
183 | 184 | from posthog.ai.utils import capture_streaming_event |
184 | 185 |
|
185 | 186 | # Prepare standardized event data |
| 187 | + formatted_input = format_openai_streaming_input(kwargs, "responses") |
| 188 | + sanitized_input = sanitize_openai_response(formatted_input) |
| 189 | + |
186 | 190 | event_data = StreamingEventData( |
187 | 191 | provider="openai", |
188 | 192 | model=kwargs.get("model"), |
189 | 193 | base_url=str(self._client.base_url), |
190 | 194 | kwargs=kwargs, |
191 | | - formatted_input=format_openai_streaming_input(kwargs, "responses"), |
| 195 | + formatted_input=sanitized_input, |
192 | 196 | formatted_output=format_openai_streaming_output(output, "responses"), |
193 | 197 | usage_stats=standardize_openai_usage(usage_stats, "responses"), |
194 | 198 | latency=latency, |
@@ -397,12 +401,15 @@ def _capture_streaming_event( |
397 | 401 | from posthog.ai.utils import capture_streaming_event |
398 | 402 |
|
399 | 403 | # Prepare standardized event data |
| 404 | + formatted_input = format_openai_streaming_input(kwargs, "chat") |
| 405 | + sanitized_input = sanitize_openai(formatted_input) |
| 406 | + |
400 | 407 | event_data = StreamingEventData( |
401 | 408 | provider="openai", |
402 | 409 | model=kwargs.get("model"), |
403 | 410 | base_url=str(self._client.base_url), |
404 | 411 | kwargs=kwargs, |
405 | | - formatted_input=format_openai_streaming_input(kwargs, "chat"), |
| 412 | + formatted_input=sanitized_input, |
406 | 413 | formatted_output=format_openai_streaming_output(output, "chat", tool_calls), |
407 | 414 | usage_stats=standardize_openai_usage(usage_stats, "chat"), |
408 | 415 | latency=latency, |
@@ -474,7 +481,9 @@ def create( |
474 | 481 | "$ai_provider": "openai", |
475 | 482 | "$ai_model": kwargs.get("model"), |
476 | 483 | "$ai_input": with_privacy_mode( |
477 | | - self._client._ph_client, posthog_privacy_mode, kwargs.get("input") |
| 484 | + self._client._ph_client, |
| 485 | + posthog_privacy_mode, |
| 486 | + sanitize_openai_response(kwargs.get("input")), |
478 | 487 | ), |
479 | 488 | "$ai_http_status": 200, |
480 | 489 | "$ai_input_tokens": usage_stats.get("prompt_tokens", 0), |
|
0 commit comments