@posthog/ai 5.2.0 → 5.2.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/CHANGELOG.md +4 -0
- package/lib/index.cjs +12 -10
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.ts +21 -18
- package/lib/index.mjs +8 -5
- package/lib/index.mjs.map +1 -1
- package/lib/openai/index.cjs +8 -9
- package/lib/openai/index.cjs.map +1 -1
- package/lib/openai/index.d.ts +21 -18
- package/lib/openai/index.mjs +8 -5
- package/lib/openai/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/openai/index.ts +8 -4
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import OpenAIOrignal, { APIPromise, ClientOptions as ClientOptions$1, AzureOpenAI } from 'openai';
|
|
1
|
+
import OpenAIOrignal, { OpenAI, APIPromise, ClientOptions as ClientOptions$1, AzureOpenAI } from 'openai';
|
|
2
2
|
import { PostHog } from 'posthog-node';
|
|
3
3
|
import { Stream } from 'openai/streaming';
|
|
4
4
|
import { ParsedResponse } from 'openai/resources/responses/responses';
|
|
@@ -31,43 +31,46 @@ interface CostOverride {
|
|
|
31
31
|
outputCost: number;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
type
|
|
38
|
-
type
|
|
39
|
-
type
|
|
40
|
-
type
|
|
41
|
-
type
|
|
34
|
+
declare const Chat: typeof OpenAI.Chat;
|
|
35
|
+
declare const Completions: typeof OpenAI.Chat.Completions;
|
|
36
|
+
declare const Responses: typeof OpenAI.Responses;
|
|
37
|
+
type ChatCompletion$1 = OpenAI.ChatCompletion;
|
|
38
|
+
type ChatCompletionChunk$1 = OpenAI.ChatCompletionChunk;
|
|
39
|
+
type ChatCompletionCreateParamsBase$1 = OpenAI.Chat.Completions.ChatCompletionCreateParams;
|
|
40
|
+
type ChatCompletionCreateParamsNonStreaming$1 = OpenAI.Chat.Completions.ChatCompletionCreateParamsNonStreaming;
|
|
41
|
+
type ChatCompletionCreateParamsStreaming$1 = OpenAI.Chat.Completions.ChatCompletionCreateParamsStreaming;
|
|
42
|
+
type ResponsesCreateParamsBase = OpenAI.Responses.ResponseCreateParams;
|
|
43
|
+
type ResponsesCreateParamsNonStreaming = OpenAI.Responses.ResponseCreateParamsNonStreaming;
|
|
44
|
+
type ResponsesCreateParamsStreaming = OpenAI.Responses.ResponseCreateParamsStreaming;
|
|
42
45
|
interface MonitoringOpenAIConfig$1 extends ClientOptions$1 {
|
|
43
46
|
apiKey: string;
|
|
44
47
|
posthog: PostHog;
|
|
45
48
|
baseURL?: string;
|
|
46
49
|
}
|
|
47
50
|
type RequestOptions$1 = Record<string, any>;
|
|
48
|
-
declare class PostHogOpenAI extends
|
|
51
|
+
declare class PostHogOpenAI extends OpenAI {
|
|
49
52
|
private readonly phClient;
|
|
50
53
|
chat: WrappedChat$1;
|
|
51
54
|
responses: WrappedResponses;
|
|
52
55
|
constructor(config: MonitoringOpenAIConfig$1);
|
|
53
56
|
}
|
|
54
|
-
declare class WrappedChat$1 extends
|
|
57
|
+
declare class WrappedChat$1 extends Chat {
|
|
55
58
|
constructor(parentClient: PostHogOpenAI, phClient: PostHog);
|
|
56
59
|
completions: WrappedCompletions$1;
|
|
57
60
|
}
|
|
58
|
-
declare class WrappedCompletions$1 extends
|
|
61
|
+
declare class WrappedCompletions$1 extends Completions {
|
|
59
62
|
private readonly phClient;
|
|
60
|
-
constructor(client:
|
|
63
|
+
constructor(client: OpenAI, phClient: PostHog);
|
|
61
64
|
create(body: ChatCompletionCreateParamsNonStreaming$1 & MonitoringParams, options?: RequestOptions$1): APIPromise<ChatCompletion$1>;
|
|
62
65
|
create(body: ChatCompletionCreateParamsStreaming$1 & MonitoringParams, options?: RequestOptions$1): APIPromise<Stream<ChatCompletionChunk$1>>;
|
|
63
66
|
create(body: ChatCompletionCreateParamsBase$1 & MonitoringParams, options?: RequestOptions$1): APIPromise<ChatCompletion$1 | Stream<ChatCompletionChunk$1>>;
|
|
64
67
|
}
|
|
65
|
-
declare class WrappedResponses extends
|
|
68
|
+
declare class WrappedResponses extends Responses {
|
|
66
69
|
private readonly phClient;
|
|
67
|
-
constructor(client:
|
|
68
|
-
create(body: ResponsesCreateParamsNonStreaming & MonitoringParams, options?: RequestOptions$1): APIPromise<
|
|
69
|
-
create(body: ResponsesCreateParamsStreaming & MonitoringParams, options?: RequestOptions$1): APIPromise<Stream<
|
|
70
|
-
create(body: ResponsesCreateParamsBase & MonitoringParams, options?: RequestOptions$1): APIPromise<
|
|
70
|
+
constructor(client: OpenAI, phClient: PostHog);
|
|
71
|
+
create(body: ResponsesCreateParamsNonStreaming & MonitoringParams, options?: RequestOptions$1): APIPromise<OpenAI.Responses.Response>;
|
|
72
|
+
create(body: ResponsesCreateParamsStreaming & MonitoringParams, options?: RequestOptions$1): APIPromise<Stream<OpenAI.Responses.ResponseStreamEvent>>;
|
|
73
|
+
create(body: ResponsesCreateParamsBase & MonitoringParams, options?: RequestOptions$1): APIPromise<OpenAI.Responses.Response | Stream<OpenAI.Responses.ResponseStreamEvent>>;
|
|
71
74
|
parse<Params extends ResponsesCreateParamsBase, ParsedT = any>(body: Params & MonitoringParams, options?: RequestOptions$1): APIPromise<ParsedResponse<ParsedT>>;
|
|
72
75
|
}
|
|
73
76
|
|
package/lib/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { OpenAI, AzureOpenAI } from 'openai';
|
|
2
2
|
import * as uuid from 'uuid';
|
|
3
3
|
import { v4 } from 'uuid';
|
|
4
4
|
import { Buffer } from 'buffer';
|
|
@@ -181,7 +181,10 @@ const sendEventToPosthog = async ({
|
|
|
181
181
|
}
|
|
182
182
|
};
|
|
183
183
|
|
|
184
|
-
|
|
184
|
+
const Chat = OpenAI.Chat;
|
|
185
|
+
const Completions = Chat.Completions;
|
|
186
|
+
const Responses = OpenAI.Responses;
|
|
187
|
+
class PostHogOpenAI extends OpenAI {
|
|
185
188
|
constructor(config) {
|
|
186
189
|
const {
|
|
187
190
|
posthog,
|
|
@@ -193,13 +196,13 @@ class PostHogOpenAI extends OpenAIOrignal {
|
|
|
193
196
|
this.responses = new WrappedResponses$1(this, this.phClient);
|
|
194
197
|
}
|
|
195
198
|
}
|
|
196
|
-
class WrappedChat$1 extends
|
|
199
|
+
class WrappedChat$1 extends Chat {
|
|
197
200
|
constructor(parentClient, phClient) {
|
|
198
201
|
super(parentClient);
|
|
199
202
|
this.completions = new WrappedCompletions$1(parentClient, phClient);
|
|
200
203
|
}
|
|
201
204
|
}
|
|
202
|
-
class WrappedCompletions$1 extends
|
|
205
|
+
class WrappedCompletions$1 extends Completions {
|
|
203
206
|
constructor(client, phClient) {
|
|
204
207
|
super(client);
|
|
205
208
|
this.phClient = phClient;
|
|
@@ -342,7 +345,7 @@ class WrappedCompletions$1 extends OpenAIOrignal.Chat.Completions {
|
|
|
342
345
|
}
|
|
343
346
|
}
|
|
344
347
|
}
|
|
345
|
-
class WrappedResponses$1 extends
|
|
348
|
+
class WrappedResponses$1 extends Responses {
|
|
346
349
|
constructor(client, phClient) {
|
|
347
350
|
super(client);
|
|
348
351
|
this.phClient = phClient;
|