#[cfg(feature = "cli")]
use clap::builder::styling::{AnsiColor, Effects, Styles};
#[cfg(feature = "cli")]
use clap::{Args, Parser, Subcommand};
#[cfg(feature = "cli")]
fn styles() -> Styles {
Styles::styled()
.header(AnsiColor::Cyan.on_default() | Effects::BOLD)
.usage(AnsiColor::Cyan.on_default() | Effects::BOLD)
.literal(AnsiColor::Blue.on_default() | Effects::BOLD)
.error(AnsiColor::Red.on_default() | Effects::BOLD)
.placeholder(AnsiColor::Green.on_default())
}
#[cfg(feature = "cli")]
#[derive(Parser, Debug, Clone)]
#[command(
author = "Mahmoud Harmouch",
version,
name = "xai",
propagate_version = true,
styles = styles(),
help_template = r#"{about}
{usage-heading} {usage}
{all-args}{after-help}
AUTHORS:
{author}
"#,
about = r#"
█████ █████ █████████ █████
▒▒███ ▒▒███ ███▒▒▒▒▒███ ▒▒███
▒▒███ ███ ▒███ ▒███ ▒███
▒▒█████ ▒███████████ ▒███
███▒███ ▒███▒▒▒▒▒███ ▒███
███ ▒▒███ ▒███ ▒███ ▒███
█████ █████ █████ █████ █████
▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒
A command-line tool for interacting with the xAI Grok API.
FUNCTIONALITIES:
- Chat Completions : Chat with Grok models.
- Text Completions : Legacy text completions.
- Embeddings : Create text embeddings.
- List Models : List all available models.
- Get Model : Get info about a specific model.
- API Key Info : Inspect the current API key.
USAGE:
xai [OPTIONS] <COMMAND>
EXAMPLES:
Run TUI (default):
xai
Chat:
xai chat -t "What is the answer to life?"
Stream chat:
xai chat -t "Tell me a story" --stream
Text completion (legacy):
xai complete -p "Once upon a time"
Create embeddings:
xai embed -t "Hello world"
List models:
xai models
Get model info:
xai model -m grok-4
API key info:
xai apikey
For more information, visit: github.com/wiseaidotdev/x-ai
"#
)]
pub struct Cli {
#[arg(short = 'k', long)]
pub api_key: Option<String>,
#[arg(short, long)]
pub model: Option<String>,
#[command(subcommand)]
pub cmd: Option<Command>,
}
#[cfg(feature = "cli")]
#[derive(Subcommand, Debug, Clone)]
pub enum Command {
Chat(Chat),
Complete(Complete),
Embed(Embed),
Models(Models),
Model(ModelInfo),
Apikey(Apikey),
}
#[cfg(feature = "cli")]
#[derive(Args, Debug, Clone)]
pub struct Chat {
#[arg(short, long)]
pub text: String,
#[arg(short, long, default_value_t = false)]
pub stream: bool,
}
#[cfg(feature = "cli")]
#[derive(Args, Debug, Clone)]
pub struct Complete {
#[arg(short, long)]
pub prompt: String,
#[arg(long, default_value_t = 256)]
pub max_tokens: u32,
}
#[cfg(feature = "cli")]
#[derive(Args, Debug, Clone)]
pub struct Embed {
#[arg(short, long)]
pub text: String,
#[arg(short, long, default_value = "float")]
pub encoding_format: String,
}
#[cfg(feature = "cli")]
#[derive(Args, Debug, Clone)]
pub struct Models {}
#[cfg(feature = "cli")]
#[derive(Args, Debug, Clone)]
pub struct ModelInfo {
#[arg(short, long)]
pub model_id: String,
}
#[cfg(feature = "cli")]
#[derive(Args, Debug, Clone)]
pub struct Apikey {}