Skip to content

Commit

Permalink
Simplify control flow in sample code.
Browse files Browse the repository at this point in the history
No longer triggers the "no-continue" eslint rule.
  • Loading branch information
mattparlane authored and salmenus committed Jun 10, 2024
1 parent 3c3c89c commit d03d260
Show file tree
Hide file tree
Showing 29 changed files with 61 additions and 118 deletions.
6 changes: 2 additions & 4 deletions docs/docs/examples/0001-react-js-ai-assistant/adapter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions docs/docs/examples/0005-welcome-message/adapter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions docs/docs/examples/0007-conversation-history/adapter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions docs/docs/examples/0008-conversation-layout/adapter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions docs/docs/examples/0009-markdown-streaming/adapter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions docs/docs/examples/0011-syntax-highlighter/adapter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions docs/docs/learn/_001-overview/adapter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions docs/src/pages/(examples)/intro/adapter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion packages/js/langchain/src/langserve/adapter/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class LangServeStreamAdapter<AiMsg> extends LangServeAbstractAdapter<AiMs
const {value, done} = await reader.read();
if (done) {
doneReading = true;
continue;
break;
}

const chunk = textDecoder.decode(value);
Expand Down
8 changes: 3 additions & 5 deletions packages/js/nlbridge/src/nlbridge/chatAdapter/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,13 @@ export class NLBridgeStreamAdapter<AiMsg> extends NLBridgeAbstractAdapter<AiMsg>
// 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);
Expand Down
Loading

0 comments on commit d03d260

Please sign in to comment.