openhorizon-cli 1.0.6 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +33 -9
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -82,6 +82,14 @@ function getHistoryEntries() {
|
|
|
82
82
|
return [];
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
|
+
function clearHistory() {
|
|
86
|
+
try {
|
|
87
|
+
if (fs2.existsSync(HISTORY_FILE)) {
|
|
88
|
+
fs2.unlinkSync(HISTORY_FILE);
|
|
89
|
+
}
|
|
90
|
+
} catch {
|
|
91
|
+
}
|
|
92
|
+
}
|
|
85
93
|
function printHistoryEntries(entries, limit, isRaw = false) {
|
|
86
94
|
if (entries.length === 0) {
|
|
87
95
|
console.log(chalk.gray("\n No history found.\n"));
|
|
@@ -215,6 +223,10 @@ async function* streamCompletion(baseUrl, apiKey, model, messages) {
|
|
|
215
223
|
const base = baseUrl.replace(/\/$/, "");
|
|
216
224
|
const v1base = base.endsWith("/v1") ? base : `${base}/v1`;
|
|
217
225
|
const url = `${v1base}/chat/completions`;
|
|
226
|
+
const systemMessage = {
|
|
227
|
+
role: "system",
|
|
228
|
+
content: "You are a helpful AI assistant. Respond in clear, concise Markdown. Made by Saidev Dhal at Galgotias University. You are hosted on NVIDIA DGX H200 GPUs."
|
|
229
|
+
};
|
|
218
230
|
const res = await fetch(url, {
|
|
219
231
|
method: "POST",
|
|
220
232
|
headers: {
|
|
@@ -222,9 +234,13 @@ async function* streamCompletion(baseUrl, apiKey, model, messages) {
|
|
|
222
234
|
Authorization: `Bearer ${apiKey}`,
|
|
223
235
|
"x-api-key": apiKey,
|
|
224
236
|
"x-client": "openhorizon-cli",
|
|
225
|
-
"x-client-version": "1.0.
|
|
237
|
+
"x-client-version": "1.0.8"
|
|
226
238
|
},
|
|
227
|
-
body: JSON.stringify({
|
|
239
|
+
body: JSON.stringify({
|
|
240
|
+
model,
|
|
241
|
+
messages: [systemMessage, ...messages],
|
|
242
|
+
stream: true
|
|
243
|
+
})
|
|
228
244
|
});
|
|
229
245
|
if (!res.ok) {
|
|
230
246
|
const body = await res.text().catch(() => "");
|
|
@@ -272,7 +288,7 @@ async function runChatLoop(options) {
|
|
|
272
288
|
console.log(
|
|
273
289
|
chalk3.gray(
|
|
274
290
|
`
|
|
275
|
-
Commands: ${chalk3.white("/model")} ${chalk3.white("/clear")} ${chalk3.white("/help")} ${chalk3.white("/version")} ${chalk3.white("/update")} ${chalk3.white("exit")}
|
|
291
|
+
Commands: ${chalk3.white("/model")} ${chalk3.white("/history")} ${chalk3.white("/clear")} ${chalk3.white("/help")} ${chalk3.white("/version")} ${chalk3.white("/update")} ${chalk3.white("exit")}
|
|
276
292
|
`
|
|
277
293
|
)
|
|
278
294
|
);
|
|
@@ -298,24 +314,31 @@ async function runChatLoop(options) {
|
|
|
298
314
|
console.log(chalk3.gray("\n /model \u2013 show current model"));
|
|
299
315
|
console.log(chalk3.gray(" /version \u2013 show current CLI version"));
|
|
300
316
|
console.log(chalk3.gray(" /update \u2013 check for and install updates"));
|
|
301
|
-
console.log(chalk3.gray(" /history \u2013
|
|
302
|
-
console.log(chalk3.gray(" /clear \u2013 clear
|
|
317
|
+
console.log(chalk3.gray(" /history \u2013 guide on how to view chat history"));
|
|
318
|
+
console.log(chalk3.gray(" /clear \u2013 permanently clear all chat history"));
|
|
303
319
|
console.log(chalk3.gray(" exit \u2013 quit\n"));
|
|
304
320
|
console.log(chalk3.dim(" Tip: Use 'openhorizon history --help' for full history viewer.\n"));
|
|
305
321
|
continue;
|
|
306
322
|
}
|
|
307
323
|
if (trimmed === "/version") {
|
|
308
324
|
console.log(chalk3.blue(`
|
|
309
|
-
OpenHorizon CLI version: ${chalk3.bold("1.0.
|
|
325
|
+
OpenHorizon CLI version: ${chalk3.bold("1.0.8")}
|
|
310
326
|
`));
|
|
311
327
|
continue;
|
|
312
328
|
}
|
|
313
329
|
if (trimmed === "/update") {
|
|
314
|
-
await runUpdate("1.0.
|
|
330
|
+
await runUpdate("1.0.8");
|
|
315
331
|
continue;
|
|
316
332
|
}
|
|
317
333
|
if (trimmed.startsWith("/history")) {
|
|
318
334
|
const args = trimmed.split(" ").slice(1);
|
|
335
|
+
if (args.length === 0) {
|
|
336
|
+
console.log(chalk3.blue("\n History Usage Guide:"));
|
|
337
|
+
console.log(chalk3.gray(" /history <number> \u2013 show last N messages (e.g. /history 10)"));
|
|
338
|
+
console.log(chalk3.gray(" /history --raw \u2013 output history in raw JSONL format\n"));
|
|
339
|
+
console.log(chalk3.dim(" Tip: Use 'openhorizon history' outside as a standalone command.\n"));
|
|
340
|
+
continue;
|
|
341
|
+
}
|
|
319
342
|
const limit = args.find((a) => !isNaN(Number(a))) || 5;
|
|
320
343
|
const isRaw = args.includes("--raw");
|
|
321
344
|
const entries = getHistoryEntries();
|
|
@@ -330,7 +353,8 @@ async function runChatLoop(options) {
|
|
|
330
353
|
}
|
|
331
354
|
if (trimmed === "/clear") {
|
|
332
355
|
messages.length = 0;
|
|
333
|
-
|
|
356
|
+
clearHistory();
|
|
357
|
+
console.log(chalk3.gray("\n \u2713 History and conversation persistently cleared.\n"));
|
|
334
358
|
continue;
|
|
335
359
|
}
|
|
336
360
|
messages.push({ role: "user", content: trimmed });
|
|
@@ -395,7 +419,7 @@ async function runChatLoop(options) {
|
|
|
395
419
|
// src/index.ts
|
|
396
420
|
dotenv.config();
|
|
397
421
|
var program = new Command();
|
|
398
|
-
var version = "1.0.
|
|
422
|
+
var version = "1.0.8";
|
|
399
423
|
program.name("openhorizon").description("CLI to interact with OpenHorizon AI Models").version(version, "-v, --version", "Output the current version");
|
|
400
424
|
program.command("version").description("Show the current CLI version").action(() => {
|
|
401
425
|
console.log(chalk4.blue(`OpenHorizon CLI version: ${chalk4.bold(version)}`));
|