Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1531,9 +1531,10 @@ Usage: zetachain ask [options] [prompt...]
Chat with ZetaChain Docs AI

Arguments:
prompt Prompt to send to AI
prompt Prompt to send to AI

Options:
-h, --help display help for command
--non-interactive Run in non-interactive mode
-h, --help display help for command

```
13 changes: 12 additions & 1 deletion src/commands/ask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@ import { streamChatResponse } from "./ask/streaming";
import { createChatSpinner } from "./ask/ui";
import { validateAndSanitizePrompt } from "./ask/validation";

const main = async (promptParts: string[]): Promise<void> => {
const main = async (
promptParts: string[],
options?: { nonInteractive?: boolean },
): Promise<void> => {
const nonInteractive = Boolean(options?.nonInteractive);
let conversationId: string = uuidv4();
const messages: { content: string; role: "assistant" | "user" }[] = [];
let nextPrompt = promptParts.join(" ").trim();
while (true) {
let prompt = nextPrompt;
if (!prompt) {
if (nonInteractive) {
return;
}
try {
const { input } = await inquirer.prompt([
{ message: "Ask ZetaChain", name: "input", type: "input" },
Expand Down Expand Up @@ -66,6 +73,9 @@ const main = async (promptParts: string[]): Promise<void> => {
if (assistantBuffer.trim()) {
messages.push({ content: assistantBuffer, role: "assistant" });
}
if (nonInteractive) {
return;
}
} catch (securityError) {
const message =
securityError instanceof Error
Expand All @@ -81,4 +91,5 @@ const main = async (promptParts: string[]): Promise<void> => {
export const askCommand = new Command("ask")
.description("Chat with ZetaChain Docs AI")
.argument("[prompt...]", "Prompt to send to AI")
.option("--non-interactive", "Run in non-interactive mode")
.action(main);