@@ -19,6 +19,16 @@ function createMockOpenAiClient() {
1919 } ) ,
2020 } ,
2121 } ,
22+ responses : {
23+ create : async ( params : { model : string ; input : string } ) => ( {
24+ id : 'resp-test' ,
25+ object : 'response' ,
26+ model : params . model ,
27+ output_text : 'Response text' ,
28+ status : 'completed' ,
29+ usage : { input_tokens : 5 , output_tokens : 3 , total_tokens : 8 } ,
30+ } ) ,
31+ } ,
2232 } ;
2333}
2434
@@ -44,7 +54,7 @@ describe('OpenAI enableTruncation option', () => {
4454
4555 async function callWithOptions (
4656 options : { recordInputs ?: boolean ; enableTruncation ?: boolean } ,
47- messages : Array < { role : string ; content : string } > ,
57+ input : Array < { role : string ; content : string } > | string ,
4858 ) : Promise < string | undefined > {
4959 const mockClient = createMockOpenAiClient ( ) ;
5060 const instrumented = instrumentOpenAiClient ( mockClient as unknown as OpenAiClient , options ) as MockClient ;
@@ -53,7 +63,11 @@ describe('OpenAI enableTruncation option', () => {
5363
5464 await startSpan ( { name : 'test' } , async span => {
5565 rootSpan = span ;
56- await instrumented . chat . completions . create ( { model : 'gpt-4' , messages } ) ;
66+ if ( typeof input === 'string' ) {
67+ await instrumented . responses . create ( { model : 'gpt-4' , input } ) ;
68+ } else {
69+ await instrumented . chat . completions . create ( { model : 'gpt-4' , messages : input } ) ;
70+ }
5771 } ) ;
5872
5973 const spans = getSpanDescendants ( rootSpan ! ) ;
@@ -83,4 +97,10 @@ describe('OpenAI enableTruncation option', () => {
8397 const parsed = JSON . parse ( inputMessages ! ) ;
8498 expect ( parsed ) . toEqual ( messages ) ;
8599 } ) ;
100+
101+ it ( 'does not wrap string input in quotes when enableTruncation is false' , async ( ) => {
102+ const stringInput = 'Translate this to French: Hello' ;
103+ const inputMessages = await callWithOptions ( { recordInputs : true , enableTruncation : false } , stringInput ) ;
104+ expect ( inputMessages ) . toBe ( stringInput ) ;
105+ } ) ;
86106} ) ;
0 commit comments