simonw / llm

Access large language models from the command-line
https://llm.datasette.io
Apache License 2.0
3.42k stars 176 forks source link

Autocomplete online cli #512

Open lzumot opened 2 weeks ago

lzumot commented 2 weeks ago

LLM can generate suggested completions in the cli based on written commands or context of previous command and current directory/files using the completion and fim functions but without needing to use FILL. Suggestions use different color to the current text and tab or other button allows toggling suggestions, shift enter accepts suggestion.

lzumot commented 6 days ago
# basic and flawed first implementation 
# General autocomplete function that uses llm to generate suggestions  
_llm_general_autocomplete() {  
    # Get the current word and the entire line input up to the cursor  
    local current_word="${COMP_WORDS[COMP_CWORD]}"  
    local line_input="${COMP_LINE}"  

    # Call llm with the entire line input to get suggestions  
    # Adjust the command to fit the requirements of your llm setup  
    local suggestions=$(llm -m gpt-3.5-turbo "Suggest bash commands or arguments for: '$line_input'")  

    # Convert llm output into an array, assuming newline-separated suggestions  
    local IFS=$'\n'  
    COMPREPLY=($(compgen -W "$suggestions" -- "$current_word"))  
}  

# Use Bash complete to specify the autocomplete function for all commands  
complete -F _llm_general_autocomplete -D