@catalystlabs/tryai-cli
v1.0.1
Published
CLI tool for TryAI - The Rails of AI Integration
Maintainers
Readme
TryAI CLI
The TryAI CLI is a comprehensive command-line tool that extends the TryAI library with interactive prompt execution, template management, and database synchronization capabilities.
Features
- Zero-config setup - Works out of the box
- Interactive REPL mode - Chat with AI models directly
- Template management - Database-backed template versioning
- Batch processing - Process multiple inputs efficiently
- Cost tracking - Monitor your AI usage and costs
- Testing & benchmarking - Validate template performance
- Template Studio - Web-based template editor (coming soon)
Installation
npm install -g @catalystlabs/tryai-cliQuick Start
# Initialize templates (creates .tryai/config.ts and database)
tryai templates init
# Run a simple prompt
tryai prompt "Explain quantum computing in simple terms"
# Start interactive mode
tryai interactive
# Start chat mode
tryai chat --model gpt-4o
# Run a template with variables
tryai run my-template --var name=John --var topic="AI"Commands
Basic Commands
tryai prompt <text>
Execute a simple prompt with AI.
tryai prompt "Write a haiku about coding"
tryai prompt "Explain REST APIs" --model claude-3-5-sonnet --format markdown
tryai prompt "Analyze this data" --system "You are a data scientist" --max-tokens 500Options:
-m, --model <model>- Model to use (default: gpt-4o-mini)-s, --stream- Stream the response-f, --format <format>- Output format (json|markdown|plain)-o, --output <file>- Save output to file--max-tokens <number>- Maximum tokens to generate--temperature <number>- Temperature (0-2)--system <text>- System prompt
tryai run <template>
Run a template with variables.
tryai run code-review --var language=python --var code="def hello(): print('hi')"
tryai run email-writer --var tone=professional --var purpose="meeting request"Options:
-v, --var <key=value...>- Template variables-m, --model <model>- Model to use-s, --stream- Stream the response-f, --format <format>- Output format-o, --output <file>- Save output to file
Interactive Modes
tryai interactive (alias: tryai i)
Start interactive REPL mode with a rich UI.
Features:
- Real-time chat with AI
- Slash commands (/help, /clear, /model, /cost, /exit)
- Token and cost tracking
- Model switching
- Conversation history
tryai chat
Start conversation mode in terminal.
tryai chat --model gpt-4o --system "You are a helpful coding assistant"Options:
-m, --model <model>- Model to use-s, --system <text>- System prompt--max-tokens <number>- Maximum tokens--temperature <number>- Temperature
Template Management
tryai templates init
Initialize template database and configuration.
Creates:
.tryai/config.ts- Configuration file.tryai/templates.db- SQLite database (or configured database)
tryai templates list (alias: tryai templates ls)
List all available templates.
tryai templates listtryai templates show <name>
Show template details including variables and configuration.
tryai templates show code-reviewtryai templates push <file>
Push a template file to the database.
tryai templates push ./templates/email-writer.toml --name email-writerTemplate file format (TOML):
[metadata]
description = "Professional email writer"
author = "Your Name"
version = "1.0.0"
tags = ["email", "business", "communication"]
[config]
model = "gpt-4o"
temperature = 0.7
max_tokens = 500
[variables]
[variables.recipient]
type = "string"
description = "Email recipient name"
required = true
[variables.purpose]
type = "string"
description = "Purpose of the email"
required = true
[variables.tone]
type = "string"
description = "Email tone"
default = "professional"
prompt = """
Write a {{tone}} email to {{recipient}} about {{purpose}}.
Make it clear, concise, and appropriate for a business context.
"""tryai templates pull <name>
Pull a template from database to file.
tryai templates pull email-writer --output email-writer.tomltryai templates diff <name>
Show changes between template versions.
tryai templates diff email-writer --version 2Batch Processing
tryai batch <command>
Process multiple inputs in batch.
# From JSON array file
tryai batch "Summarize: \${input}" --input prompts.json --output results.json
# From newline-delimited file
tryai batch "Translate to Spanish: \${input}" --input sentences.txt --concurrency 5Input file formats:
- JSON array:
["text 1", "text 2", "text 3"] - Newline-delimited: Each line is a separate input
Options:
-i, --input <file>- Input file (required)-o, --output <file>- Output file-c, --concurrency <number>- Concurrent requests (default: 3)-m, --model <model>- Model to use
Testing & Benchmarking
tryai test <template>
Test a template with sample data.
tryai test email-writer --var recipient=John --var purpose="meeting" --samples 5
tryai test json-parser --validate-json --samples 10Options:
-v, --var <key=value...>- Template variables-s, --samples <number>- Number of test samples (default: 1)--validate-json- Validate JSON output format--validate-schema <file>- Validate against JSON schema
tryai benchmark <template>
Performance benchmark a template.
tryai benchmark code-review --iterations 50 --concurrency 3
tryai benchmark fast-summary --iterations 100 --warmup 5Options:
-n, --iterations <number>- Number of iterations (default: 10)-c, --concurrency <number>- Concurrent requests (default: 1)--warmup <number>- Warmup iterations (default: 2)
Statistics & Environment
tryai stats
Show usage statistics.
tryai stats --detailedtryai env list
List current configuration.
tryai env listtryai env use <provider> [model]
Set default provider and model.
tryai env use openai gpt-4o
tryai env use anthropic claude-3-5-sonnetConfiguration
Config File Structure
The CLI creates a .tryai/config.ts file for configuration:
import type { TryAIConfig } from '@catalystlabs/tryai-cli';
const config: TryAIConfig = {
defaultModel: 'gpt-4o-mini',
defaultProvider: 'openai',
// Template database configuration
templates: {
database: {
type: 'sqlite',
connection: '.tryai/templates.db'
}
},
// API keys (can also use environment variables)
apiKeys: {
openai: process.env.OPENAI_API_KEY,
anthropic: process.env.ANTHROPIC_API_KEY,
google: process.env.GOOGLE_API_KEY,
llama: process.env.LLAMA_API_KEY,
}
};
export default config;Environment Variables
Set API keys via environment variables:
export OPENAI_API_KEY="your-key-here"
export ANTHROPIC_API_KEY="your-key-here"
export GOOGLE_API_KEY="your-key-here"
export LLAMA_API_KEY="your-key-here"Database Support
The CLI supports multiple database types for template storage:
- SQLite (default): Local file-based database
- PostgreSQL: For team/production use
- MySQL: Alternative production option
// PostgreSQL example
templates: {
database: {
type: 'postgres',
connection: 'postgresql://user:password@localhost:5432/tryai'
}
}
// MySQL example
templates: {
database: {
type: 'mysql',
connection: 'mysql://user:password@localhost:3306/tryai'
}
}Examples
Creating a Code Review Template
- Create
code-review.toml:
[metadata]
description = "AI-powered code review assistant"
tags = ["code", "review", "quality"]
[config]
model = "gpt-4o"
temperature = 0.3
[variables]
[variables.language]
type = "string"
description = "Programming language"
required = true
[variables.code]
type = "string"
description = "Code to review"
required = true
[variables.focus]
type = "string"
description = "Review focus (security, performance, style)"
default = "general"
prompt = """
Review this {{language}} code with focus on {{focus}}:
```{{language}}
{{code}}Provide:
- Overall assessment
- Specific issues found
- Suggestions for improvement
- Security considerations (if applicable)
Be constructive and educational in your feedback. """
2. Push to database:
```bash
tryai templates push code-review.toml- Use the template:
tryai run code-review \
--var language=python \
--var focus=security \
--var code="def authenticate(password): return password == 'admin'"Batch Processing Example
Process multiple code files for review:
- Create
files.json:
[
"def user_login(pwd): return pwd == 'password123'",
"SELECT * FROM users WHERE id = '" + user_id + "'",
"function validateEmail(email) { return true; }"
]- Run batch review:
tryai batch "Review this code for security issues: \${input}" \
--input files.json \
--output security-review.json \
--model gpt-4o \
--concurrency 3Performance Testing
Test and benchmark your templates:
# Test with various inputs
tryai test code-review \
--var language=javascript \
--var code="console.log('test')" \
--samples 10
# Benchmark performance
tryai benchmark code-review \
--iterations 50 \
--concurrency 3 \
--warmup 5Coming Soon
- Template Studio: Web-based template editor with visual workflow builder
- Team Collaboration: Share templates across team members
- Template Marketplace: Discover and share templates with the community
- Advanced Analytics: Detailed usage and performance analytics
- CI/CD Integration: Template testing in continuous integration pipelines
Support
For issues and feature requests, visit: GitHub Issues
License
MIT License - see LICENSE file for details.
