@pollinations/cli 0.1.29 → 0.1.30
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 +32 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var init_package = __esm({
|
|
|
14
14
|
"package.json"() {
|
|
15
15
|
package_default = {
|
|
16
16
|
name: "@pollinations/cli",
|
|
17
|
-
version: "0.1.
|
|
17
|
+
version: "0.1.30",
|
|
18
18
|
description: "The Pollinations CLI \u2014 for humans, AI agents, and everything in between",
|
|
19
19
|
type: "module",
|
|
20
20
|
bin: {
|
|
@@ -160,7 +160,7 @@ var init_config = __esm({
|
|
|
160
160
|
|
|
161
161
|
// src/lib/output.ts
|
|
162
162
|
import chalk from "chalk";
|
|
163
|
-
var configureHelp, currentMode, setOutputMode, getOutputMode, printResult, printTable, printInfo, printMeta, printSuccess, printError, ExitSignal, fail;
|
|
163
|
+
var configureHelp, currentMode, setOutputMode, getOutputMode, printResult, printTable, printInfo, printMeta, printSuccess, printError, ExitSignal, fail, printWarn;
|
|
164
164
|
var init_output = __esm({
|
|
165
165
|
"src/lib/output.ts"() {
|
|
166
166
|
"use strict";
|
|
@@ -280,6 +280,12 @@ var init_output = __esm({
|
|
|
280
280
|
printError(`${message}${detail}`);
|
|
281
281
|
throw new ExitSignal(1);
|
|
282
282
|
};
|
|
283
|
+
printWarn = (msg) => {
|
|
284
|
+
process.stderr.write(
|
|
285
|
+
`${chalk.yellow.bold("warn:")} ${chalk.yellow(msg)}
|
|
286
|
+
`
|
|
287
|
+
);
|
|
288
|
+
};
|
|
283
289
|
}
|
|
284
290
|
});
|
|
285
291
|
|
|
@@ -788,11 +794,22 @@ var docsCommand = new Command3("docs").description("Show Pollinations API docume
|
|
|
788
794
|
const isJson = getOutputMode() === "json";
|
|
789
795
|
let content = doc;
|
|
790
796
|
if (endpoint) {
|
|
791
|
-
const sections =
|
|
797
|
+
const sections = [""];
|
|
798
|
+
let inFence = false;
|
|
799
|
+
for (const line of doc.split(/(?<=\n)/)) {
|
|
800
|
+
if (line.startsWith("```")) inFence = !inFence;
|
|
801
|
+
if (!inFence && /^#{1,6} /.test(line)) {
|
|
802
|
+
sections.push("");
|
|
803
|
+
}
|
|
804
|
+
sections[sections.length - 1] += line;
|
|
805
|
+
}
|
|
792
806
|
const needle = endpoint.replace(/^\//, "").toLowerCase();
|
|
793
|
-
const
|
|
807
|
+
const headingMatches = sections.filter(
|
|
794
808
|
(s) => s.split("\n")[0].toLowerCase().includes(needle)
|
|
795
809
|
);
|
|
810
|
+
const matches = headingMatches.length ? headingMatches : sections.filter(
|
|
811
|
+
(s) => s.toLowerCase().includes(needle)
|
|
812
|
+
);
|
|
796
813
|
if (matches.length === 0) {
|
|
797
814
|
printError(`No docs found matching "${endpoint}"`);
|
|
798
815
|
printInfo(
|
|
@@ -1643,6 +1660,12 @@ ${stdinText}` : stdinText;
|
|
|
1643
1660
|
if (opts.reasoning) body.reasoning_effort = opts.reasoning;
|
|
1644
1661
|
if (useStream) body.stream = true;
|
|
1645
1662
|
if (isHuman && !useStream) printInfo("Generating...");
|
|
1663
|
+
const warnIfTruncated = (reason) => {
|
|
1664
|
+
if (reason === "length")
|
|
1665
|
+
printWarn(
|
|
1666
|
+
"The model reached its output token limit; the response may be truncated."
|
|
1667
|
+
);
|
|
1668
|
+
};
|
|
1646
1669
|
try {
|
|
1647
1670
|
const res = await fetchGen("/v1/chat/completions", {
|
|
1648
1671
|
method: "POST",
|
|
@@ -1656,15 +1679,19 @@ ${stdinText}` : stdinText;
|
|
|
1656
1679
|
let content2 = "";
|
|
1657
1680
|
let model = null;
|
|
1658
1681
|
let tokens = null;
|
|
1682
|
+
let lengthTerminated = false;
|
|
1659
1683
|
for await (const chunk of streamSSE(res, (event) => {
|
|
1660
1684
|
if (typeof event.model === "string")
|
|
1661
1685
|
model = event.model;
|
|
1662
1686
|
if (typeof event.usage?.total_tokens === "number")
|
|
1663
1687
|
tokens = event.usage.total_tokens;
|
|
1688
|
+
if (event.choices?.[0]?.finish_reason === "length")
|
|
1689
|
+
lengthTerminated = true;
|
|
1664
1690
|
})) {
|
|
1665
1691
|
content2 += chunk;
|
|
1666
1692
|
if (isHuman) process.stdout.write(colorize(chunk));
|
|
1667
1693
|
}
|
|
1694
|
+
if (lengthTerminated) warnIfTruncated("length");
|
|
1668
1695
|
if (isHuman) process.stdout.write("\n");
|
|
1669
1696
|
if (getOutputMode() === "json") {
|
|
1670
1697
|
printResult({ content: content2, model, tokens });
|
|
@@ -1673,6 +1700,7 @@ ${stdinText}` : stdinText;
|
|
|
1673
1700
|
}
|
|
1674
1701
|
const data = await res.json();
|
|
1675
1702
|
const content = data.choices[0]?.message?.content ?? "";
|
|
1703
|
+
warnIfTruncated(data.choices[0]?.finish_reason);
|
|
1676
1704
|
if (opts.output) {
|
|
1677
1705
|
writeFileSync7(opts.output, content, "utf-8");
|
|
1678
1706
|
if (getOutputMode() === "json") {
|