Skip to content

Refactor AI wrapper callback helpers#623

Merged
marandaneto merged 3 commits into
mainfrom
refactor/dedupe-ai-wrapper-callbacks
May 28, 2026
Merged

Refactor AI wrapper callback helpers#623
marandaneto merged 3 commits into
mainfrom
refactor/dedupe-ai-wrapper-callbacks

Conversation

@marandaneto
Copy link
Copy Markdown
Member

@marandaneto marandaneto commented May 24, 2026

💡 Motivation and Context

This refactors repeated AI wrapper and LangChain callback helper logic to make the code easier to maintain without changing behavior.

Changes:

  • Adds a shared OpenAIWrapperResource base class for OpenAI wrapper resources.
  • Updates sync and async OpenAI wrappers to reuse the shared fallback/delegation logic.
  • Adds small LangChain capture helper methods to centralize debug logging and run capture behavior.

💚 How did you test it?

Not run (refactor-only change).
found issues with https://github.com/marandaneto/dry4python

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran sampo add to generate a changeset file

@marandaneto marandaneto requested a review from a team as a code owner May 24, 2026 15:39
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 24, 2026

Reviews (1): Last reviewed commit: "refactor: deduplicate AI wrapper callbac..." | Re-trigger Greptile

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 24, 2026

posthog-python Compliance Report

Date: 2026-05-28 09:42:54 UTC
Duration: 176198ms

✅ All Tests Passed!

45/45 tests passed


Capture Tests

29/29 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields 519ms
Format Validation.Event Has Uuid 1508ms
Format Validation.Event Has Lib Properties 1507ms
Format Validation.Distinct Id Is String 1508ms
Format Validation.Token Is Present 1508ms
Format Validation.Custom Properties Preserved 1507ms
Format Validation.Event Has Timestamp 1508ms
Retry Behavior.Retries On 503 9520ms
Retry Behavior.Does Not Retry On 400 3506ms
Retry Behavior.Does Not Retry On 401 3508ms
Retry Behavior.Respects Retry After Header 9515ms
Retry Behavior.Implements Backoff 23536ms
Retry Behavior.Retries On 500 7501ms
Retry Behavior.Retries On 502 7513ms
Retry Behavior.Retries On 504 7518ms
Retry Behavior.Max Retries Respected 23519ms
Deduplication.Generates Unique Uuids 1508ms
Deduplication.Preserves Uuid On Retry 7512ms
Deduplication.Preserves Uuid And Timestamp On Retry 14521ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry 7510ms
Deduplication.No Duplicate Events In Batch 1508ms
Deduplication.Different Events Have Different Uuids 1507ms
Compression.Sends Gzip When Enabled 1507ms
Batch Format.Uses Proper Batch Structure 1508ms
Batch Format.Flush With No Events Sends Nothing 1005ms
Batch Format.Multiple Events Batched Together 1506ms
Error Handling.Does Not Retry On 403 3509ms
Error Handling.Does Not Retry On 413 3508ms
Error Handling.Retries On 408 7513ms

Feature_Flags Tests

16/16 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id 1006ms
Request Payload.Flags Request Uses V2 Query Param 1007ms
Request Payload.Flags Request Hits Flags Path Not Decide 1007ms
Request Payload.Flags Request Omits Authorization Header 1008ms
Request Payload.Token In Flags Body Matches Init 1007ms
Request Payload.Groups Round Trip 1007ms
Request Payload.Groups Default To Empty Object 1008ms
Request Payload.Person Properties Distinct Id Auto Populated When Caller Omits It 1007ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False 1007ms
Request Payload.Disable Geoip Omitted Defaults To False 1007ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key 1008ms
Request Lifecycle.No Flags Request On Init Alone 503ms
Request Lifecycle.No Flags Request On Normal Capture 1508ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests 1012ms
Request Lifecycle.Mock Response Value Is Returned To Caller 1003ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event 1509ms

@marandaneto
Copy link
Copy Markdown
Member Author

@PostHog/team-client-libraries review pls

Comment thread posthog/ai/openai/wrapper_utils.py Outdated
@marandaneto marandaneto requested a review from ioannisj May 28, 2026 09:39
@marandaneto marandaneto enabled auto-merge (squash) May 28, 2026 09:39
@marandaneto marandaneto merged commit b0726d1 into main May 28, 2026
27 of 28 checks passed
@marandaneto marandaneto deleted the refactor/dedupe-ai-wrapper-callbacks branch May 28, 2026 09:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants