Skip to content

Commit ee3b6bc

Browse files
committed
remove caching related code
1 parent 7cfbcbd commit ee3b6bc

File tree

5 files changed

+0
-709
lines changed

5 files changed

+0
-709
lines changed

packages/ai-semantic-conventions/src/SemanticAttributes.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ export const SpanAttributes = {
3535
LLM_USAGE_COMPLETION_TOKENS: "gen_ai.usage.completion_tokens",
3636
LLM_USAGE_INPUT_TOKENS: ATTR_GEN_AI_USAGE_INPUT_TOKENS,
3737
LLM_USAGE_OUTPUT_TOKENS: ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,
38-
LLM_USAGE_CACHE_CREATION_INPUT_TOKENS:
39-
"gen_ai.usage.cache_creation_input_tokens",
40-
LLM_USAGE_CACHE_READ_INPUT_TOKENS: "gen_ai.usage.cache_read_input_tokens",
4138

4239
GEN_AI_AGENT_NAME: "gen_ai.agent.name",
4340

packages/traceloop-sdk/recordings/Test-AI-SDK-Integration-with-Recording_156038438/should-capture-and-transform-cache-tokens-from-OpenAI-with-prompt-caching_4027203422/recording.har

Lines changed: 0 additions & 330 deletions
This file was deleted.

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

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ const AI_PROMPT_MESSAGES = "ai.prompt.messages";
3232
const AI_PROMPT = "ai.prompt";
3333
const AI_USAGE_PROMPT_TOKENS = "ai.usage.promptTokens";
3434
const AI_USAGE_COMPLETION_TOKENS = "ai.usage.completionTokens";
35-
const AI_USAGE_CACHE_CREATION_INPUT_TOKENS =
36-
"ai.usage.cacheCreationInputTokens";
37-
const AI_USAGE_CACHE_READ_INPUT_TOKENS = "ai.usage.cacheReadInputTokens";
3835
const AI_MODEL_PROVIDER = "ai.model.provider";
3936
const AI_PROMPT_TOOLS = "ai.prompt.tools";
4037
const AI_TELEMETRY_METADATA_PREFIX = "ai.telemetry.metadata.";
@@ -378,26 +375,6 @@ const calculateTotalTokens = (attributes: Record<string, any>): void => {
378375
}
379376
};
380377

