@posthog/ai 7.13.2 → 7.14.0
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/dist/anthropic/index.cjs +14 -1
- package/dist/anthropic/index.cjs.map +1 -1
- package/dist/anthropic/index.mjs +14 -1
- package/dist/anthropic/index.mjs.map +1 -1
- package/dist/gemini/index.cjs +79 -1
- package/dist/gemini/index.cjs.map +1 -1
- package/dist/gemini/index.d.ts +2 -1
- package/dist/gemini/index.mjs +79 -1
- package/dist/gemini/index.mjs.map +1 -1
- package/dist/index.cjs +145 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.mjs +145 -2
- package/dist/index.mjs.map +1 -1
- package/dist/langchain/index.cjs +38 -1
- package/dist/langchain/index.cjs.map +1 -1
- package/dist/langchain/index.d.ts +1 -0
- package/dist/langchain/index.mjs +38 -1
- package/dist/langchain/index.mjs.map +1 -1
- package/dist/openai/index.cjs +19 -2
- package/dist/openai/index.cjs.map +1 -1
- package/dist/openai/index.mjs +19 -2
- package/dist/openai/index.mjs.map +1 -1
- package/dist/vercel/index.cjs +20 -1
- package/dist/vercel/index.cjs.map +1 -1
- package/dist/vercel/index.mjs +20 -1
- package/dist/vercel/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/langchain/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as uuid from 'uuid';
|
|
2
2
|
import '@posthog/core';
|
|
3
3
|
|
|
4
|
-
var version = "7.
|
|
4
|
+
var version = "7.14.0";
|
|
5
5
|
|
|
6
6
|
// Type guards for safer type checking
|
|
7
7
|
|
|
@@ -965,6 +965,12 @@ class LangChainCallbackHandler extends BaseCallbackHandler {
|
|
|
965
965
|
eventProperties['$ai_web_search_count'] = additionalTokenData.webSearchCount;
|
|
966
966
|
}
|
|
967
967
|
|
|
968
|
+
// Extract stop reason from generation info
|
|
969
|
+
const stopReason = this._extractStopReason(output);
|
|
970
|
+
if (stopReason) {
|
|
971
|
+
eventProperties['$ai_stop_reason'] = stopReason;
|
|
972
|
+
}
|
|
973
|
+
|
|
968
974
|
// Handle generations/completions
|
|
969
975
|
let completions;
|
|
970
976
|
if (output.generations && Array.isArray(output.generations)) {
|
|
@@ -1100,6 +1106,37 @@ class LangChainCallbackHandler extends BaseCallbackHandler {
|
|
|
1100
1106
|
// Sanitize the message content to redact base64 images
|
|
1101
1107
|
return sanitizeLangChain(messageDict);
|
|
1102
1108
|
}
|
|
1109
|
+
_extractStopReason(output) {
|
|
1110
|
+
if (!output.generations || !Array.isArray(output.generations)) {
|
|
1111
|
+
return undefined;
|
|
1112
|
+
}
|
|
1113
|
+
const lastGeneration = output.generations[output.generations.length - 1];
|
|
1114
|
+
if (!Array.isArray(lastGeneration) || lastGeneration.length === 0) {
|
|
1115
|
+
return undefined;
|
|
1116
|
+
}
|
|
1117
|
+
const gen = lastGeneration[0];
|
|
1118
|
+
|
|
1119
|
+
// Check generationInfo for finish_reason (OpenAI format)
|
|
1120
|
+
if (gen.generationInfo?.finish_reason) {
|
|
1121
|
+
return String(gen.generationInfo.finish_reason);
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
// Check generationInfo for response_metadata.stop_reason (Anthropic format)
|
|
1125
|
+
if (gen.generationInfo?.response_metadata?.stop_reason) {
|
|
1126
|
+
return String(gen.generationInfo.response_metadata.stop_reason);
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
// Check message response_metadata for finish_reason (common LangChain format)
|
|
1130
|
+
if (gen.generationInfo?.response_metadata?.finish_reason) {
|
|
1131
|
+
return String(gen.generationInfo.response_metadata.finish_reason);
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1134
|
+
// Check for stop_reason directly in generationInfo
|
|
1135
|
+
if (gen.generationInfo?.stop_reason) {
|
|
1136
|
+
return String(gen.generationInfo.stop_reason);
|
|
1137
|
+
}
|
|
1138
|
+
return undefined;
|
|
1139
|
+
}
|
|
1103
1140
|
_parseUsageModel(usage, provider, model) {
|
|
1104
1141
|
const conversionList = [['promptTokens', 'input'], ['completionTokens', 'output'], ['input_tokens', 'input'], ['output_tokens', 'output'], ['prompt_token_count', 'input'], ['candidates_token_count', 'output'], ['inputTokenCount', 'input'], ['outputTokenCount', 'output'], ['input_token_count', 'input'], ['generated_token_count', 'output']];
|
|
1105
1142
|
const parsedUsage = conversionList.reduce((acc, [modelKey, typeKey]) => {
|