Skip to content

Commit

Permalink
bump and address comments (#352)
Browse files Browse the repository at this point in the history
  • Loading branch information
k11kirky authored Jan 21, 2025
1 parent 9ddb478 commit dbcffee
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
12 changes: 8 additions & 4 deletions posthog-ai/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@posthog/ai",
"version": "1.2.1",
"version": "1.3.0",
"description": "PostHog Node.js AI integrations",
"repository": {
"type": "git",
Expand All @@ -17,7 +17,9 @@
"jest": "^29.0.0",
"node-fetch": "^3.3.2",
"ts-jest": "^29.0.0",
"typescript": "^4.7.4"
"typescript": "^4.7.4",
"ai": "^4.0.0",
"openai": "^4.0.0"
},
"keywords": [
"posthog",
Expand All @@ -27,11 +29,13 @@
"llm"
],
"dependencies": {
"ai": "^4.1.0",
"openai": "^4.79.1",
"uuid": "^11.0.5",
"zod": "^3.24.1"
},
"peerDependencies": {
"ai": "^4.0.0",
"openai": "^4.0.0"
},
"scripts": {
"test": "jest",
"prepublishOnly": "cd .. && yarn build"
Expand Down
40 changes: 20 additions & 20 deletions posthog-ai/src/vercel/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import type { PostHog } from 'posthog-node'
import { sendEventToPosthog } from '../utils'

interface CreateInstrumentationMiddlewareOptions {
posthog_distinct_id?: string
posthog_trace_id: string
posthog_properties?: Record<string, any>
posthog_privacy_mode?: boolean
posthog_groups?: string[]
posthogDistinctId?: string
posthogTraceId: string
posthogProperties?: Record<string, any>
posthogPrivacyMode?: boolean
posthogGroups?: string[]
}

export const createInstrumentationMiddleware = (
Expand All @@ -31,11 +31,11 @@ export const createInstrumentationMiddleware = (

sendEventToPosthog({
client: phClient,
distinctId: options.posthog_distinct_id,
traceId: options.posthog_trace_id,
distinctId: options.posthogDistinctId,
traceId: options.posthogTraceId,
model: model.modelId,
provider: 'vercel',
input: options.posthog_privacy_mode ? '' : params.prompt,
input: options.posthogPrivacyMode ? '' : params.prompt,
output: [{ content: result.text, role: 'assistant' }],
latency,
baseURL: '',
Expand All @@ -51,11 +51,11 @@ export const createInstrumentationMiddleware = (
} catch (error) {
sendEventToPosthog({
client: phClient,
distinctId: options.posthog_distinct_id,
traceId: options.posthog_trace_id,
distinctId: options.posthogDistinctId,
traceId: options.posthogTraceId,
model: model.modelId,
provider: 'vercel',
input: options.posthog_privacy_mode ? '' : params.prompt,
input: options.posthogPrivacyMode ? '' : params.prompt,
output: [],
latency: 0,
baseURL: '',
Expand Down Expand Up @@ -96,11 +96,11 @@ export const createInstrumentationMiddleware = (
const latency = (Date.now() - startTime) / 1000
sendEventToPosthog({
client: phClient,
distinctId: options.posthog_distinct_id,
traceId: options.posthog_trace_id,
distinctId: options.posthogDistinctId,
traceId: options.posthogTraceId,
model: model.modelId,
provider: 'vercel',
input: options.posthog_privacy_mode ? '' : params.prompt,
input: options.posthogPrivacyMode ? '' : params.prompt,
output: [{ content: generatedText, role: 'assistant' }],
latency,
baseURL: '',
Expand All @@ -118,11 +118,11 @@ export const createInstrumentationMiddleware = (
} catch (error) {
sendEventToPosthog({
client: phClient,
distinctId: options.posthog_distinct_id,
traceId: options.posthog_trace_id,
distinctId: options.posthogDistinctId,
traceId: options.posthogTraceId,
model: model.modelId,
provider: 'vercel',
input: options.posthog_privacy_mode ? '' : params.prompt,
input: options.posthogPrivacyMode ? '' : params.prompt,
output: [],
latency: 0,
baseURL: '',
Expand All @@ -146,11 +146,11 @@ export const wrapVercelLanguageModel = (
phClient: PostHog,
options: CreateInstrumentationMiddlewareOptions
): LanguageModelV1 => {
const traceId = options.posthog_trace_id ?? uuidv4()
const traceId = options.posthogTraceId ?? uuidv4()
const middleware = createInstrumentationMiddleware(phClient, model, {
...options,
posthog_trace_id: traceId,
posthog_distinct_id: options.posthog_distinct_id ?? traceId,
posthogTraceId: traceId,
posthogDistinctId: options.posthogDistinctId ?? traceId,
})

const wrappedModel = wrapLanguageModel({
Expand Down

0 comments on commit dbcffee

Please sign in to comment.