Skip to content

Refactor AI wrapper callback helpers#623

Open
marandaneto wants to merge 1 commit into
mainfrom
refactor/dedupe-ai-wrapper-callbacks
Open

Refactor AI wrapper callback helpers#623
marandaneto wants to merge 1 commit 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

posthog-python Compliance Report

Date: 2026-05-24 15:43:24 UTC
Duration: 176091ms

✅ All Tests Passed!

45/45 tests passed


Capture Tests

29/29 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields 517ms
Format Validation.Event Has Uuid 1507ms
Format Validation.Event Has Lib Properties 1506ms
Format Validation.Distinct Id Is String 1505ms
Format Validation.Token Is Present 1505ms
Format Validation.Custom Properties Preserved 1506ms
Format Validation.Event Has Timestamp 1507ms
Retry Behavior.Retries On 503 9516ms
Retry Behavior.Does Not Retry On 400 3504ms
Retry Behavior.Does Not Retry On 401 3507ms
Retry Behavior.Respects Retry After Header 9509ms
Retry Behavior.Implements Backoff 23518ms
Retry Behavior.Retries On 500 7510ms
Retry Behavior.Retries On 502 7510ms
Retry Behavior.Retries On 504 7514ms
Retry Behavior.Max Retries Respected 23524ms
Deduplication.Generates Unique Uuids 1496ms
Deduplication.Preserves Uuid On Retry 7513ms
Deduplication.Preserves Uuid And Timestamp On Retry 14517ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry 7506ms
Deduplication.No Duplicate Events In Batch 1506ms
Deduplication.Different Events Have Different Uuids 1505ms
Compression.Sends Gzip When Enabled 1506ms
Batch Format.Uses Proper Batch Structure 1507ms
Batch Format.Flush With No Events Sends Nothing 1005ms
Batch Format.Multiple Events Batched Together 1505ms
Error Handling.Does Not Retry On 403 3509ms
Error Handling.Does Not Retry On 413 3507ms
Error Handling.Retries On 408 7514ms

Feature_Flags Tests

16/16 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id 1003ms
Request Payload.Flags Request Uses V2 Query Param 1006ms
Request Payload.Flags Request Hits Flags Path Not Decide 1007ms
Request Payload.Flags Request Omits Authorization Header 1007ms
Request Payload.Token In Flags Body Matches Init 1007ms
Request Payload.Groups Round Trip 1006ms
Request Payload.Groups Default To Empty Object 1007ms
Request Payload.Person Properties Distinct Id Auto Populated When Caller Omits It 1007ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False 1005ms
Request Payload.Disable Geoip Omitted Defaults To False 1007ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key 1006ms
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 1009ms
Request Lifecycle.Mock Response Value Is Returned To Caller 1001ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event 1507ms

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.

1 participant