Skip to content

Commit d1587ed

Browse files
committed
fix test
1 parent 23eae01 commit d1587ed

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

js/packages/openinference-instrumentation-langchain/src/utils.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ function formatIO({
144144
if (values.length === 1 && typeof values[0] === "string") {
145145
return {
146146
[valueAttribute]: values[0],
147-
[mimeTypeAttribute]: MimeType.TEXT,
147+
[mimeTypeAttribute]: isJSONString(values[0])
148+
? MimeType.JSON
149+
: MimeType.TEXT,
148150
};
149151
}
150152

@@ -495,6 +497,13 @@ function formatPromptTemplate(run: Run): PromptTemplateAttributes | null {
495497
function getTokenCount(maybeCount: unknown) {
496498
return isNumber(maybeCount) ? maybeCount : undefined;
497499
}
500+
/**
501+
* A simple function that determines if a string is JSON like
502+
* Note this is a rough check just to set the MIME type
503+
*/
504+
function isJSONString(str: string) {
505+
return str.startsWith("{") && str.endsWith("}");
506+
}
498507

499508
/**
500509
* Formats the token counts of a langchain run into OpenInference attributes.

js/packages/openinference-instrumentation-langchain/test/langchainV3.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -541,11 +541,11 @@ describe("LangChainInstrumentation", () => {
541541
span.attributes[OPENINFERENCE_SPAN_KIND] === OpenInferenceSpanKind.TOOL,
542542
);
543543
expect(toolSpan).toBeDefined();
544-
expect(toolSpan?.attributes).toStrictEqual({
544+
expect(toolSpan?.attributes).toMatchObject({
545545
[OPENINFERENCE_SPAN_KIND]: OpenInferenceSpanKind.TOOL,
546546
[TOOL_NAME]: "test_tool",
547-
[INPUT_VALUE]: "hello",
548-
[INPUT_MIME_TYPE]: "text/plain",
547+
[INPUT_VALUE]: '{"input":"hello"}',
548+
[INPUT_MIME_TYPE]: "application/json",
549549
[OUTPUT_VALUE]: "this is a test tool",
550550
[OUTPUT_MIME_TYPE]: "text/plain",
551551
metadata: "{}",

0 commit comments

Comments
 (0)