okai 0.0.28 → 0.0.29
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 +44 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -51,6 +51,9 @@ function parseArgs(...args) {
|
|
51
51
|
case "/cached":
|
52
52
|
ret.cached = true;
|
53
53
|
break;
|
54
|
+
case "/system":
|
55
|
+
ret.system = args[++i];
|
56
|
+
break;
|
54
57
|
default:
|
55
58
|
ret.unknown = ret.unknown || [];
|
56
59
|
ret.unknown.push(arg);
|
@@ -95,6 +98,10 @@ function parseArgs(...args) {
|
|
95
98
|
ret.accept = args[++i];
|
96
99
|
}
|
97
100
|
}
|
101
|
+
else if (arg == "chat") {
|
102
|
+
ret.type = "chat";
|
103
|
+
ret.chat = args[++i];
|
104
|
+
}
|
98
105
|
else if (arg.endsWith('.d.ts')) {
|
99
106
|
if (ret.type == "help")
|
100
107
|
ret.type = "update";
|
@@ -174,6 +181,8 @@ ${bin} ls models Display list of available premium LLM models
|
|
174
181
|
${bin} init Initialize okai.json with project info to override default paths
|
175
182
|
${bin} init <model> Create an empty <model>.d.ts file for the specified model
|
176
183
|
${bin} info Display current project info
|
184
|
+
${bin} chat <prompt> Submit a new OpenAI chat request with the specified prompt
|
185
|
+
-system <prompt> Specify a system prompt
|
177
186
|
|
178
187
|
Options:
|
179
188
|
-v, -verbose Display verbose logging
|
@@ -416,6 +425,41 @@ Options:
|
|
416
425
|
await acceptGist(command, command.accept);
|
417
426
|
process.exit(0);
|
418
427
|
}
|
428
|
+
if (command.type === "chat") {
|
429
|
+
try {
|
430
|
+
const url = new URL('/chat', command.baseUrl);
|
431
|
+
const formData = new FormData();
|
432
|
+
formData.append('prompt', command.chat);
|
433
|
+
if (command.system) {
|
434
|
+
formData.append('system', command.system);
|
435
|
+
}
|
436
|
+
if (command.models) {
|
437
|
+
formData.append('model', command.models);
|
438
|
+
if (command.license) {
|
439
|
+
formData.append('license', command.license);
|
440
|
+
}
|
441
|
+
}
|
442
|
+
if (command.verbose)
|
443
|
+
console.log(`POST: ${url}`);
|
444
|
+
const res = await fetch(url, {
|
445
|
+
method: 'POST',
|
446
|
+
body: formData,
|
447
|
+
});
|
448
|
+
if (!res.ok) {
|
449
|
+
console.log(`Failed to chat: ${res.statusText}`);
|
450
|
+
process.exit(1);
|
451
|
+
}
|
452
|
+
const response = await res.json();
|
453
|
+
if (command.verbose)
|
454
|
+
console.log(JSON.stringify(response, undefined, 2));
|
455
|
+
const content = response.choices[response.choices.length - 1]?.message?.content;
|
456
|
+
console.log(content);
|
457
|
+
}
|
458
|
+
catch (err) {
|
459
|
+
console.error(err);
|
460
|
+
}
|
461
|
+
process.exit(0);
|
462
|
+
}
|
419
463
|
if (command.type === "prompt") {
|
420
464
|
try {
|
421
465
|
if (!info.serviceModelDir)
|