From b09da81d523fa34774771b22f420573685d9489c Mon Sep 17 00:00:00 2001 From: Ben Siraphob Date: Fri, 31 Mar 2023 17:37:33 -0500 Subject: [PATCH] Use getopts for example scripts --- examples/chat-13B.sh | 18 ++++++++++++++++-- examples/reason-act.sh | 19 +++++++++++-------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/examples/chat-13B.sh b/examples/chat-13B.sh index 4265d7b66..04a4afb2e 100755 --- a/examples/chat-13B.sh +++ b/examples/chat-13B.sh @@ -1,4 +1,18 @@ -#!/bin/bash +#!/usr/env/bin bash + +while getopts "m:u:a:t:p:g:" opt; do + case $opt in + m) MODEL="--model $OPTARG";; + u) USER_NAME="$OPTARG";; + a) AI_NAME="$OPTARG";; + t) N_THREAD="$OPTARG";; + p) N_PREDICTS="$OPTARG";; + g) GEN_OPTIONS="$OPTARG";; + \?) echo "Invalid option -$OPTARG" >&2; exit 1;; + esac +done + +shift $((OPTIND-1)) cd "$(dirname "$0")/.." || exit @@ -17,7 +31,7 @@ GEN_OPTIONS="${GEN_OPTIONS:---ctx_size 2048 --temp 0.7 --top_k 40 --top_p 0.5 -- # shellcheck disable=SC2086 # Intended splitting of GEN_OPTIONS ./main $GEN_OPTIONS \ - --model "$MODEL" \ + $MODEL \ --threads "$N_THREAD" \ --n_predict "$N_PREDICTS" \ --color --interactive \ diff --git a/examples/reason-act.sh b/examples/reason-act.sh index e7fe655db..a8c134686 100755 --- a/examples/reason-act.sh +++ b/examples/reason-act.sh @@ -1,15 +1,18 @@ +#!/usr/env/bin bash -#!/bin/bash +while getopts "m:" opt; do + case $opt in + m) MODEL="-m $OPTARG";; + \?) echo "Invalid option -$OPTARG" >&2; exit 1;; + esac +done -cd `dirname $0` +shift $((OPTIND-1)) + +cd "$(dirname "$0")" cd .. -# get -m model parameter otherwise defer to default -if [ "$1" == "-m" ]; then - MODEL="-m $2 " -fi - -./main $MODEL --color \ +./bin/main $MODEL --color \ -f ./prompts/reason-act.txt \ -i --interactive-first \ --top_k 10000 --temp 0.2 --repeat_penalty 1 -t 7 -c 2048 \