docs: add examples using bash to compare models
Signed-off-by: Matt Williams <m@technovangelist.com>
This commit is contained in:
parent
ad88799411
commit
2236a93efc
4 changed files with 75 additions and 0 deletions
9
examples/bash-comparemodels/README.md
Normal file
9
examples/bash-comparemodels/README.md
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# Bash Shell examples
|
||||||
|
|
||||||
|
When calling `ollama`, you can pass it a file to run all the prompts in the file, one after the other. This concept is used in two examples
|
||||||
|
|
||||||
|
## Bulk Questions
|
||||||
|
`bulkquestions.sh` is a script that runs all the questions in `sourcequestions` using the llama2 model and outputs the answers.
|
||||||
|
|
||||||
|
## Compare Models
|
||||||
|
`comparemodels.sh` is a script that runs all the questions in `sourcequestions` using any 4 models you choose that you have already pulled from the registry or have created locally.
|
3
examples/bash-comparemodels/bulkquestions.sh
Executable file
3
examples/bash-comparemodels/bulkquestions.sh
Executable file
|
@ -0,0 +1,3 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
ollama run llama2 < sourcequestions
|
56
examples/bash-comparemodels/comparemodels.sh
Executable file
56
examples/bash-comparemodels/comparemodels.sh
Executable file
|
@ -0,0 +1,56 @@
|
||||||
|
#! /usr/bin/env bash
|
||||||
|
NUMBEROFCHOICES=4
|
||||||
|
CHOICES=$(ollama list | awk '{print $1}')
|
||||||
|
SELECTIONS=()
|
||||||
|
declare -a SUMS=()
|
||||||
|
|
||||||
|
echo "Select $NUMBEROFCHOICES models to compare:"
|
||||||
|
select ITEM in $CHOICES; do
|
||||||
|
if [[ -n $ITEM ]]; then
|
||||||
|
echo "You have selected $ITEM"
|
||||||
|
SELECTIONS+=("$ITEM")
|
||||||
|
((COUNT++))
|
||||||
|
if [[ $COUNT -eq $NUMBEROFCHOICES ]]; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Invalid selection"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
for ITEM in "${SELECTIONS[@]}"; do
|
||||||
|
echo "--------------------------------------------------------------"
|
||||||
|
echo "Loading the model $ITEM into memory"
|
||||||
|
ollama run "$ITEM" ""
|
||||||
|
echo "--------------------------------------------------------------"
|
||||||
|
echo "Running the questions through the model $ITEM"
|
||||||
|
COMMAND_OUTPUT=$(ollama run "$ITEM" --verbose < sourcequestions 2>&1| tee /dev/stderr)
|
||||||
|
|
||||||
|
SUM=$(echo "$COMMAND_OUTPUT" | awk '
|
||||||
|
/eval duration:/ {
|
||||||
|
value = $3
|
||||||
|
if (index(value, "ms") > 0) {
|
||||||
|
gsub("ms", "", value)
|
||||||
|
value /= 1000
|
||||||
|
} else {
|
||||||
|
gsub("s", "", value)
|
||||||
|
}
|
||||||
|
sum += value
|
||||||
|
}
|
||||||
|
END { print sum }')
|
||||||
|
|
||||||
|
|
||||||
|
SUMS+=("All questions for $ITEM completed in $SUM seconds")
|
||||||
|
done
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "--------------------------------------------------------------"
|
||||||
|
echo -e "Sums of eval durations for each run:"
|
||||||
|
for val in "${SUMS[@]}"; do
|
||||||
|
echo "$val"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "--------------------------------------------------------------"
|
||||||
|
echo "Comparison complete. Now you can decide"
|
||||||
|
echo "which model is best."
|
||||||
|
echo "--------------------------------------------------------------"
|
7
examples/bash-comparemodels/sourcequestions
Normal file
7
examples/bash-comparemodels/sourcequestions
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
Why is the sky blue
|
||||||
|
What is a black hole
|
||||||
|
Explain the big bang theory like I am 5?
|
||||||
|
What is the quickest way to win a game of Monopoly with 3 others?
|
||||||
|
Why does a vacuum bottle keep my coffee hot and my milkshake cold?
|
||||||
|
What is the difference between a meteor, a meteorite, and a meteoroid?
|
||||||
|
Create an array with 5 items and print to the console. Do this in Python, C#, Typescript, and Rust.
|
Loading…
Reference in a new issue