5.1.0 • Published 5 months ago

@posthog/ai v5.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

PostHog Node AI

Initial Typescript SDK for LLM Observability

SEE FULL DOCS

Installation

npm install @posthog/ai

Usage

import { OpenAI } from '@posthog/ai'
import { PostHog } from 'posthog-node'

const phClient = new PostHog('<YOUR_PROJECT_API_KEY>', { host: 'https://us.i.posthog.com' })

const client = new OpenAI({
  apiKey: '<YOUR_OPENAI_API_KEY>',
  posthog: phClient,
})

const completion = await client.chat.completions.create({
  model: 'gpt-3.5-turbo',
  messages: [{ role: 'user', content: 'Tell me a fun fact about hedgehogs' }],
  posthogDistinctId: 'user_123', // optional
  posthogTraceId: 'trace_123', // optional
  posthogProperties: { conversation_id: 'abc123', paid: true }, //optional
  posthogGroups: { company: 'company_id_in_your_db' }, // optional
  posthogPrivacyMode: false, // optional
})

console.log(completion.choices[0].message.content)

// YOU HAVE TO HAVE THIS OR THE CLIENT MAY NOT SEND EVENTS
await phClient.shutdown()

LLM Observability docs

Please see the main PostHog docs.

Questions?

Check out our community page.

5.1.0

5 months ago

5.0.1

5 months ago

5.0.0

6 months ago

4.4.0

6 months ago

4.3.2

6 months ago

4.3.1

7 months ago

4.3.0

7 months ago

4.2.1

7 months ago

4.2.0

7 months ago

4.1.0

7 months ago

4.0.1

7 months ago

4.0.0

7 months ago

3.3.2

8 months ago

3.3.1

8 months ago

3.3.0

8 months ago

3.2.1

9 months ago

3.2.0

9 months ago

3.1.1

9 months ago

3.1.0

9 months ago

3.0.0

9 months ago

2.4.0

10 months ago

2.3.1

10 months ago

2.3.0

10 months ago

2.2.0

10 months ago

2.1.2

10 months ago

2.1.1

10 months ago

2.1.0

10 months ago

2.0.1

10 months ago

2.0.0

10 months ago

1.6.0

10 months ago

1.5.0

10 months ago

1.4.0

10 months ago

1.3.0

10 months ago

1.2.1

10 months ago

1.2.0

10 months ago

1.0.1

10 months ago