Skip to content

refactor: Share LLM response property construction - #188

Open
marandaneto wants to merge 1 commit into
mainfrom
refactor/dedupe-llm-response-properties
Open

refactor: Share LLM response property construction#188
marandaneto wants to merge 1 commit into
mainfrom
refactor/dedupe-llm-response-properties

Conversation

@marandaneto

Copy link
Copy Markdown
Member

💡 Motivation and Context

The OpenAI Responses, OpenAI Chat Completions, Gemini, and Anthropic parsers each built the same core LLM analytics response properties. Keeping those maps separate makes it easy for the provider implementations to drift when the shared properties change.

This refactor moves the shared successful-response map into one private function. Each provider still owns its response matching, token extraction, and additional properties.

💚 How did you test it?

  • mix test test/posthog/integrations/llm_analytics/req_test.exs
  • mix test
  • mix credo --strict
  • mix format --check-formatted lib/posthog/integrations/llm_analytics/req.ex

📝 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

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Pi coding agent and Slopo were used to identify and refactor the duplicated response-property maps. The refactor was limited to successful response map construction because provider-specific parsing remains clearer in each response clause. Pi autoreview found no actionable issues in the final commit.

@marandaneto marandaneto self-assigned this Aug 22, 2026
@marandaneto
marandaneto marked this pull request as ready for review August 22, 2026 12:18
@marandaneto
marandaneto requested a review from a team as a code owner August 22, 2026 12:18
@marandaneto
marandaneto requested a review from a team August 22, 2026 12:18
@github-actions

Copy link
Copy Markdown
Contributor

posthog-elixir Compliance Report

Date: 2026-08-22 12:21:38 UTC
Duration: 117322ms

✅ All Tests Passed!

46/46 tests passed


Capture Tests

29/29 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields 607ms
Format Validation.Event Has Uuid 608ms
Format Validation.Event Has Lib Properties 608ms
Format Validation.Distinct Id Is String 607ms
Format Validation.Token Is Present 608ms
Format Validation.Custom Properties Preserved 606ms
Format Validation.Event Has Timestamp 608ms
Retry Behavior.Retries On 503 5612ms
Retry Behavior.Does Not Retry On 400 2608ms
Retry Behavior.Does Not Retry On 401 2608ms
Retry Behavior.Respects Retry After Header 5611ms
Retry Behavior.Implements Backoff 15619ms
Retry Behavior.Retries On 500 5612ms
Retry Behavior.Retries On 502 5612ms
Retry Behavior.Retries On 504 5612ms
Retry Behavior.Max Retries Respected 15612ms
Deduplication.Generates Unique Uuids 614ms
Deduplication.Preserves Uuid On Retry 5610ms
Deduplication.Preserves Uuid And Timestamp On Retry 10617ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry 5613ms
Deduplication.No Duplicate Events In Batch 610ms
Deduplication.Different Events Have Different Uuids 608ms
Compression.Sends Gzip When Enabled 606ms
Batch Format.Uses Proper Batch Structure 606ms
Batch Format.Flush With No Events Sends Nothing 604ms
Batch Format.Multiple Events Batched Together 609ms
Error Handling.Does Not Retry On 403 2607ms
Error Handling.Does Not Retry On 413 2608ms
Error Handling.Retries On 408 5612ms

Feature_Flags Tests

17/17 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id 607ms
Request Payload.Flags Request Uses V2 Query Param 605ms
Request Payload.Flags Request Hits Flags Path Not Decide 605ms
Request Payload.Flags Request Omits Authorization Header 605ms
Request Payload.Token In Flags Body Matches Init 605ms
Request Payload.Groups Round Trip 605ms
Request Payload.Groups Default To Empty Object 605ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False 605ms
Request Payload.Disable Geoip Omitted Defaults To False 605ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key 605ms
Request Lifecycle.No Flags Request On Init Alone 3ms
Request Lifecycle.No Flags Request On Normal Capture 605ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests 1210ms
Request Lifecycle.Mock Response Value Is Returned To Caller 607ms
Retry Behavior.Retries Flags On 502 907ms
Retry Behavior.Retries Flags On 504 908ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event 1207ms

@greptile-apps

greptile-apps Bot commented Aug 22, 2026

Copy link
Copy Markdown

Reviews (1): Last reviewed commit: "refactor: deduplicate LLM response prope..." | Re-trigger Greptile

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