Skip to content
This repository has been archived by the owner on Jun 2, 2023. It is now read-only.

Commit

Permalink
feat: Optimize the output of bing
Browse files Browse the repository at this point in the history
  • Loading branch information
KeJunMao committed Feb 18, 2023
1 parent 1001bdd commit 1671b66
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
},
"dependencies": {
"c12": "^1.1.2",
"chalk": "^5.2.0",
"consola": "^2.15.3",
"lodash": "^4.17.21",
"prompts": "^2.4.2",
Expand Down
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions src/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { EdgeGPTConfig } from "../types";
import prompts from "prompts";
import { ChatBot } from "../ChatBot";
import { logger } from "../utils";
import chalk from "chalk";

export const run = async (options: Partial<EdgeGPTConfig>) => {
const config = await loadEdgeGPTConfig({
Expand All @@ -13,6 +14,7 @@ export const run = async (options: Partial<EdgeGPTConfig>) => {

const chatBot = new ChatBot(config);
await chatBot.create();
const prefix = [chalk.blue("?"), chalk.bold("Bing: ")].join(" ");

while (true) {
const cmd = await prompts([
Expand All @@ -23,7 +25,6 @@ export const run = async (options: Partial<EdgeGPTConfig>) => {
validate: (value) => (!value ? "Prompt can not be empty" : true),
},
]);
let wrote = 0;
if (!cmd.prompt) {
continue;
}
Expand All @@ -34,15 +35,16 @@ export const run = async (options: Partial<EdgeGPTConfig>) => {
chatBot.reset();
break;
}
let wrote = 0;
if (cmd.prompt) {
process.stdout.write(prefix);
if (config.stream) {
await chatBot.ask(cmd.prompt, (msg) => {
process.stdout.write(msg.slice(wrote));
wrote = msg.length;
});
process.stdout.write("\n");
} else {
logger.log(await chatBot.askAsync(cmd.prompt));
process.stdout.write(prefix + (await chatBot.askAsync(cmd.prompt)));
}
}
}
Expand Down

0 comments on commit 1671b66

Please sign in to comment.