@@ -124,7 +124,6 @@ replace_tokens() {
124124 ' " $@ "
125125}
126126
127-
128127# build_prompt [--project-title X] [--version V] [--example E] [--rules R] \
129128# <template_file> <diff_file>
130129#
@@ -373,37 +372,59 @@ generate_remote() {
373372 # print_debug "Parsed response:$result"
374373 echo " ${result} "
375374}
376-
377375run_local () {
376+ # Backup original values of OLLAMA_TEMPERATURE and OLLAMA_NUM_CTX
377+ orig_ollama_temperature=" ${OLLAMA_TEMPERATURE:- } "
378+ orig_ollama_num_ctx=" ${OLLAMA_NUM_CTX:- } "
379+
380+ export OLLAMA_TEMPERATURE=" ${3:- 0.9} "
381+ export OLLAMA_NUM_CTX=" ${4:- 32768} "
382+
378383 if [ " $debug " = " true" ]; then
379384 # shellcheck disable=SC2154
380385 ollama run " ${model} " --verbose < " $1 "
381386 else
382387 ollama run " ${model} " < " $1 "
383388 fi
389+
390+ # Reset to original values after the command completes
391+ export OLLAMA_TEMPERATURE=" ${orig_ollama_temperature} "
392+ export OLLAMA_NUM_CTX=" ${orig_ollama_num_ctx} "
384393}
385394
386395# The `generate_response` function generates a response based on the specified mode.
387396#
388397# Parameters:
389398# $1 - Path to the input file.
390399# $2 (optional) - Mode for generating the response. Possible values are 'remote', 'none', or any other value for local generation.
400+ # $3 (optional) - Temperature setting for the model, if applicable.
401+ # $4 (optional) - Context window size for the model, if applicable.
391402#
392403# Description:
393404# The function determines the mode of operation based on the second argument ($2), falling back to the `model_mode` environment variable, and finally defaulting to 'auto'.
394405# If debugging is enabled (via the `debug` environment variable), it prints a debug message indicating the chosen mode.
395406#
396407# Depending on the mode:
397- # - 'remote': Calls the `generate_remote` function with the input file path as an argument.
408+ # - 'remote': Calls the `generate_remote` function with the input file path as an argument, along with temperature and context window size if provided .
398409# - 'none': Outputs the content of the input file directly using `cat`.
399- # - Any other value: Calls the `run_local` function with the input file path as an argument.
410+ # - Any other value: Calls the `run_local` function with the input file path as an argument, along with temperature and context window size if provided .
400411generate_response () {
401412 gen_mode=" ${2:- $model_mode :- auto} "
402- print_debug " Generating response using $gen_mode mode"
413+ temp=" ${3:- 0.9} " # Default to a neutral temperature of 1.0
414+ ctx_window=" ${4:- 32768} " # Default context window size
415+
416+ print_debug " Generating response using $gen_mode mode with temperature=$temp and context window size=$ctx_window "
417+
403418 case ${gen_mode} in
404- remote) generate_remote " $1 " ;;
405- none) cat " $1 " ;;
406- * ) run_local " $1 " ;;
419+ remote)
420+ generate_remote " $1 " " $temp " " $ctx_window "
421+ ;;
422+ none)
423+ cat " $1 "
424+ ;;
425+ * )
426+ run_local " $1 " " $temp " " $ctx_window "
427+ ;;
407428 esac
408429}
409430
@@ -418,13 +439,15 @@ generate_from_prompt() {
418439 prompt_file=" $1 "
419440 response_output_file=" $2 "
420441 gen_mode=" ${3:- ${GIV_MODEL_MODE:- ${model_mode:- auto} } } "
442+ temperature=" ${4:- 0.9} " # Default value for temperature
443+ context_window=" ${5:- 32768} " # Default value for context window
421444
422445 print_debug " Prompt file: $prompt_file "
423446 print_debug " Output file: $response_output_file "
424447 print_debug " Model mode: $gen_mode "
425448
426449 # 1) Invoke the AI
427- if ! res=$( generate_response " $prompt_file " " $gen_mode " ) ; then
450+ if ! res=$( generate_response " $prompt_file " " $gen_mode " " $temperature " " $context_window " ) ; then
428451 printf ' Error: generate_response failed (mode=%s)\n' " $gen_mode " >&2
429452 exit 1
430453 fi
@@ -784,7 +807,7 @@ summarize_commit() {
784807 summary_template=$( build_prompt --version " ${sc_version} " " ${TEMPLATE_DIR} /summary_prompt.md" " ${hist} " )
785808 print_debug " Using summary prompt: ${summary_template} "
786809 printf ' %s\n' " ${summary_template} " > " ${pr} "
787- res=$( generate_response " ${pr} " " ${gen_mode} " )
810+ res=$( generate_response " ${pr} " " ${gen_mode} " " 0.9 " " 32768 " )
788811 echo " ${res} " > " ${res_file} "
789812
790813 printf ' %s\n' " ${res} "
@@ -841,93 +864,96 @@ extract_section() {
841864 sed -n " ${start} ,${end} p" " $file "
842865}
843866
844-
845867is_glow_installed () {
846- command -v glow > /dev/null 2>&1
868+ command -v glow > /dev/null 2>&1
847869}
848870
849871install_pkg () {
850- echo " Checking package managers..."
851- if command -v brew > /dev/null 2>&1 ; then
852- brew install glow && return 0
853- elif command -v port > /dev/null 2>&1 ; then
854- sudo port install glow && return 0
855- elif command -v pacman > /dev/null 2>&1 ; then
856- sudo pacman -S --noconfirm glow && return 0
857- elif command -v xbps-install > /dev/null 2>&1 ; then
858- sudo xbps-install -Sy glow && return 0
859- elif command -v nix-shell > /dev/null 2>&1 ; then
860- nix-shell -p glow --run glow && return 0
861- elif command -v pkg > /dev/null 2>&1 && uname -s | grep -qi freebsd; then
862- sudo pkg install -y glow && return 0
863- elif command -v eopkg > /dev/null 2>&1 ; then
864- sudo eopkg install glow && return 0
865- elif command -v snap > /dev/null 2>&1 ; then
866- sudo snap install glow && return 0
867- elif command -v choco > /dev/null 2>&1 ; then
868- choco install glow -y && return 0
869- elif command -v scoop > /dev/null 2>&1 ; then
870- scoop install glow && return 0
871- elif command -v winget > /dev/null 2>&1 ; then
872- winget install --id=charmbracelet.glow -e && return 0
873- fi
874- return 1
872+ echo " Checking package managers..."
873+ if command -v brew > /dev/null 2>&1 ; then
874+ brew install glow && return 0
875+ elif command -v port > /dev/null 2>&1 ; then
876+ sudo port install glow && return 0
877+ elif command -v pacman > /dev/null 2>&1 ; then
878+ sudo pacman -S --noconfirm glow && return 0
879+ elif command -v xbps-install > /dev/null 2>&1 ; then
880+ sudo xbps-install -Sy glow && return 0
881+ elif command -v nix-shell > /dev/null 2>&1 ; then
882+ nix-shell -p glow --run glow && return 0
883+ elif command -v pkg > /dev/null 2>&1 && uname -s | grep -qi freebsd; then
884+ sudo pkg install -y glow && return 0
885+ elif command -v eopkg > /dev/null 2>&1 ; then
886+ sudo eopkg install glow && return 0
887+ elif command -v snap > /dev/null 2>&1 ; then
888+ sudo snap install glow && return 0
889+ elif command -v choco > /dev/null 2>&1 ; then
890+ choco install glow -y && return 0
891+ elif command -v scoop > /dev/null 2>&1 ; then
892+ scoop install glow && return 0
893+ elif command -v winget > /dev/null 2>&1 ; then
894+ winget install --id=charmbracelet.glow -e && return 0
895+ fi
896+ return 1
875897}
876898
877899install_from_github () {
878- echo " Installing glow binary from GitHub releases…"
879- os=$( uname -s | tr ' [:upper:]' ' [:lower:]' )
880- arch=$( uname -m)
881- case " $arch " in
882- x86_64|amd64) arch=" x86_64" ;;
883- arm64|aarch64) arch=" arm64" ;;
884- * ) echo " Unsupported arch: $arch " ; exit 1 ;;
885- esac
900+ echo " Installing glow binary from GitHub releases…"
901+ os=$( uname -s | tr ' [:upper:]' ' [:lower:]' )
902+ arch=$( uname -m)
903+ case " $arch " in
904+ x86_64 | amd64) arch=" x86_64" ;;
905+ arm64 | aarch64) arch=" arm64" ;;
906+ * )
907+ echo " Unsupported arch: $arch "
908+ exit 1
909+ ;;
910+ esac
886911
887- tag=$( curl -fsSL https://api.github.com/repos/charmbracelet/glow/releases/latest \
888- | grep ' "tag_name":' | sed -E ' s/.*"([^"]+)".*/\1/' )
889- file=" glow_${tag# v} _${os} _${arch} .tar.gz"
912+ tag=$( curl -fsSL https://api.github.com/repos/charmbracelet/glow/releases/latest |
913+ grep ' "tag_name":' | sed -E ' s/.*"([^"]+)".*/\1/' )
914+ file=" glow_${tag# v} _${os} _${arch} .tar.gz"
890915
891- tmpdir=$( mktemp -d)
892- curl -fsSL " https://github.com/charmbracelet/glow/releases/download/$tag /$file " -o " $tmpdir /glow.tar.gz"
893- curl -fsSL " https://github.com/charmbracelet/glow/releases/download/$tag /checksums.txt" -o " $tmpdir /checksums.txt"
916+ tmpdir=$( mktemp -d)
917+ curl -fsSL " https://github.com/charmbracelet/glow/releases/download/$tag /$file " -o " $tmpdir /glow.tar.gz"
918+ curl -fsSL " https://github.com/charmbracelet/glow/releases/download/$tag /checksums.txt" -o " $tmpdir /checksums.txt"
894919
895- cd " $tmpdir "
896- sha256sum -c checksums.txt --ignore-missing --quiet || {
897- echo " Checksum verification failed" ; exit 1;
898- }
920+ cd " $tmpdir "
921+ sha256sum -c checksums.txt --ignore-missing --quiet || {
922+ echo " Checksum verification failed"
923+ exit 1
924+ }
899925
900- tar -xzf glow.tar.gz
901- chmod +x glow
926+ tar -xzf glow.tar.gz
927+ chmod +x glow
902928
903- bindir=" /usr/local/bin"
904- if [ -w " $bindir " ]; then
905- mv glow " $bindir "
906- else
907- sudo mv glow " $bindir "
908- fi
929+ bindir=" /usr/local/bin"
930+ if [ -w " $bindir " ]; then
931+ mv glow " $bindir "
932+ else
933+ sudo mv glow " $bindir "
934+ fi
909935
910- cd -
911- rm -rf " $tmpdir "
936+ cd -
937+ rm -rf " $tmpdir "
912938
913- echo " glow installed to $bindir "
939+ echo " glow installed to $bindir "
914940}
915941
916942ensure_glow () {
917- if is_installed; then
918- echo " ✔ glow already installed: $( command -v glow) "
919- return
920- fi
943+ if is_installed; then
944+ echo " ✔ glow already installed: $( command -v glow) "
945+ return
946+ fi
921947
922- echo " ✗ glow not found. Installing…"
923- if install_pkg; then
924- echo " Installed via package manager."
925- else
926- install_from_github
927- fi
948+ echo " ✗ glow not found. Installing…"
949+ if install_pkg; then
950+ echo " Installed via package manager."
951+ else
952+ install_from_github
953+ fi
928954
929- if ! is_installed; then
930- echo " Installation failed. See https://github.com/charmbracelet/glow#installation"
931- exit 1
932- fi
955+ if ! is_installed; then
956+ echo " Installation failed. See https://github.com/charmbracelet/glow#installation"
957+ exit 1
958+ fi
933959}
0 commit comments