@posthog/ai 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -32
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,56 +5,43 @@ Initial Typescript SDK for LLM Observability
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
|
|
8
|
+
npm install @posthog/ai
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
|
-
### Before
|
|
14
|
-
|
|
15
|
-
```typescript
|
|
16
|
-
import { OpenAI } from 'openai'
|
|
17
|
-
|
|
18
|
-
const client = new OpenAI({
|
|
19
|
-
apiKey: process.env.OPENAI_API_KEY || '',
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
await client.chat.completions.create({
|
|
23
|
-
model: 'gpt-4',
|
|
24
|
-
messages: [{ role: 'user', content: 'Hello, world!' }],
|
|
25
|
-
})
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
### After
|
|
29
|
-
|
|
30
13
|
```typescript
|
|
31
14
|
import { OpenAI } from '@posthog/ai'
|
|
32
15
|
import { PostHog } from 'posthog-node'
|
|
33
16
|
|
|
34
17
|
const phClient = new PostHog(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
})
|
|
18
|
+
'<YOUR_PROJECT_API_KEY>',
|
|
19
|
+
{ host: 'https://us.i.posthog.com' }
|
|
20
|
+
);
|
|
39
21
|
|
|
40
22
|
const client = new OpenAI({
|
|
41
|
-
apiKey:
|
|
23
|
+
apiKey: '<YOUR_OPENAI_API_KEY>',
|
|
42
24
|
posthog: phClient,
|
|
43
|
-
})
|
|
25
|
+
});
|
|
44
26
|
|
|
45
|
-
await client.chat.completions.create({
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
27
|
+
const completion = await client.chat.completions.create({
|
|
28
|
+
model: "gpt-3.5-turbo",
|
|
29
|
+
messages: [{ role: "user", content: "Tell me a fun fact about hedgehogs" }],
|
|
30
|
+
posthogDistinctId: "user_123", // optional
|
|
31
|
+
posthogTraceId: "trace_123", // optional
|
|
32
|
+
posthogProperties: { conversation_id: "abc123", paid: true }, //optional
|
|
33
|
+
posthogGroups: { company: "company_id_in_your_db" }, // optional
|
|
34
|
+
posthogPrivacyMode: false // optional
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
console.log(completion.choices[0].message.content)
|
|
53
38
|
|
|
54
39
|
// YOU HAVE TO HAVE THIS OR THE CLIENT MAY NOT SEND EVENTS
|
|
55
40
|
await phClient.shutdown()
|
|
56
41
|
```
|
|
57
42
|
|
|
43
|
+
LLM Observability [docs](https://posthog.com/docs/ai-engineering/observability)
|
|
44
|
+
|
|
58
45
|
Please see the main [PostHog docs](https://www.posthog.com/docs).
|
|
59
46
|
|
|
60
47
|
## Questions?
|