1.0.1 • Published 1 year ago
@posthog/posthog-ai v1.0.1
PostHog Node AI
Initial Typescript SDK for LLM Observability
Installation
yarn add @posthog/posthog-aiUsage
Before
import { OpenAI } from 'openai'
const client = new OpenAI({
apiKey: process.env.OPENAI_API_KEY || '',
})
await client.chat.completions.create({
model: 'gpt-4',
messages: [{ role: 'user', content: 'Hello, world!' }],
})After
import { OpenAI } from 'posthog-node-ai'
import { PostHog } from 'posthog-node'
const phClient = new PostHog(
process.env.POSTHOG_API_KEY, {
host: process.env.POSTHOG_HOST || 'https://us.posthog.com',
}
})
const client = new OpenAI({
apiKey: process.env.OPENAI_API_KEY || '',
posthog: phClient,
})
await client.chat.completions.create({
model: 'gpt-4',
messages: [{ role: 'user', content: 'Hello, world!' }],
posthog_distinct_id: 'test-user-id',
posthog_properties: {
test_property: 'test_value',
}
})
// YOU HAVE TO HAVE THIS OR THE CLIENT MAY NOT SEND EVENTS
await phClient.shutdown()Please see the main PostHog docs.