From 7e0e9ebea9d4f74edc02e3e00ba672c7d0538366 Mon Sep 17 00:00:00 2001 From: Bam4d Date: Mon, 15 Jan 2024 15:24:23 +0100 Subject: [PATCH] fixing tests --- src/client.js | 2 +- tests/utils.js | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/client.js b/src/client.js index d7d6a7c..d0a801b 100644 --- a/src/client.js +++ b/src/client.js @@ -76,7 +76,7 @@ class MistralClient { method: method, headers: { 'User-Agent': `mistral-client-js/${VERSION}`, - 'Accept': request.stream ? 'text/event-stream' : 'application/json', + 'Accept': request?.stream ? 'text/event-stream' : 'application/json', 'Content-Type': 'application/json', 'Authorization': `Bearer ${this.apiKey}`, }, diff --git a/tests/utils.js b/tests/utils.js index 8d80084..3370228 100644 --- a/tests/utils.js +++ b/tests/utils.js @@ -182,8 +182,9 @@ export function mockChatResponsePayload() { * @return {Object} */ export function mockChatResponseStreamingPayload() { + const encoder = new TextEncoder(); const firstMessage = - ['data: ' + + [encoder.encode('data: ' + JSON.stringify({ id: 'cmpl-8cd9019d21ba490aa6b9740f5d0a883e', model: 'mistral-small', @@ -195,12 +196,12 @@ export function mockChatResponseStreamingPayload() { }, ], }) + - '\n\n']; - const lastMessage = ['data: [DONE]\n\n']; + '\n\n')]; + const lastMessage = [encoder.encode('data: [DONE]\n\n')]; const dataMessages = []; for (let i = 0; i < 10; i++) { - dataMessages.push( + dataMessages.push(encoder.encode( 'data: ' + JSON.stringify({ id: 'cmpl-8cd9019d21ba490aa6b9740f5d0a883e', @@ -215,7 +216,7 @@ export function mockChatResponseStreamingPayload() { }, ], }) + - '\n\n', + '\n\n'), ); }