Skip to content

Commit ad0afa6

Browse files
committed
prettier
1 parent 40c6ea4 commit ad0afa6

File tree

2 files changed

+136
-149
lines changed

2 files changed

+136
-149
lines changed

packages/traceloop-sdk/src/lib/tracing/ai-sdk-transformations.ts

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ export const transformAiSdkSpanName = (span: ReadableSpan): void => {
2222
}
2323
};
2424

25-
export const transformResponseText = (attributes: Record<string, any>): void => {
25+
export const transformResponseText = (
26+
attributes: Record<string, any>,
27+
): void => {
2628
if (AI_RESPONSE_TEXT in attributes) {
2729
attributes[`${SpanAttributes.LLM_COMPLETIONS}.0.content`] =
2830
attributes[AI_RESPONSE_TEXT];
@@ -31,35 +33,39 @@ export const transformResponseText = (attributes: Record<string, any>): void =>
3133
}
3234
};
3335

34-
export const transformPromptMessages = (attributes: Record<string, any>): void => {
36+
export const transformPromptMessages = (
37+
attributes: Record<string, any>,
38+
): void => {
3539
if (AI_PROMPT_MESSAGES in attributes) {
3640
try {
3741
const messages = JSON.parse(attributes[AI_PROMPT_MESSAGES] as string);
38-
messages.forEach(
39-
(msg: { role: string; content: any }, index: number) => {
40-
attributes[`${SpanAttributes.LLM_PROMPTS}.${index}.content`] =
41-
typeof msg.content === "string"
42-
? msg.content
43-
: JSON.stringify(msg.content);
44-
attributes[`${SpanAttributes.LLM_PROMPTS}.${index}.role`] = msg.role;
45-
},
46-
);
42+
messages.forEach((msg: { role: string; content: any }, index: number) => {
43+
attributes[`${SpanAttributes.LLM_PROMPTS}.${index}.content`] =
44+
typeof msg.content === "string"
45+
? msg.content
46+
: JSON.stringify(msg.content);
47+
attributes[`${SpanAttributes.LLM_PROMPTS}.${index}.role`] = msg.role;
48+
});
4749
delete attributes[AI_PROMPT_MESSAGES];
4850
} catch {
4951
// Skip if JSON parsing fails
5052
}
5153
}
5254
};
5355

54-
export const transformPromptTokens = (attributes: Record<string, any>): void => {
56+
export const transformPromptTokens = (
57+
attributes: Record<string, any>,
58+
): void => {
5559
if (AI_USAGE_PROMPT_TOKENS in attributes) {
5660
attributes[`${SpanAttributes.LLM_USAGE_PROMPT_TOKENS}`] =
5761
attributes[AI_USAGE_PROMPT_TOKENS];
5862
delete attributes[AI_USAGE_PROMPT_TOKENS];
5963
}
6064
};
6165

62-
export const transformCompletionTokens = (attributes: Record<string, any>): void => {
66+
export const transformCompletionTokens = (
67+
attributes: Record<string, any>,
68+
): void => {
6369
if (AI_USAGE_COMPLETION_TOKENS in attributes) {
6470
attributes[`${SpanAttributes.LLM_USAGE_COMPLETION_TOKENS}`] =
6571
attributes[AI_USAGE_COMPLETION_TOKENS];
@@ -69,7 +75,8 @@ export const transformCompletionTokens = (attributes: Record<string, any>): void
6975

7076
export const calculateTotalTokens = (attributes: Record<string, any>): void => {
7177
const promptTokens = attributes[`${SpanAttributes.LLM_USAGE_PROMPT_TOKENS}`];
72-
const completionTokens = attributes[`${SpanAttributes.LLM_USAGE_COMPLETION_TOKENS}`];
78+
const completionTokens =
79+
attributes[`${SpanAttributes.LLM_USAGE_COMPLETION_TOKENS}`];
7380

7481
if (promptTokens && completionTokens) {
7582
attributes[`${SpanAttributes.LLM_USAGE_TOTAL_TOKENS}`] =
@@ -89,7 +96,9 @@ export const transformVendor = (attributes: Record<string, any>): void => {
8996
}
9097
};
9198

92-
export const transformAiSdkAttributes = (attributes: Record<string, any>): void => {
99+
export const transformAiSdkAttributes = (
100+
attributes: Record<string, any>,
101+
): void => {
93102
transformResponseText(attributes);
94103
transformPromptMessages(attributes);
95104
transformPromptTokens(attributes);
@@ -101,4 +110,4 @@ export const transformAiSdkAttributes = (attributes: Record<string, any>): void
101110
export const transformAiSdkSpan = (span: ReadableSpan): void => {
102111
transformAiSdkSpanName(span);
103112
transformAiSdkAttributes(span.attributes);
104-
};
113+
};

0 commit comments

Comments
 (0)