File tree Expand file tree Collapse file tree 2 files changed +13
-4
lines changed
js/packages/openinference-instrumentation-langchain Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Original file line number Diff line number Diff 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 {
495497function 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.
Original file line number Diff line number Diff 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 : "{}" ,
You can’t perform that action at this time.
0 commit comments