Skip to content

Commit

Permalink
feat: improve console logs to provide context
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasbueschel committed Mar 4, 2023
1 parent df59012 commit 6e444a5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ async function startCli() {
}

async function searchGPT(userPrompt) {
process.stdout.write(chalk.dim("> Starting Google Search..."));

previousChat = [
{
role: "system",
Expand All @@ -65,6 +67,9 @@ async function searchGPT(userPrompt) {
const [firstpage, ...remainingPages] = searchResults.items;
const urlToCheck = firstpage.link;

process.stdout.cursorTo(0);
process.stdout.write(chalk.dim(`> Checking: ${urlToCheck}`));

// Fetch raw HTML of first page & get main content
const htmlString = await fetch(urlToCheck);
let context = convert(await htmlString.text());
Expand Down Expand Up @@ -98,8 +103,10 @@ async function searchGPT(userPrompt) {
});

const finalResponse = await getOpenAIChatCompletion(previousChat);
console.log(chalk.green("> ") + chalk.white(finalResponse));

process.stdout.clearLine(0);
process.stdout.cursorTo(0);
console.log("\n" + chalk.green("> ") + chalk.white(finalResponse));
console.log(chalk.dim(`> Know more: ${urlToCheck}` + "\n"));

return finalResponse;
Expand Down

0 comments on commit 6e444a5

Please sign in to comment.