From d03d260e257935355a87a96bdd295b243e974c06 Mon Sep 17 00:00:00 2001 From: Matt Parlane Date: Mon, 10 Jun 2024 11:14:13 +1000 Subject: [PATCH] Simplify control flow in sample code. No longer triggers the "no-continue" eslint rule. --- .../docs/examples/0001-react-js-ai-assistant/adapter.tsx | 6 ++---- .../_a-personas-with-url/adapter.tsx | 6 ++---- .../_b-personas-with-jsx/adapter.tsx | 6 ++---- docs/docs/examples/0005-welcome-message/adapter.tsx | 6 ++---- .../_a-streamed-data/adapter.ts | 6 ++---- .../_b-batched-data/adapter.ts | 6 ++---- docs/docs/examples/0007-conversation-history/adapter.tsx | 6 ++---- docs/docs/examples/0008-conversation-layout/adapter.tsx | 6 ++---- docs/docs/examples/0009-markdown-streaming/adapter.tsx | 6 ++---- .../example-custom-button-color/adapter.tsx | 6 ++---- docs/docs/examples/0011-syntax-highlighter/adapter.tsx | 6 ++---- docs/docs/learn/_001-overview/adapter.tsx | 6 ++---- .../example-custom-button-color/adapter.tsx | 6 ++---- docs/src/pages/(examples)/intro/adapter.tsx | 6 ++---- .../examples/0001-react-js-ai-chatbot/adapter.tsx | 6 ++---- .../0003-bot-persona/_a-personas-with-url/adapter.tsx | 6 ++---- .../0003-bot-persona/_b-personas-with-jsx/adapter.tsx | 6 ++---- .../examples/0004-conversation-history/adapter.tsx | 6 ++---- .../examples/0005-markdown-streaming/adapter.tsx | 6 ++---- .../examples/0006-syntax-highlighter/adapter.tsx | 6 ++---- .../example-custom-button-color/adapter.tsx | 6 ++---- .../example-custom-button-color/adapter.tsx | 6 ++---- packages/js/langchain/src/langserve/adapter/stream.ts | 2 +- packages/js/nlbridge/src/nlbridge/chatAdapter/stream.ts | 8 +++----- .../01-vanilla-js-with-adapters/nlBridgeCustomAdapter.ts | 9 +++------ samples/emulator/src/02-vanilla-js-with-events/stream.ts | 8 +++----- .../05-react-js-with-langserve/adapters/einbotStream.ts | 8 +++----- samples/emulator/src/06-react-js-with-adapters/stream.ts | 6 ++---- samples/emulator/src/08-react-js-events/stream.ts | 6 ++---- 29 files changed, 61 insertions(+), 118 deletions(-) diff --git a/docs/docs/examples/0001-react-js-ai-assistant/adapter.tsx b/docs/docs/examples/0001-react-js-ai-assistant/adapter.tsx index e46c2797..9896d569 100644 --- a/docs/docs/examples/0001-react-js-ai-assistant/adapter.tsx +++ b/docs/docs/examples/0001-react-js-ai-assistant/adapter.tsx @@ -29,13 +29,11 @@ export const streamAdapter: ChatAdapter = { // and feed them to the observer as they are being generated const reader = response.body.getReader(); const textDecoder = new TextDecoder(); - let doneReading = false; - while (!doneReading) { + while (true) { const { value, done } = await reader.read(); if (done) { - doneReading = true; - continue; + break; } const content = textDecoder.decode(value); diff --git a/docs/docs/examples/0004-assistant-persona/_a-personas-with-url/adapter.tsx b/docs/docs/examples/0004-assistant-persona/_a-personas-with-url/adapter.tsx index e438d0b4..6d42055f 100644 --- a/docs/docs/examples/0004-assistant-persona/_a-personas-with-url/adapter.tsx +++ b/docs/docs/examples/0004-assistant-persona/_a-personas-with-url/adapter.tsx @@ -26,13 +26,11 @@ export const streamAdapter: ChatAdapter = { // and feed them to the observer as they are being generated const reader = response.body.getReader(); const textDecoder = new TextDecoder(); - let doneReading = false; - while (!doneReading) { + while (true) { const { value, done } = await reader.read(); if (done) { - doneReading = true; - continue; + break; } const content = textDecoder.decode(value); diff --git a/docs/docs/examples/0004-assistant-persona/_b-personas-with-jsx/adapter.tsx b/docs/docs/examples/0004-assistant-persona/_b-personas-with-jsx/adapter.tsx index e438d0b4..6d42055f 100644 --- a/docs/docs/examples/0004-assistant-persona/_b-personas-with-jsx/adapter.tsx +++ b/docs/docs/examples/0004-assistant-persona/_b-personas-with-jsx/adapter.tsx @@ -26,13 +26,11 @@ export const streamAdapter: ChatAdapter = { // and feed them to the observer as they are being generated const reader = response.body.getReader(); const textDecoder = new TextDecoder(); - let doneReading = false; - while (!doneReading) { + while (true) { const { value, done } = await reader.read(); if (done) { - doneReading = true; - continue; + break; } const content = textDecoder.decode(value); diff --git a/docs/docs/examples/0005-welcome-message/adapter.tsx b/docs/docs/examples/0005-welcome-message/adapter.tsx index e438d0b4..6d42055f 100644 --- a/docs/docs/examples/0005-welcome-message/adapter.tsx +++ b/docs/docs/examples/0005-welcome-message/adapter.tsx @@ -26,13 +26,11 @@ export const streamAdapter: ChatAdapter = { // and feed them to the observer as they are being generated const reader = response.body.getReader(); const textDecoder = new TextDecoder(); - let doneReading = false; - while (!doneReading) { + while (true) { const { value, done } = await reader.read(); if (done) { - doneReading = true; - continue; + break; } const content = textDecoder.decode(value); diff --git a/docs/docs/examples/0006-custom-response-renderers/_a-streamed-data/adapter.ts b/docs/docs/examples/0006-custom-response-renderers/_a-streamed-data/adapter.ts index 64fce76f..f4b524ca 100644 --- a/docs/docs/examples/0006-custom-response-renderers/_a-streamed-data/adapter.ts +++ b/docs/docs/examples/0006-custom-response-renderers/_a-streamed-data/adapter.ts @@ -26,13 +26,11 @@ export const streamAdapter: ChatAdapter = { // and feed them to the observer as they are being generated const reader = response.body.getReader(); const textDecoder = new TextDecoder(); - let doneReading = false; - while (!doneReading) { + while (true) { const { value, done } = await reader.read(); if (done) { - doneReading = true; - continue; + break; } const content = textDecoder.decode(value); diff --git a/docs/docs/examples/0006-custom-response-renderers/_b-batched-data/adapter.ts b/docs/docs/examples/0006-custom-response-renderers/_b-batched-data/adapter.ts index 64fce76f..f4b524ca 100644 --- a/docs/docs/examples/0006-custom-response-renderers/_b-batched-data/adapter.ts +++ b/docs/docs/examples/0006-custom-response-renderers/_b-batched-data/adapter.ts @@ -26,13 +26,11 @@ export const streamAdapter: ChatAdapter = { // and feed them to the observer as they are being generated const reader = response.body.getReader(); const textDecoder = new TextDecoder(); - let doneReading = false; - while (!doneReading) { + while (true) { const { value, done } = await reader.read(); if (done) { - doneReading = true; - continue; + break; } const content = textDecoder.decode(value); diff --git a/docs/docs/examples/0007-conversation-history/adapter.tsx b/docs/docs/examples/0007-conversation-history/adapter.tsx index 64fce76f..f4b524ca 100644 --- a/docs/docs/examples/0007-conversation-history/adapter.tsx +++ b/docs/docs/examples/0007-conversation-history/adapter.tsx @@ -26,13 +26,11 @@ export const streamAdapter: ChatAdapter = { // and feed them to the observer as they are being generated const reader = response.body.getReader(); const textDecoder = new TextDecoder(); - let doneReading = false; - while (!doneReading) { + while (true) { const { value, done } = await reader.read(); if (done) { - doneReading = true; - continue; + break; } const content = textDecoder.decode(value); diff --git a/docs/docs/examples/0008-conversation-layout/adapter.tsx b/docs/docs/examples/0008-conversation-layout/adapter.tsx index 64fce76f..f4b524ca 100644 --- a/docs/docs/examples/0008-conversation-layout/adapter.tsx +++ b/docs/docs/examples/0008-conversation-layout/adapter.tsx @@ -26,13 +26,11 @@ export const streamAdapter: ChatAdapter = { // and feed them to the observer as they are being generated const reader = response.body.getReader(); const textDecoder = new TextDecoder(); - let doneReading = false; - while (!doneReading) { + while (true) { const { value, done } = await reader.read(); if (done) { - doneReading = true; - continue; + break; } const content = textDecoder.decode(value); diff --git a/docs/docs/examples/0009-markdown-streaming/adapter.tsx b/docs/docs/examples/0009-markdown-streaming/adapter.tsx index 78cd0bf6..117ae541 100644 --- a/docs/docs/examples/0009-markdown-streaming/adapter.tsx +++ b/docs/docs/examples/0009-markdown-streaming/adapter.tsx @@ -26,13 +26,11 @@ export const streamAdapter: ChatAdapter = { // and feed them to the observer as they are being generated const reader = response.body.getReader(); const textDecoder = new TextDecoder(); - let doneReading = false; - while (!doneReading) { + while (true) { const { value, done } = await reader.read(); if (done) { - doneReading = true; - continue; + break; } const content = textDecoder.decode(value); diff --git a/docs/docs/examples/0010-customize-theme/example-custom-button-color/adapter.tsx b/docs/docs/examples/0010-customize-theme/example-custom-button-color/adapter.tsx index 64fce76f..f4b524ca 100644 --- a/docs/docs/examples/0010-customize-theme/example-custom-button-color/adapter.tsx +++ b/docs/docs/examples/0010-customize-theme/example-custom-button-color/adapter.tsx @@ -26,13 +26,11 @@ export const streamAdapter: ChatAdapter = { // and feed them to the observer as they are being generated const reader = response.body.getReader(); const textDecoder = new TextDecoder(); - let doneReading = false; - while (!doneReading) { + while (true) { const { value, done } = await reader.read(); if (done) { - doneReading = true; - continue; + break; } const content = textDecoder.decode(value); diff --git a/docs/docs/examples/0011-syntax-highlighter/adapter.tsx b/docs/docs/examples/0011-syntax-highlighter/adapter.tsx index 78cd0bf6..117ae541 100644 --- a/docs/docs/examples/0011-syntax-highlighter/adapter.tsx +++ b/docs/docs/examples/0011-syntax-highlighter/adapter.tsx @@ -26,13 +26,11 @@ export const streamAdapter: ChatAdapter = { // and feed them to the observer as they are being generated const reader = response.body.getReader(); const textDecoder = new TextDecoder(); - let doneReading = false; - while (!doneReading) { + while (true) { const { value, done } = await reader.read(); if (done) { - doneReading = true; - continue; + break; } const content = textDecoder.decode(value); diff --git a/docs/docs/learn/_001-overview/adapter.tsx b/docs/docs/learn/_001-overview/adapter.tsx index 78cd0bf6..117ae541 100644 --- a/docs/docs/learn/_001-overview/adapter.tsx +++ b/docs/docs/learn/_001-overview/adapter.tsx @@ -26,13 +26,11 @@ export const streamAdapter: ChatAdapter = { // and feed them to the observer as they are being generated const reader = response.body.getReader(); const textDecoder = new TextDecoder(); - let doneReading = false; - while (!doneReading) { + while (true) { const { value, done } = await reader.read(); if (done) { - doneReading = true; - continue; + break; } const content = textDecoder.decode(value); diff --git a/docs/docs/learn/_005-customize-theme/example-custom-button-color/adapter.tsx b/docs/docs/learn/_005-customize-theme/example-custom-button-color/adapter.tsx index 64fce76f..f4b524ca 100644 --- a/docs/docs/learn/_005-customize-theme/example-custom-button-color/adapter.tsx +++ b/docs/docs/learn/_005-customize-theme/example-custom-button-color/adapter.tsx @@ -26,13 +26,11 @@ export const streamAdapter: ChatAdapter = { // and feed them to the observer as they are being generated const reader = response.body.getReader(); const textDecoder = new TextDecoder(); - let doneReading = false; - while (!doneReading) { + while (true) { const { value, done } = await reader.read(); if (done) { - doneReading = true; - continue; + break; } const content = textDecoder.decode(value); diff --git a/docs/src/pages/(examples)/intro/adapter.tsx b/docs/src/pages/(examples)/intro/adapter.tsx index 33a2bf95..907d95eb 100644 --- a/docs/src/pages/(examples)/intro/adapter.tsx +++ b/docs/src/pages/(examples)/intro/adapter.tsx @@ -26,13 +26,11 @@ export const streamAdapter: ChatAdapter = { // and feed them to the observer as they are being generated const reader = response.body.getReader(); const textDecoder = new TextDecoder(); - let doneReading = false; - while (!doneReading) { + while (true) { const { value, done } = await reader.read(); if (done) { - doneReading = true; - continue; + break; } const content = textDecoder.decode(value); diff --git a/docs/versioned_docs/version-1.0.15/examples/0001-react-js-ai-chatbot/adapter.tsx b/docs/versioned_docs/version-1.0.15/examples/0001-react-js-ai-chatbot/adapter.tsx index baf7aca6..451237f6 100644 --- a/docs/versioned_docs/version-1.0.15/examples/0001-react-js-ai-chatbot/adapter.tsx +++ b/docs/versioned_docs/version-1.0.15/examples/0001-react-js-ai-chatbot/adapter.tsx @@ -26,13 +26,11 @@ export const streamAdapter: Adapter = { // and feed them to the observer as they are being generated const reader = response.body.getReader(); const textDecoder = new TextDecoder(); - let doneReading = false; - while (!doneReading) { + while (true) { const { value, done } = await reader.read(); if (done) { - doneReading = true; - continue; + break; } const content = textDecoder.decode(value); diff --git a/docs/versioned_docs/version-1.0.15/examples/0003-bot-persona/_a-personas-with-url/adapter.tsx b/docs/versioned_docs/version-1.0.15/examples/0003-bot-persona/_a-personas-with-url/adapter.tsx index baf7aca6..451237f6 100644 --- a/docs/versioned_docs/version-1.0.15/examples/0003-bot-persona/_a-personas-with-url/adapter.tsx +++ b/docs/versioned_docs/version-1.0.15/examples/0003-bot-persona/_a-personas-with-url/adapter.tsx @@ -26,13 +26,11 @@ export const streamAdapter: Adapter = { // and feed them to the observer as they are being generated const reader = response.body.getReader(); const textDecoder = new TextDecoder(); - let doneReading = false; - while (!doneReading) { + while (true) { const { value, done } = await reader.read(); if (done) { - doneReading = true; - continue; + break; } const content = textDecoder.decode(value); diff --git a/docs/versioned_docs/version-1.0.15/examples/0003-bot-persona/_b-personas-with-jsx/adapter.tsx b/docs/versioned_docs/version-1.0.15/examples/0003-bot-persona/_b-personas-with-jsx/adapter.tsx index baf7aca6..451237f6 100644 --- a/docs/versioned_docs/version-1.0.15/examples/0003-bot-persona/_b-personas-with-jsx/adapter.tsx +++ b/docs/versioned_docs/version-1.0.15/examples/0003-bot-persona/_b-personas-with-jsx/adapter.tsx @@ -26,13 +26,11 @@ export const streamAdapter: Adapter = { // and feed them to the observer as they are being generated const reader = response.body.getReader(); const textDecoder = new TextDecoder(); - let doneReading = false; - while (!doneReading) { + while (true) { const { value, done } = await reader.read(); if (done) { - doneReading = true; - continue; + break; } const content = textDecoder.decode(value); diff --git a/docs/versioned_docs/version-1.0.15/examples/0004-conversation-history/adapter.tsx b/docs/versioned_docs/version-1.0.15/examples/0004-conversation-history/adapter.tsx index baf7aca6..451237f6 100644 --- a/docs/versioned_docs/version-1.0.15/examples/0004-conversation-history/adapter.tsx +++ b/docs/versioned_docs/version-1.0.15/examples/0004-conversation-history/adapter.tsx @@ -26,13 +26,11 @@ export const streamAdapter: Adapter = { // and feed them to the observer as they are being generated const reader = response.body.getReader(); const textDecoder = new TextDecoder(); - let doneReading = false; - while (!doneReading) { + while (true) { const { value, done } = await reader.read(); if (done) { - doneReading = true; - continue; + break; } const content = textDecoder.decode(value); diff --git a/docs/versioned_docs/version-1.0.15/examples/0005-markdown-streaming/adapter.tsx b/docs/versioned_docs/version-1.0.15/examples/0005-markdown-streaming/adapter.tsx index de324f32..56351dcf 100644 --- a/docs/versioned_docs/version-1.0.15/examples/0005-markdown-streaming/adapter.tsx +++ b/docs/versioned_docs/version-1.0.15/examples/0005-markdown-streaming/adapter.tsx @@ -26,13 +26,11 @@ export const streamAdapter: Adapter = { // and feed them to the observer as they are being generated const reader = response.body.getReader(); const textDecoder = new TextDecoder(); - let doneReading = false; - while (!doneReading) { + while (true) { const { value, done } = await reader.read(); if (done) { - doneReading = true; - continue; + break; } const content = textDecoder.decode(value); diff --git a/docs/versioned_docs/version-1.0.15/examples/0006-syntax-highlighter/adapter.tsx b/docs/versioned_docs/version-1.0.15/examples/0006-syntax-highlighter/adapter.tsx index de324f32..56351dcf 100644 --- a/docs/versioned_docs/version-1.0.15/examples/0006-syntax-highlighter/adapter.tsx +++ b/docs/versioned_docs/version-1.0.15/examples/0006-syntax-highlighter/adapter.tsx @@ -26,13 +26,11 @@ export const streamAdapter: Adapter = { // and feed them to the observer as they are being generated const reader = response.body.getReader(); const textDecoder = new TextDecoder(); - let doneReading = false; - while (!doneReading) { + while (true) { const { value, done } = await reader.read(); if (done) { - doneReading = true; - continue; + break; } const content = textDecoder.decode(value); diff --git a/docs/versioned_docs/version-1.0.15/examples/0007-customize-theme/example-custom-button-color/adapter.tsx b/docs/versioned_docs/version-1.0.15/examples/0007-customize-theme/example-custom-button-color/adapter.tsx index baf7aca6..451237f6 100644 --- a/docs/versioned_docs/version-1.0.15/examples/0007-customize-theme/example-custom-button-color/adapter.tsx +++ b/docs/versioned_docs/version-1.0.15/examples/0007-customize-theme/example-custom-button-color/adapter.tsx @@ -26,13 +26,11 @@ export const streamAdapter: Adapter = { // and feed them to the observer as they are being generated const reader = response.body.getReader(); const textDecoder = new TextDecoder(); - let doneReading = false; - while (!doneReading) { + while (true) { const { value, done } = await reader.read(); if (done) { - doneReading = true; - continue; + break; } const content = textDecoder.decode(value); diff --git a/docs/versioned_docs/version-1.0.15/learn/_005-customize-theme/example-custom-button-color/adapter.tsx b/docs/versioned_docs/version-1.0.15/learn/_005-customize-theme/example-custom-button-color/adapter.tsx index 64fce76f..f4b524ca 100644 --- a/docs/versioned_docs/version-1.0.15/learn/_005-customize-theme/example-custom-button-color/adapter.tsx +++ b/docs/versioned_docs/version-1.0.15/learn/_005-customize-theme/example-custom-button-color/adapter.tsx @@ -26,13 +26,11 @@ export const streamAdapter: ChatAdapter = { // and feed them to the observer as they are being generated const reader = response.body.getReader(); const textDecoder = new TextDecoder(); - let doneReading = false; - while (!doneReading) { + while (true) { const { value, done } = await reader.read(); if (done) { - doneReading = true; - continue; + break; } const content = textDecoder.decode(value); diff --git a/packages/js/langchain/src/langserve/adapter/stream.ts b/packages/js/langchain/src/langserve/adapter/stream.ts index 3e61ea54..b45e9c8d 100644 --- a/packages/js/langchain/src/langserve/adapter/stream.ts +++ b/packages/js/langchain/src/langserve/adapter/stream.ts @@ -62,7 +62,7 @@ export class LangServeStreamAdapter extends LangServeAbstractAdapter extends NLBridgeAbstractAdapter // and feed them to the observer as they are being generated const reader = response.body.getReader(); const textDecoder = new TextDecoder(); - let doneReading = false; - while (!doneReading) { + while (true) { const {value, done} = await reader.read(); if (done) { - doneReading = true; - continue; + break; } - + try { const chunk = textDecoder.decode(value); observer.next(chunk); diff --git a/samples/emulator/src/01-vanilla-js-with-adapters/nlBridgeCustomAdapter.ts b/samples/emulator/src/01-vanilla-js-with-adapters/nlBridgeCustomAdapter.ts index 60fb975d..33b22a72 100644 --- a/samples/emulator/src/01-vanilla-js-with-adapters/nlBridgeCustomAdapter.ts +++ b/samples/emulator/src/01-vanilla-js-with-adapters/nlBridgeCustomAdapter.ts @@ -31,15 +31,13 @@ export const nlBridgeCustomStreamingAdapter: ChatAdapter = { // and feed them to the observer as they are being generated const reader = response.body.getReader(); const textDecoder = new TextDecoder(); - let doneReading = false; - while (!doneReading) { + while (true) { const {value, done} = await reader.read(); if (done) { - doneReading = true; - continue; + break; } - + try { const chunk = textDecoder.decode(value); observer.next(chunk); @@ -85,4 +83,3 @@ export const nlBridgeCustomPromiseAdapter: ChatAdapter = { } }, }; - diff --git a/samples/emulator/src/02-vanilla-js-with-events/stream.ts b/samples/emulator/src/02-vanilla-js-with-events/stream.ts index 32f91dba..cb41f1e7 100644 --- a/samples/emulator/src/02-vanilla-js-with-events/stream.ts +++ b/samples/emulator/src/02-vanilla-js-with-events/stream.ts @@ -29,15 +29,13 @@ export const streamAdapter: ChatAdapter = { // and feed them to the observer as they are being generated const reader = response.body.getReader(); const textDecoder = new TextDecoder(); - let doneReading = false; - while (!doneReading) { + while (true) { const {value, done} = await reader.read(); if (done) { - doneReading = true; - continue; + break; } - + const content = textDecoder.decode(value); if (content) { observer.next(content); diff --git a/samples/emulator/src/05-react-js-with-langserve/adapters/einbotStream.ts b/samples/emulator/src/05-react-js-with-langserve/adapters/einbotStream.ts index 38f6260a..73992534 100644 --- a/samples/emulator/src/05-react-js-with-langserve/adapters/einbotStream.ts +++ b/samples/emulator/src/05-react-js-with-langserve/adapters/einbotStream.ts @@ -34,13 +34,11 @@ export const streamAdapter: ChatAdapter = { // and feed them to the observer as they are being generated const reader = response.body.getReader(); const textDecoder = new TextDecoder(); - let doneReading = false; - while (!doneReading) { + while (true) { const {value, done} = await reader.read(); if (done) { - doneReading = true; - continue; + break; } const result = textDecoder.decode(value); @@ -72,4 +70,4 @@ event: end observer.complete(); }, -}; \ No newline at end of file +}; diff --git a/samples/emulator/src/06-react-js-with-adapters/stream.ts b/samples/emulator/src/06-react-js-with-adapters/stream.ts index 6fa5a41b..5f8169a6 100644 --- a/samples/emulator/src/06-react-js-with-adapters/stream.ts +++ b/samples/emulator/src/06-react-js-with-adapters/stream.ts @@ -21,13 +21,11 @@ export const streamAdapter: ChatAdapter = { // and feed them to the observer as they are being generated const reader = response.body.getReader(); const textDecoder = new TextDecoder(); - let doneReading = false; - while (!doneReading) { + while (true) { const {value, done} = await reader.read(); if (done) { - doneReading = true; - continue; + break; } const content = textDecoder.decode(value); diff --git a/samples/emulator/src/08-react-js-events/stream.ts b/samples/emulator/src/08-react-js-events/stream.ts index 8b6a3837..9130278f 100644 --- a/samples/emulator/src/08-react-js-events/stream.ts +++ b/samples/emulator/src/08-react-js-events/stream.ts @@ -31,13 +31,11 @@ export const streamAdapter: ChatAdapter = { // and feed them to the observer as they are being generated const reader = response.body.getReader(); const textDecoder = new TextDecoder(); - let doneReading = false; - while (!doneReading) { + while (true) { const {value, done} = await reader.read(); if (done) { - doneReading = true; - continue; + break; } const content = textDecoder.decode(value);