Created
January 27, 2024 23:37
-
-
Save serverlessnomad/6c5c8c63185383427378b3fb2313130a to your computer and use it in GitHub Desktop.
Shell function and alias to refresh Ollama models
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ollama_refresh() { | |
pattern=$1 | |
if [[ -n $pattern ]]; then | |
# Modify the grep command to handle patterns | |
# If pattern ends with '*', use '^' to match the start of the line | |
# Else, use the pattern as is | |
if [[ $pattern == *'*' ]]; then | |
modified_pattern="^${pattern%*}" | |
for i in $(ollama list | grep -v NAME | grep "$modified_pattern" | awk '{print $1}') | |
do | |
ollama pull $i | |
done | |
else | |
for i in $(ollama list | grep -v NAME | grep "$pattern" | awk '{print $1}') | |
do | |
ollama pull $i | |
done | |
fi | |
else | |
# If no pattern is provided, proceed as before | |
for i in $(ollama list | grep -v NAME | awk '{print $1}') | |
do | |
ollama pull $i | |
done | |
fi | |
} | |
alias olr='ollama_refresh' |
Author
serverlessnomad
commented
Jan 27, 2024
- olr alias will refresh all models.
- olr "llama2*" will refresh all models matching the pattern.
- olr :latest will refresh all models with a :latest tag.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment