Skip to content

Commit 194980f

Browse files
committed
update aiq! to only respond with json
1 parent 932c0d8 commit 194980f

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ aiq my_database "list all users where age is over 30"
107107
# or
108108
aiq my_database "list all users where age is over 30
109109
110-
# Don't start a AI Database Query Session.. Get one response.
110+
# Don't start a AI Database Query Session.. Just get one response in JSON format.
111111
aiq! my_database "list all users where age is over 30"
112112
113113
# Start an AI conversation

aiq.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ import { getDatabaseAdapter } from "dbinfoz";
1212

1313
const configFilePath = path.resolve(process.env.HOME, ".commandai/db.json");
1414

15+
let USE_PROMPT = true;
16+
17+
function consoleLog(message) {
18+
if (USE_PROMPT) {
19+
console.log(message);
20+
}
21+
}
22+
1523
async function fileExists(filePath) {
1624
return fs.existsSync(filePath);
1725
}
@@ -42,10 +50,10 @@ async function getConnectionConfig(dbConfigs, nameOrFilePath) {
4250

4351

4452
async function generateQuery(command, client, dbAdapter) {
45-
const spinner = ora(gradient.cristal("Thinking...")).start();
53+
if (USE_PROMPT) { const spinner = ora(gradient.cristal("Thinking...")).start(); }
4654
const queryString = await client.generateQuery(command, dbAdapter);
47-
spinner.succeed(gradient.cristal("Query generated."));
48-
console.log(queryString);
55+
if (USE_PROMPT) { spinner.succeed(gradient.cristal("Query generated.")); }
56+
consoleLog(queryString);
4957

5058
const queryObject = JSON.parse(queryString);
5159
return queryObject;
@@ -58,7 +66,7 @@ async function retryQuery(client, dbAdapter) {
5866
dbAdapter,
5967
);
6068
spinner.succeed(gradient.cristal("Query generated."));
61-
console.log(queryString);
69+
consoleLog(queryString);
6270

6371
const queryObject = JSON.parse(queryString);
6472
return queryObject;
@@ -133,8 +141,8 @@ async function getPreviewCount(adapter, previewQuery) {
133141

134142
async function handleQuery(command, client, adapter) {
135143
const queryObj = await generateQuery(command, client, adapter);
136-
console.log(gradient.cristal("Generated Query:"));
137-
console.log(gradient.teen(queryObj.query));
144+
consoleLog(gradient.cristal("Generated Query:"));
145+
consoleLog(gradient.teen(queryObj.query));
138146
return queryObj;
139147
}
140148

@@ -250,7 +258,7 @@ async function processQuery(dbConfigs, connectionNameOrFile, command, client, pr
250258
if (shouldExecute) {
251259
await executeWithRetries(adapter, queryObj.query, client, prompt);
252260
} else {
253-
console.log("Query execution aborted by user.");
261+
consoleLog("Query execution aborted by user.");
254262
}
255263
}
256264

@@ -458,6 +466,8 @@ async function handleExecuteQuery(args, prompt) {
458466
}
459467

460468
async function main(prompt = true) {
469+
USE_PROMPT = prompt;
470+
461471
let args = process.argv.slice(2);
462472
if(args.length === 1) { args = args[0].split(' ') }
463473
const paramType = await validateArguments(args);

0 commit comments

Comments
 (0)