Skip to content

Conversation

cameronaziz
Copy link

@cameronaziz cameronaziz commented Aug 29, 2025

Problem

Currently, when sending events to PostHog for Gemini API calls, the system instructions are not included in the input data that gets tracked.

Changes

  • Added system instruction parsing: Created new parseGeminiSystemInstruction function to parse various system instruction formats into standardized PostHog event format
  • Added utility function: Created getPartText helper function to safely extract text content from various part formats
  • Updated all tracking calls: Modified all sendEventToPostHog calls in Gemini implementation to pass system instructions
  • Enhanced PostHog tracking: Modified formatInputForPostHog to accept and include system instructions in the input data sent to PostHog

Release info Sub-libraries affected

Libraries affected

  • All of them
  • posthog-js (web)
  • posthog-js-lite (web lite)
  • posthog-node
  • posthog-react-native
  • @posthog/react
  • @posthog/ai
  • @posthog/nextjs-config

Checklist

  • Tests for new code
  • Accounted for the impact of any changes across different platforms
  • Accounted for backwards compatibility of any changes (no breaking changes!)
  • Took care not to unnecessarily increase the bundle size

If releasing new changes

  • Ran pnpm changeset to generate a changeset file
  • Added the "release" label to the PR to indicate we're publishing new versions for the affected packages

Copy link

vercel bot commented Aug 29, 2025

@cameronaziz is attempting to deploy a commit to the PostHog Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 files reviewed, 4 comments

Edit Code Review Bot Settings | Greptile

Comment on lines 566 to 567
describe('parseGeminiSystemInstruction', () => {
describe('parseGeminiSystemInstruction', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Duplicate nested describe blocks - the outer one is redundant

Suggested change
describe('parseGeminiSystemInstruction', () => {
describe('parseGeminiSystemInstruction', () => {
describe('parseGeminiSystemInstruction', () => {

Comment on lines 574 to 582
it('should filter out empty strings but keep non-empty ones', () => {
const instructions = ['', 'Valid instruction', ' ', 'Another valid']
const result = parseGeminiSystemInstruction(instructions)
expect(result).toEqual([
{ role: 'system', content: 'Valid instruction' },
{ role: 'system', content: ' ' },
{ role: 'system', content: 'Another valid' },
])
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Test behavior differs from description - whitespace-only strings (' ') are kept, contradicting 'filter out empty strings'

Comment on lines 268 to 269
const result = []
for (const instruction of systemInstruction) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider declaring explicit type for result array as Array<{ role: string; content: string }> to improve type safety

Suggested change
const result = []
for (const instruction of systemInstruction) {
const result: Array<{ role: string; content: string }> = []
for (const instruction of systemInstruction) {

Comment on lines 281 to 282
const result = []
for (const part of parts) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider declaring explicit type for result array as Array<{ role: string; content: string }> to improve type safety

Suggested change
const result = []
for (const part of parts) {
const result: Array<{ role: string; content: string }> = []
for (const part of parts) {

@cameronaziz cameronaziz changed the title Support Gemini System Instructions feat(llma)/Support Gemini System Instructions Aug 29, 2025
@cameronaziz cameronaziz changed the title feat(llma)/Support Gemini System Instructions feat(llma): Support Gemini System Instructions Aug 29, 2025
@posthog-bot
Copy link
Collaborator

This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in another week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants