Skip to content

Commit

Permalink
feat(examples): replace process exit with reader close
Browse files Browse the repository at this point in the history
Signed-off-by: Tomas Dvorak <toomas2d@gmail.com>
  • Loading branch information
Tomas2D committed Oct 11, 2024
1 parent fdfca98 commit 65b7da4
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
4 changes: 1 addition & 3 deletions docs/llms.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@ const llm = new WatsonXLLM({
});

const reader = createConsoleReader();

const prompt = await reader.prompt();
const response = await llm.generate(prompt);
reader.write(`LLM 🤖 (text) : `, response.getTextContent());
process.exit(0);
reader.close();
```

_Source: [examples/llms/text.ts](/examples/llms/text.ts)_
Expand Down Expand Up @@ -209,7 +208,6 @@ const response = await driver.generate(
],
);
console.info(response);
process.exit(0);
```

_Source: [examples/llms/structured.ts](/examples/llms/structured.ts)_
Expand Down
2 changes: 1 addition & 1 deletion examples/agents/bee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,5 @@ try {
} catch (error) {
logger.error(FrameworkError.ensure(error).dump());
} finally {
process.exit(0);
reader.close();
}
2 changes: 1 addition & 1 deletion examples/agents/bee_advanced.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,5 @@ try {
} catch (error) {
logger.error(FrameworkError.ensure(error).dump());
} finally {
process.exit(0);
reader.close();
}
4 changes: 4 additions & 0 deletions examples/helpers/io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ export function createConsoleReader({
}
process.exit(0);
},
close() {
stdin.pause();
rl.close();
},
async *[Symbol.asyncIterator]() {
if (!isActive) {
return;
Expand Down
1 change: 0 additions & 1 deletion examples/llms/structured.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@ const response = await driver.generate(
],
);
console.info(response);
process.exit(0);
3 changes: 1 addition & 2 deletions examples/llms/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ const llm = new WatsonXLLM({
});

const reader = createConsoleReader();

const prompt = await reader.prompt();
const response = await llm.generate(prompt);
reader.write(`LLM 🤖 (text) : `, response.getTextContent());
process.exit(0);
reader.close();

0 comments on commit 65b7da4

Please sign in to comment.