Skip to main content

CMDLLM

中文

CMDLLM is an intelligent interface for interacting with command-line tools using natural language. It supports any command-line tool, such as bash, kubectl, ros2, etc. It leverages Large Language Models (LLM) to translate your natural language queries into corresponding commands and provides options to execute these commands.

The original purpose of developing this tool was to help myself quickly use the podman command line. Since my new company doesn't allow the use of docker commands, I was struggling to adapt from docker to podman. So I tried to develop this tool, and after several updates, I decided to open-source it. I hope it will be useful to you.

Features

  • Multi-tool Support: Works with any command-line tool, such as Bash, kubectl, ros2, docker, etc.
  • Natural Language Processing: Translates everyday language into corresponding tool commands.
  • Command Execution: Offers the option to directly execute suggested commands.
  • Context Management: Maintains conversation history to support more complex interactions.
  • Safety Prompts: Provides warnings and confirmations for potentially dangerous operations (like deleting data).
  • Interactive Sessions: Supports both interactive session mode and one-time query mode.
  • Command-line Configuration: Provides convenient command-line configuration management without the need to manually edit configuration files.
  • Multiple LLM Providers: Supports OpenAI API-compatible services and Azure OpenAI services (such as OpenAI, DeepSeek, etc.).

Installation

From PyPI

pip install cmdllm

From Source Code

git clone https://github.com/yexia553/cmdllm.git
cd cmdllm
pip install -e .

Usage

Basic Usage

CMDLLM provides an interactive session mode:

Interactive Session Mode

Start an interactive session with a specific tool:

cmdllm chat -t bash

This will start an interactive session where you can input multiple queries continuously, and the program will maintain the context. Type exit or quit to end the session.

Bash Interactive Session Example

$ cmdllm chat -t bash

Starting interactive bash session. Type 'exit' or 'quit' to end.
-----------------------------------------------------
bash> List all files in the current directory
Processing your query...

Suggested command:
  ls -la

Execution result:
total 64
drwxr-xr-x  15 user  staff   480  5 Jun 15:30 .
drwxr-xr-x  25 user  staff   800  5 Jun 14:22 ..
-rw-r--r--   1 user  staff  1550  5 Jun 15:30 LICENSE
-rw-r--r--   1 user  staff   133  5 Jun 15:30 MANIFEST.in
-rw-r--r--   1 user  staff  3122  5 Jun 15:30 README.md
...

-----------------------------------------------------
bash> Create a directory named test

Processing your query...

Suggested command:
  mkdir test

Execution result:

-----------------------------------------------------
bash> exit
Exiting chat session.

Kubectl Interactive Session Example

$ cmdllm chat -t kubectl

Starting interactive kubectl session. Type 'exit' or 'quit' to end.
-----------------------------------------------------
kubectl> List all namespaces
Processing your query...

Suggested command:
  kubectl get namespaces

Execution result:
NAME              STATUS   AGE
default           Active   45d
kube-node-lease   Active   45d
kube-public       Active   45d
kube-system       Active   45d
-----------------------------------------------------
kubectl> Show all pods in the default namespace
Processing your query...

Suggested command:
  kubectl get pods -n default

Execution result:
NAME                           READY   STATUS    RESTARTS   AGE
nginx-deployment-66b6c48dd5-8ph2j   1/1     Running   0          24h
nginx-deployment-66b6c48dd5-vb6l8   1/1     Running   0          24h
-----------------------------------------------------
kubectl> Describe the first nginx pod

Processing your query...

Suggested command:
  kubectl describe pod nginx-deployment-66b6c48dd5-8ph2j -n default

Execution result:
Name:             nginx-deployment-66b6c48dd5-8ph2j
Namespace:        default
Priority:         0
Service Account:  default
Node:             minikube/192.168.49.2
Start Time:       Thu, 21 Mar 2024 09:30:42 +0800
...
Events:
  Type    Reason     Age   From               Message
  ----    ------     ----  ----               -------
  Normal  Scheduled  24h   default-scheduler  Successfully assigned default/nginx-deployment-66b6c48dd5-8ph2j to minikube
  Normal  Pulled     24h   kubelet            Container image "nginx:1.14.2" already present on machine
  Normal  Created    24h   kubelet            Created container nginx
  Normal  Started    24h   kubelet            Started container nginx
-----------------------------------------------------
kubectl> exit
Exiting chat session.

Configuration

CMDLLM provides convenient command-line configuration management without the need to manually edit configuration files.

