-
Notifications
You must be signed in to change notification settings - Fork 53
feat(llmo): Make it optional to pass posthog client
#291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
aad169c to
20a7b57
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Summary
This PR modifies all AI provider wrapper classes (OpenAI, Anthropic, and their variants) to make the posthog_client parameter optional in their constructors. Instead of requiring explicit client initialization, the wrappers now follow PostHog's standard pattern where if no client is provided, they automatically call posthog.setup() to initialize and use the default_client. The change affects all AI provider implementations including async versions.
This improvement aligns the AI wrappers with PostHog's core functionality pattern (like posthog.capture()), making the library more ergonomic while maintaining the flexibility to use custom clients when needed.
Confidence score: 5/5
- This PR is very safe to merge as it adds convenience without breaking existing functionality
- The implementation is consistent across all providers, uses proper type safety with cast(), and follows established PostHog patterns
- Key files that warrant attention:
- posthog/ai/openai/openai.py
- posthog/ai/anthropic/anthropic.py
- Corresponding async implementations
6 files reviewed, 3 comments
k11kirky
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Added to gemini as well, Realized i need to fix the docs as well and support this for node.
Avoiding wonky casts.
dcbd8ac to
8c16f3f
Compare
It's been inconvenient to have to explicitly pass a
posthog_clientto every AI provider wrapper. We should do what happens when you callposthogmethods likeposthog.capture()– runsetup()to init thedefault_clientand usedefault_client.This is what this PR introduces.