@posthog/ai 5.2.0 → 5.2.2
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 +8 -0
- package/lib/index.cjs +28 -13
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.ts +23 -19
- package/lib/index.mjs +24 -8
- package/lib/index.mjs.map +1 -1
- package/lib/langchain/index.cjs +16 -4
- package/lib/langchain/index.cjs.map +1 -1
- package/lib/langchain/index.d.ts +2 -1
- package/lib/langchain/index.mjs +16 -4
- package/lib/langchain/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/langchain/callbacks.ts +22 -4
- package/src/openai/index.ts +8 -4
- package/tests/callbacks.test.ts +48 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
# 5.2.2
|
|
2
|
+
|
|
3
|
+
- Add support for parsing tool calls from reasoning models in LangChain by converting the tool call format to the expected shape
|
|
4
|
+
|
|
5
|
+
# 5.2.1
|
|
6
|
+
|
|
7
|
+
- Fix crash when importing @posthog/ai with OpenAI SDK v5.x by deferring access to Chat, Completions, and Responses classes until runtime
|
|
8
|
+
|
|
1
9
|
# 5.2.0
|
|
2
10
|
|
|
3
11
|
- Fix anonymous events
|
package/lib/index.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var openai = require('openai');
|
|
6
6
|
var uuid = require('uuid');
|
|
7
7
|
var buffer = require('buffer');
|
|
8
8
|
var ai = require('ai');
|
|
@@ -29,7 +29,6 @@ function _interopNamespace(e) {
|
|
|
29
29
|
return Object.freeze(n);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
var OpenAIOrignal__default = /*#__PURE__*/_interopDefaultLegacy(OpenAIOrignal);
|
|
33
32
|
var uuid__namespace = /*#__PURE__*/_interopNamespace(uuid);
|
|
34
33
|
var AnthropicOriginal__default = /*#__PURE__*/_interopDefaultLegacy(AnthropicOriginal);
|
|
35
34
|
|
|
@@ -208,7 +207,10 @@ const sendEventToPosthog = async ({
|
|
|
208
207
|
}
|
|
209
208
|
};
|
|
210
209
|
|
|
211
|
-
|
|
210
|
+
const Chat = openai.OpenAI.Chat;
|
|
211
|
+
const Completions = Chat.Completions;
|
|
212
|
+
const Responses = openai.OpenAI.Responses;
|
|
213
|
+
class PostHogOpenAI extends openai.OpenAI {
|
|
212
214
|
constructor(config) {
|
|
213
215
|
const {
|
|
214
216
|
posthog,
|
|
@@ -220,13 +222,13 @@ class PostHogOpenAI extends OpenAIOrignal__default["default"] {
|
|
|
220
222
|
this.responses = new WrappedResponses$1(this, this.phClient);
|
|
221
223
|
}
|
|
222
224
|
}
|
|
223
|
-
class WrappedChat$1 extends
|
|
225
|
+
class WrappedChat$1 extends Chat {
|
|
224
226
|
constructor(parentClient, phClient) {
|
|
225
227
|
super(parentClient);
|
|
226
228
|
this.completions = new WrappedCompletions$1(parentClient, phClient);
|
|
227
229
|
}
|
|
228
230
|
}
|
|
229
|
-
class WrappedCompletions$1 extends
|
|
231
|
+
class WrappedCompletions$1 extends Completions {
|
|
230
232
|
constructor(client, phClient) {
|
|
231
233
|
super(client);
|
|
232
234
|
this.phClient = phClient;
|
|
@@ -369,7 +371,7 @@ class WrappedCompletions$1 extends OpenAIOrignal__default["default"].Chat.Comple
|
|
|
369
371
|
}
|
|
370
372
|
}
|
|
371
373
|
}
|
|
372
|
-
class WrappedResponses$1 extends
|
|
374
|
+
class WrappedResponses$1 extends Responses {
|
|
373
375
|
constructor(client, phClient) {
|
|
374
376
|
super(client);
|
|
375
377
|
this.phClient = phClient;
|
|
@@ -582,7 +584,7 @@ class WrappedResponses$1 extends OpenAIOrignal__default["default"].Responses {
|
|
|
582
584
|
}
|
|
583
585
|
}
|
|
584
586
|
|
|
585
|
-
class PostHogAzureOpenAI extends
|
|
587
|
+
class PostHogAzureOpenAI extends openai.AzureOpenAI {
|
|
586
588
|
constructor(config) {
|
|
587
589
|
const {
|
|
588
590
|
posthog,
|
|
@@ -593,13 +595,13 @@ class PostHogAzureOpenAI extends OpenAIOrignal.AzureOpenAI {
|
|
|
593
595
|
this.chat = new WrappedChat(this, this.phClient);
|
|
594
596
|
}
|
|
595
597
|
}
|
|
596
|
-
class WrappedChat extends
|
|
598
|
+
class WrappedChat extends openai.AzureOpenAI.Chat {
|
|
597
599
|
constructor(parentClient, phClient) {
|
|
598
600
|
super(parentClient);
|
|
599
601
|
this.completions = new WrappedCompletions(parentClient, phClient);
|
|
600
602
|
}
|
|
601
603
|
}
|
|
602
|
-
class WrappedCompletions extends
|
|
604
|
+
class WrappedCompletions extends openai.AzureOpenAI.Chat.Completions {
|
|
603
605
|
constructor(client, phClient) {
|
|
604
606
|
super(client);
|
|
605
607
|
this.phClient = phClient;
|
|
@@ -742,7 +744,7 @@ class WrappedCompletions extends OpenAIOrignal.AzureOpenAI.Chat.Completions {
|
|
|
742
744
|
}
|
|
743
745
|
}
|
|
744
746
|
}
|
|
745
|
-
class WrappedResponses extends
|
|
747
|
+
class WrappedResponses extends openai.AzureOpenAI.Responses {
|
|
746
748
|
constructor(client, phClient) {
|
|
747
749
|
super(client);
|
|
748
750
|
this.phClient = phClient;
|
|
@@ -2508,10 +2510,19 @@ class LangChainCallbackHandler extends BaseCallbackHandler {
|
|
|
2508
2510
|
}
|
|
2509
2511
|
return undefined;
|
|
2510
2512
|
}
|
|
2513
|
+
_convertLcToolCallsToOai(toolCalls) {
|
|
2514
|
+
return toolCalls.map(toolCall => ({
|
|
2515
|
+
type: 'function',
|
|
2516
|
+
id: toolCall.id,
|
|
2517
|
+
function: {
|
|
2518
|
+
name: toolCall.name,
|
|
2519
|
+
arguments: JSON.stringify(toolCall.args)
|
|
2520
|
+
}
|
|
2521
|
+
}));
|
|
2522
|
+
}
|
|
2511
2523
|
_convertMessageToDict(message) {
|
|
2512
2524
|
let messageDict = {};
|
|
2513
|
-
|
|
2514
|
-
const messageType = message._getType?.() || message.type;
|
|
2525
|
+
const messageType = message.getType();
|
|
2515
2526
|
switch (messageType) {
|
|
2516
2527
|
case 'human':
|
|
2517
2528
|
messageDict = {
|
|
@@ -2524,6 +2535,9 @@ class LangChainCallbackHandler extends BaseCallbackHandler {
|
|
|
2524
2535
|
role: 'assistant',
|
|
2525
2536
|
content: message.content
|
|
2526
2537
|
};
|
|
2538
|
+
if (message.tool_calls) {
|
|
2539
|
+
messageDict.tool_calls = this._convertLcToolCallsToOai(message.tool_calls);
|
|
2540
|
+
}
|
|
2527
2541
|
break;
|
|
2528
2542
|
case 'system':
|
|
2529
2543
|
messageDict = {
|
|
@@ -2545,9 +2559,10 @@ class LangChainCallbackHandler extends BaseCallbackHandler {
|
|
|
2545
2559
|
break;
|
|
2546
2560
|
default:
|
|
2547
2561
|
messageDict = {
|
|
2548
|
-
role: messageType
|
|
2562
|
+
role: messageType,
|
|
2549
2563
|
content: String(message.content)
|
|
2550
2564
|
};
|
|
2565
|
+
break;
|
|
2551
2566
|
}
|
|
2552
2567
|
if (message.additional_kwargs) {
|
|
2553
2568
|
messageDict = {
|