Interactive Configuration

The simplest way is to use the interactive configuration command to set up the LLM provider:

cmdllm config setup

This will guide you through setting up all necessary LLM configuration items, such as API keys, endpoints, model or deployment names. You can choose to use either OpenAI API-compatible services or Azure OpenAI services.

Command-line Tool Management

CMDLLM provides dedicated commands for managing available command-line tools:

# View all available tools
cmdllm tools list

# Add a new tool
cmdllm tools add kubectl

# Remove a tool
cmdllm tools del kubectl

Configuring Azure OpenAI

cmdllm config setup can help you configure interactively, but if you want to configure or modify a single option, you can use the following commands to configure manually:

# Set LLM provider to Azure
cmdllm config set llm_provider azure

# Configure Azure OpenAI parameters, remember to replace the values with your actual values
cmdllm config set azure.api_key YOUR_AZURE_API_KEY
cmdllm config set azure.endpoint https://your-resource-name.openai.azure.com
cmdllm config set azure.deployment your-deployment-name
cmdllm config set azure.api_version 2023-05-15

Configuring OpenAI API-compatible Services

If you want to use OpenAI API-compatible services (such as OpenAI, DeepSeek, etc.):

# Set LLM provider to OpenAI compatible
cmdllm config set llm_provider openai_compatible

# Configure OpenAI compatible parameters, remember to replace the values with your actual values
cmdllm config set openai_compatible.api_key YOUR_API_KEY
cmdllm config set openai_compatible.base_url https://api.openai.com/v1
cmdllm config set openai_compatible.model gpt-3.5-turbo

Managing Context Message Count

You can set the maximum number of messages carried in the conversation, default is 20:

# Set context message count
cmdllm config set-context-messages 10

# View current context message setting
cmdllm config get-context-messages

View Current Configuration

cmdllm config list

Get Individual Configuration Item

cmdllm config get llm_provider
cmdllm config get azure.endpoint

Reset Configuration

cmdllm config init

Manually Edit Configuration File

If you still want to manually edit the configuration file, CMDLLM's configuration file is located at ~/.cmdllm/config.yaml:

tools:
- bash
- kubectl
- ros2

llm_provider: openai_compatible  # LLM provider being used: openai_compatible or azure

openai_compatible:
  base_url: https://api.openai.com/v1  # OpenAI compatible API endpoint
  api_key: your_API_key  # API key
  model: gpt-3.5-turbo  # Model being used

azure:
  api_key: your_Azure_key  # Azure OpenAI API key
  endpoint: https://your-resource-name.openai.azure.com  # Azure endpoint
  deployment: your-deployment-name  # Azure model deployment name
  api_version: 2023-05-15  # Azure API version

context:
  max_messages: 10  # Maximum number of messages saved in context

Supported LLM services:

  • OpenAI API-compatible services (such as OpenAI, DeepSeek, etc.)
  • Azure OpenAI

Clearing Context

$ cmdllm clear
Context has been successfully cleared.

Notes

  • Before use, ensure that the corresponding command-line tools are installed on your system and available in the PATH.
  • Some operations may require administrator privileges.
  • Commands generated by large language models are assessed for risk by the model itself before execution, but this process has certain security issues

License

This project is licensed under the Apache 2.0 License - see the LICENSE file for details.

Metadata

Release files for cmdllm 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cmdllm 0.1.2
File Size Uploaded Provenance
cmdllm-0.1.2.tar.gz 20.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for cmdllm 0.1.2
File Interpreter ABI Platform
cmdllm-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 40.5 kB

Release files / cmdllm-0.1.2.tar.gz

Download URL cmdllm-0.1.2.tar.gz
Size 20.7 kB
Tags Source
SHA-256 checksum
How to use checksums
c82da5d0781c88e17fb3068b7c8c040b5035e85a45f018abd7f8036ec1d0f96a
BLAKE2b-256 checksum
How to use checksums
dcc3e638040a736104add710567c3a94181f362e657d9ebd58432ac7b3f46af2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.8

Release files / cmdllm-0.1.2-py3-none-any.whl

Download URL cmdllm-0.1.2-py3-none-any.whl
Size 19.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d4e28a3587501adc7a8bb9dd814529ad578dae3ed0965117aaf0aab95e1d47e3
BLAKE2b-256 checksum
How to use checksums
c4f2bab22271c7525770e10b233f6ef46d74daac0dd0fd7cda706148aa7bd490
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.8

Security for cmdllm 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page