The openai module provides a comprehensive CLI interface for OpenAI services, enabling users to perform complex AI tasks like text generation, translation, image creation, and audio conversion directly from the terminal.
When to Activate
- When the user wants to use OpenAI for chat or text generation (e.g., generating commit messages).
- When the user needs to translate file contents using AI.
- When the user wants to generate images based on text prompts.
- When the user needs to convert text to speech or transcribe audio.
- When managing OpenAI API keys or model configurations.
Core Principles & Rules
- API Key Management: Use
initor--cfg apikey=<key>to set up the environment. - File Input: Use the
--fileflag to provide context from local files to the chat/generation subcommands. - Reproducibility: Be aware that AI outputs can vary; use appropriate parameters for consistent results if needed.
Additional Scenarios
- Git Commit Messages: Pipe
git diffinto@gptto generate standardized commit messages. - Audio Processing: Use the
audiosubcommand for TTS (Text-to-Speech) or transcription tasks. - Embedding & Fine-tuning: Advanced users can manage fine-tuned models or calculate text embeddings.
Patterns & Examples
Chat with File Context
# Translate multiple files to Chinese using OpenAI
x openai chat request --file ./abstract.en.md --file ./content.en.md "Translate to chinese"
Image Generation
# Generate an image based on a prompt
x openai image create --prompt "a high-quality digital art of a futuristic city"
Text to Speech
# Convert text to an audio file
x openai audio generate --input "Welcome to x-cmd" --model tts-1 --voice alloy
Generate Commit Message
# Pipe diff into gpt for commit message generation
git diff | @gpt "generate a suitable Git commit message that follows the Conventional Commits format"
Checklist
- Ensure the OpenAI API key is configured using
x openai init. - Verify the input files exist when using the
--fileflag. - Confirm the desired model and voice for audio generation.