381-
const transformCacheCreationInputTokens = (
382-
attributes: Record<string, any>,
383-
): void => {
384-
if (AI_USAGE_CACHE_CREATION_INPUT_TOKENS in attributes) {
385-
attributes[SpanAttributes.LLM_USAGE_CACHE_CREATION_INPUT_TOKENS] =
386-
attributes[AI_USAGE_CACHE_CREATION_INPUT_TOKENS];
387-
delete attributes[AI_USAGE_CACHE_CREATION_INPUT_TOKENS];
388-
}
389-
};
390-
391-
const transformCacheReadInputTokens = (
392-
attributes: Record<string, any>,
393-
): void => {
394-
if (AI_USAGE_CACHE_READ_INPUT_TOKENS in attributes) {
395-
attributes[SpanAttributes.LLM_USAGE_CACHE_READ_INPUT_TOKENS] =
396-
attributes[AI_USAGE_CACHE_READ_INPUT_TOKENS];
397-
delete attributes[AI_USAGE_CACHE_READ_INPUT_TOKENS];
398-
}
399-
};
400-
401378
const transformVendor = (attributes: Record<string, any>): void => {
402379
if (AI_MODEL_PROVIDER in attributes) {
403380
const vendor = attributes[AI_MODEL_PROVIDER];
@@ -484,8 +461,6 @@ export const transformLLMSpans = (
484461
transformTools(attributes);
485462
transformPromptTokens(attributes);
486463
transformCompletionTokens(attributes);
487-
transformCacheCreationInputTokens(attributes);
488-
transformCacheReadInputTokens(attributes);
489464
calculateTotalTokens(attributes);
490465
transformVendor(attributes);
491466
transformTelemetryMetadata(attributes, spanName);

packages/traceloop-sdk/test/ai-sdk-integration.test.ts

Lines changed: 0 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -269,168 +269,4 @@ describe("Test AI SDK Integration with Recording", function () {
269269
assert.ok(outputMessages[0].parts[0].content);
270270
assert.ok(typeof outputMessages[0].parts[0].content === "string");
271271
});
272-
273-
it("should capture and transform cache tokens from OpenAI with prompt caching", async function () {
274-
this.timeout(30000);
275-
const basePrompt =
276-
"You are an expert AI assistant with comprehensive knowledge across numerous domains. " +
277-
"Your responses should be accurate, detailed, and thoughtful. " +
278-
"Always consider multiple perspectives and provide thorough explanations. " +
279-
"\n\n" +
280-
"## Guidelines for Different Domains:\n\n" +
281-
"### Mathematics\n" +
282-
"- Show all steps in your calculations\n" +
283-
"- Explain the reasoning behind each step\n" +
284-
"- Provide examples when helpful\n" +
285-
"- Double-check your arithmetic\n" +
286-
"\n" +
287-
"### Science\n" +
288-
"- Reference fundamental scientific principles\n" +
289-
"- Cite recent discoveries when relevant\n" +
290-
"- Explain complex concepts in accessible terms\n" +
291-
"- Distinguish between established facts and theories\n" +
292-
"\n" +
293-
"### History\n" +
294-
"- Consider broader historical context\n" +
295-
"- Present multiple viewpoints\n" +
296-
"- Acknowledge complexity and nuance\n" +
297-
"- Connect historical events to modern implications\n" +
298-
"\n" +
299-
"### Literature\n" +
300-
"- Analyze themes, symbolism, and motifs\n" +
301-
"- Examine character development\n" +
302-
"- Discuss literary devices and techniques\n" +
303-
"- Place works in their cultural and historical context\n" +
304-
"\n" +
305-
"### Technology\n" +
306-
"- Explain both practical applications and underlying concepts\n" +
307-
"- Discuss benefits and potential drawbacks\n" +
308-
"- Consider ethical implications\n" +
309-
"- Keep up with current developments\n" +
310-
"\n" +
311-
"### Philosophy\n" +
312-
"- Explore different schools of thought\n" +
313-
"- Present arguments fairly and objectively\n" +
314-
"- Examine ethical implications\n" +
315-
"- Connect philosophical concepts to real-world scenarios\n" +
316-
"\n";
317-
318-
const longSystemPrompt = basePrompt.repeat(30);
319-
320-
const result1 = await traceloop.withWorkflow(
321-
{ name: "test_cache_creation" },
322-
async () => {
323-
return await generateText({
324-
messages: [
325-
{ role: "system", content: longSystemPrompt },
326-
{ role: "user", content: "What is 2+2?" },
327-
],
328-
model: vercel_openai("gpt-4o-mini"),
329-
experimental_telemetry: { isEnabled: true },
330-
});
331-
},
332-
);
333-
334-
assert.ok(result1);
335-
assert.ok(result1.text);
336-
337-
await traceloop.forceFlush();
338-
const spans1 = memoryExporter.getFinishedSpans();
339-
const firstCallSpan = spans1.find((span) => span.name === "text.generate");
340-
341-
assert.ok(firstCallSpan);
342-
assert.ok(firstCallSpan.attributes[SpanAttributes.LLM_USAGE_INPUT_TOKENS]);
343-
assert.ok(firstCallSpan.attributes[SpanAttributes.LLM_USAGE_OUTPUT_TOKENS]);
344-
345-
assert.strictEqual(
346-
firstCallSpan.attributes["ai.usage.cachedInputTokens"],
347-
undefined,
348-
);
349-
assert.strictEqual(
350-
firstCallSpan.attributes["ai.usage.cacheCreationInputTokens"],
351-
undefined,
352-
);
353-
assert.strictEqual(
354-
firstCallSpan.attributes["ai.usage.cacheReadInputTokens"],
355-
undefined,
356-
);
357-
358-
if (
359-
firstCallSpan.attributes[
360-
SpanAttributes.LLM_USAGE_CACHE_CREATION_INPUT_TOKENS
361-
]
362-
) {
363-
assert.ok(
364-
Number(
365-
firstCallSpan.attributes[
366-
SpanAttributes.LLM_USAGE_CACHE_CREATION_INPUT_TOKENS
367-
],
368-
) > 0,
369-
"Cache creation tokens should be > 0",
370-
);
371-
}
372-
373-
memoryExporter.reset();
374-
375-
const result2 = await traceloop.withWorkflow(
376-
{ name: "test_cache_read" },
377-
async () => {
378-
return await generateText({
379-
messages: [
380-
{ role: "system", content: longSystemPrompt },
381-
{ role: "user", content: "What is 3+3?" },
382-
],
383-
model: vercel_openai("gpt-4o-mini"),
384-
experimental_telemetry: { isEnabled: true },
385-
});
386-
},
387-
);
388-
389-
assert.ok(result2);
390-
assert.ok(result2.text);
391-
392-
await traceloop.forceFlush();
393-
const spans2 = memoryExporter.getFinishedSpans();
394-
const secondCallSpan = spans2.find((span) => span.name === "text.generate");
395-
396-
assert.ok(secondCallSpan);
397-
assert.ok(secondCallSpan.attributes[SpanAttributes.LLM_USAGE_INPUT_TOKENS]);
398-
assert.ok(
399-
secondCallSpan.attributes[SpanAttributes.LLM_USAGE_OUTPUT_TOKENS],
400-
);
401-
402-
assert.strictEqual(
403-
secondCallSpan.attributes["ai.usage.cachedInputTokens"],
404-
undefined,
405-
);
406-
assert.strictEqual(
407-
secondCallSpan.attributes["ai.usage.cacheCreationInputTokens"],
408-
undefined,
409-
);
410-
assert.strictEqual(
411-
secondCallSpan.attributes["ai.usage.cacheReadInputTokens"],
412-
undefined,
413-
);
414-
415-
if (
416-
secondCallSpan.attributes[
417-
SpanAttributes.LLM_USAGE_CACHE_READ_INPUT_TOKENS
418-
]
419-
) {
420-
const cacheReadTokens = Number(
421-
secondCallSpan.attributes[
422-
SpanAttributes.LLM_USAGE_CACHE_READ_INPUT_TOKENS
423-
],
424-
);
425-
assert.ok(
426-
cacheReadTokens > 0,
427-
"Cache read tokens should be > 0 when cache is used",
428-
);
429-
assert.strictEqual(
430-
cacheReadTokens,
431-
6900,
432-
"Expected 6900 cache read tokens from recording",
433-
);
434-
}
435-
});
436272
});

0 commit comments

Comments
 (0)