MCPcopy Create free account
hub / github.com/pollinations/pollinations / createTextCommand

Function createTextCommand

packages/polli-cli/src/commands/gen/text.ts:23–190  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

21}
22
23export function createTextCommand() {
24 return new Command("text")
25 .description(
26 "Generate text from a prompt (also reads stdin: echo 'hello' | polli text)",
27 )
28 .argument("[prompt]", "Text prompt (or pipe via stdin)")
29 .option("--model <model>", "Text model")
30 .option("--system <msg>", "System message")
31 .option("--temperature <n>", "Randomness (0-2)")
32 .option("--max-tokens <n>", "Maximum output tokens")
33 .option("--top-p <n>", "Nucleus sampling (0-1)")
34 .option("--frequency-penalty <n>", "Repetition penalty (-2 to 2)")
35 .option("--presence-penalty <n>", "Topic penalty (-2 to 2)")
36 .option("--seed <n>", "Reproducibility seed")
37 .option("--json-response", "Force model to return JSON object")
38 .option(
39 "--reasoning <effort>",
40 "Reasoning effort for reasoning models: none|minimal|low|medium|high|xhigh",
41 )
42 .option(
43 "--image <url...>",
44 "Attach image URL(s) for vision models (repeatable)",
45 )
46 .option("--output <path>", "Save to file instead of stdout")
47 .option(
48 "--no-stream",
49 "Wait for full response instead of streaming tokens",
50 )
51 .action(async (promptArg, opts) => {
52 const key = requireKey();
53 const stdinText = await readStdin();
54 const prompt = promptArg || stdinText;
55
56 if (!prompt) {
57 printError(
58 "No prompt provided. Pass as argument or pipe via stdin.",
59 );
60 process.exit(1);
61 }
62
63 // If both stdin and arg are provided, use arg as prompt and stdin as context
64 if (promptArg && stdinText) {
65 opts.system = opts.system
66 ? `${opts.system}\n\nContext:\n${stdinText}`
67 : stdinText;
68 }
69
70 const isHuman = getOutputMode() === "human";
71 // Streaming on by default when a human is watching (TTY stdout).
72 // Auto-off when piping/redirecting so SSE chunks don't leak into
73 // the downstream consumer. `--no-stream` forces off; `--stream`
74 // (when explicitly passed) forces on even if piped.
75 const explicitStream = opts.stream === true;
76 const autoStream = isHuman && !!process.stdout.isTTY;
77 const useStream =
78 opts.stream !== false &&
79 !opts.output &&
80 (explicitStream || autoStream);

Callers 1

createGenCommandFunction · 0.85

Calls 14

requireKeyFunction · 0.85
readStdinFunction · 0.85
printErrorFunction · 0.85
getOutputModeFunction · 0.85
printInfoFunction · 0.85
budgetHintFunction · 0.85
streamSSEFunction · 0.85
printResultFunction · 0.85
printSuccessFunction · 0.85
pushMethod · 0.80
stringifyMethod · 0.80
jsonMethod · 0.80

Tested by

no test coverage detected