@@ -38,8 +38,11 @@ function createCondensedStreamingResponse(
3838export async function handlerStreaming ( c : Context ) {
3939 const payload = await c . req . json < ChatCompletionsPayload > ( )
4040
41+ // Convert request headers to a regular object from Headers
42+ const requestHeaders = c . req . header ( )
43+
4144 // Log the request at the beginning for both streaming and non-streaming cases
42- await logger . logRequest ( "/chat/completions" , "POST" , payload )
45+ await logger . logRequest ( "/chat/completions" , "POST" , payload , requestHeaders )
4346
4447 if ( payload . stream ) {
4548 const response = await chatCompletionsStream ( payload )
@@ -52,7 +55,7 @@ export async function handlerStreaming(c: Context) {
5255 for await ( const chunk of response ) {
5356 await stream . writeSSE ( chunk as SSEMessage )
5457
55- if ( ! logger . options . enabled ) continue // Changed from return to continue
58+ if ( ! logger . options . enabled ) continue
5659
5760 // Check if chunk data is "DONE" or not a valid JSON string
5861 if ( ! chunk . data || chunk . data === "[DONE]" ) {
@@ -83,15 +86,18 @@ export async function handlerStreaming(c: Context) {
8386 collectedContent ,
8487 )
8588
86- await logger . logResponse ( "/chat/completions" , condensedResponse )
89+ await logger . logResponse ( "/chat/completions" , condensedResponse , { } )
8790 }
8891 } )
8992 }
9093
9194 const response = await chatCompletions ( payload )
9295
93- // Log the non-streaming response
94- await logger . logResponse ( "/chat/completions" , response )
96+ // Get response headers if any
97+ const responseHeaders = { } // Empty placeholder for response headers
98+
99+ // Log the non-streaming response with headers
100+ await logger . logResponse ( "/chat/completions" , response , responseHeaders )
95101
96102 return c . json ( response )
97103}
0 commit comments