Skip to content

Commit

Permalink
Small maintenance update.
Browse files Browse the repository at this point in the history
Inspired by Ollama project commit ollama/ollama@c2e8cba, I reviewed all our "[[ -[efs] file.ext ]]" tests to consider _not adding_ files with zero length to the request block, even though they will be recognised as possible file with payloads if the files exists.

Add a separation mark after dumping the contents of a text file/pdf/url and also after running a shell command, which may have dumped lots of text that the user will not recognise as part of hi own prompt at first, according to TheR1D/shell_gpt#638.

---
  • Loading branch information
mountaineerbr committed Nov 10, 2024
1 parent cf67626 commit 0cb7376
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 28 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1310,9 +1310,7 @@ Not all features of the API will be covered.

- This project _doesn't_ support "Function Calling" or "Structured Outputs".

- Probably, we will _not_ support "Real-Time" chatting.

- We _aren't_ very much keen on implementing video capabilities.
- Probably, we will _not_ support "Real-Time" chatting, or video modality.

- Bash shell truncates input on `\000` (null).

Expand Down
23 changes: 13 additions & 10 deletions chatgpt.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
# chatgpt.sh -- Shell Wrapper for ChatGPT/DALL-E/Whisper/TTS
# v0.85.3 nov/2024 by mountaineerbr GPL+3
# v0.85.4 nov/2024 by mountaineerbr GPL+3
set -o pipefail; shopt -s extglob checkwinsize cmdhist lithist histappend;
export COLUMNS LINES; ((COLUMNS>2)) || COLUMNS=80; ((LINES>2)) || LINES=24;

Expand Down Expand Up @@ -2343,6 +2343,7 @@ function cmd_runf
[NnOo]|[!Ss]|'') SKIP=1 PSKIP=1; break;; #no need to edit
esac; set --;
done; _clr_lineupf $((12+1+47)); #!#

((opt_append)) && [[ $REPLY != [/!]* ]] && REPLY=:$REPLY;
((${#args[@]})) && shell_histf "!${args[*]}";
((RET==200)) || REPLY_CMD_BLOCK=1 SKIP_SH_HIST=1;
Expand Down Expand Up @@ -2434,7 +2435,7 @@ function cmd_runf
fi
;;
replay|rep)
if ((${#REPLAY_FILES[@]})) || [[ -s $FILEOUT_TTS ]]
if ((${#REPLAY_FILES[@]})) || [[ -f $FILEOUT_TTS ]]
then for var in "${REPLAY_FILES[@]:-$FILEOUT_TTS}"
do [[ -f $var ]] || continue
du -h "$var" >&2 2>/dev/null;
Expand Down Expand Up @@ -2589,7 +2590,7 @@ function edf
[Rr]) return 200;; #redo
[Ee]|$'\e'|*) _edf "$FILETXT";; #edit
esac
done
done; printf '\n---\n\n' >&2;

ind=320 sub="${pos:${#pre}:${ind}}"
if ((OPTCMPL))
Expand Down Expand Up @@ -2709,15 +2710,15 @@ function fmt_ccf
case "$var" in \~\/*) var="$HOME/${var:2}";; esac;
if [[ $var != *[!$IFS]* ]]
then continue;
elif [[ -f $var ]] && is_audiof "$var"
elif [[ -s $var ]] && is_audiof "$var"
then ext=${var##*.};
((${#ext}<7)) || ext=;
case "$ext" in mp3|opus|aac|flac|wav|pcm16) :;;
*) _warmsgf 'Warning:' "Filetype may be unsupported -- ${ext:-extension_err}" ;;
esac
((${#1})) && printf ',';
printf '\n{ "type": "input_audio", "input_audio": { "data": "%s", "format": "%s" } }' "$(base64 "$var" | tr -d $'\n')" "${ext:-mp3}" ;
elif [[ -f $var ]]
elif [[ -s $var ]]
then ext=${var##*.} ext=${ext/[Jj][Pp][Gg]/jpeg};
((${#ext}<7)) || ext=;
case "$ext" in jpeg|png|gif|webp) :;; #20MB per image
Expand Down Expand Up @@ -2943,7 +2944,7 @@ function _mediachatf
MEDIA_IND=("$var" "${MEDIA_IND[@]}");
fi;

((${#1}-ind >= 0)) || { _warmsgf 'Err: _mediachatf():' "negative index -- $((${#1}-ind))"; break ;}
((${#1}-ind < 0)) && { _warmsgf 'Err: _mediachatf():' "negative index -- $((${#1}-ind))"; break ;}
set -- "$(trim_trailf "${1: 0: ${#1}-ind}" $'*(\\[tnr]|[ \t\n\r|])')";
else
((OPTV>99)) || [[ $var = *[[\]\<\>{}\(\)*?=%\&^\$\#\ ]* ]] ||
Expand Down Expand Up @@ -3030,7 +3031,7 @@ function is_txturl
((${#1}>320)) && set -- "${1: ${#1}-320}"

set -- "$1" "$(INDEX=64 trimf "$1" "$SPC")";
if [[ -s ${2:-$1} ]]
if [[ -f ${2:-$1} ]]
then set -- "${2:-$1}";
else set -- "$(trim_leadf "$(trim_trailf "$1" "$SPC")" $'*[!\\\\][ \t\n]')";
[[ ${1:0:1} = [$IFS] ]] && set -- "${1:1}";
Expand Down Expand Up @@ -3185,6 +3186,7 @@ function foldf
do
r=$REPLY;
r=${r//$'\t'/ }; #fix for tabs

((OPTK)) || { #delete ansi codes
text="$r" result=""
while [[ "$text" = *$'\e'*[mG]* ]]
Expand Down Expand Up @@ -4942,7 +4944,7 @@ function set_googleaif
do
if [[ $var != *[!$IFS]* ]]
then continue;
elif [[ -f $var ]]
elif [[ -s $var ]]
then ext=${var##*.}; ((${#ext}<7)) && ext=${ext/[Jj][Pp][Gg]/jpeg} || ext=;
((${#1})) && printf ',';
printf '
Expand Down Expand Up @@ -5886,11 +5888,12 @@ else
#check whether last arg is url or directory
var=$(INDEX=64 trimf "${REPLY: ind}" "$SPC")
if [[ -s $var ]]
if [[ -s ${var//\\} ]]
then :;
else var=$(trim_leadf "$(trim_trailf "${REPLY: ind}" "$SPC")" $'*[!\\\\][ \t\n]');
[[ ${var:0:1} = [$IFS] ]] && var=${var:1};
fi #C#
[[ $var = *\\* ]] && var=${var//\\};
case "$var" in \~\/*) var="$HOME/${var:2}";; esac;
if { _is_linkf "$var" && ! _is_imagef "$var" && ! _is_videof "$var" && [[ $var != *\/\/ ]] ;} ||
Expand Down Expand Up @@ -6445,7 +6448,7 @@ $( ((MISTRALAI+LOCALAI+ANTHROPICAI+GITHUBAI)) || ((!STREAM)) || echo "\"stream_o
fi >/dev/null 2>&1 || ! _warmsgf 'Err:' 'ffmpeg/sox/lame -- pcm16 to wav';
[[ -s $var ]] && FILEOUT_TTS=$var;
[[ ! -s $var ]] || du -h "$var" >&2 2>/dev/null || _sysmsgf 'TTS File:' "${var/"$HOME"/"~"}";
[[ ! -e $var ]] || du -h "$var" >&2 2>/dev/null || _sysmsgf 'TTS File:' "${var/"$HOME"/"~"}";
fi
#Audio formats
# raw 16 bit PCM audio at 24kHz, 1 channel, little-endian
Expand Down
11 changes: 8 additions & 3 deletions man/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
author:
- mountaineerbr
date: November 2024
title: CHATGPT.SH(1) v0.85 \| General Commands Manual
title: CHATGPT.SH(1) v0.85.4 \| General Commands Manual
---

### NAME
Expand Down Expand Up @@ -879,8 +879,13 @@ Bash “read command” may not correctly display input buffers larger than
the TTY screen size during editing. However, input buffers remain
unaffected. Use the text editor interface for big prompt editing.

File paths containing spaces may not work correctly with some script
features.
File paths containing spaces may not work correctly in the chat
interface. Make sure to backslash-escape filepaths with white spaces.

Folding the response at white spaces may not worked correctly if the
user has changed his terminal tabstop setting. Reset it with command
`tabs -8` or `reset` before starting the script, or set one of these in
the script configuration file.

Bash truncates input on “\000” (null).

Expand Down
13 changes: 10 additions & 3 deletions man/chatgpt.sh.1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'\" t
.\" Automatically generated by Pandoc 3.1.11.1
.\"
.TH "CHATGPT.SH" "1" "November 2024" "v0.85" "General Commands Manual"
.TH "CHATGPT.SH" "1" "November 2024" "v0.85.4" "General Commands Manual"
.SS NAME
.PP
\ \ \ chatgpt.sh \-\- Wrapper for ChatGPT / DALL\-E / Whisper / TTS
Expand Down Expand Up @@ -1426,8 +1426,15 @@ larger than the TTY screen size during editing.
However, input buffers remain unaffected.
Use the text editor interface for big prompt editing.
.PP
File paths containing spaces may not work correctly with some script
features.
File paths containing spaces may not work correctly in the chat
interface.
Make sure to backslash\-escape filepaths with white spaces.
.PP
Folding the response at white spaces may not worked correctly if the
user has changed his terminal tabstop setting.
Reset it with command \f[CR]tabs \-8\f[R] or \f[CR]reset\f[R] before
starting the script, or set one of these in the script configuration
file.
.PP
Bash truncates input on \[lq]\[rs]000\[rq] (null).
.PP
Expand Down
10 changes: 8 additions & 2 deletions man/chatgpt.sh.1.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% CHATGPT.SH(1) v0.85 | General Commands Manual
% CHATGPT.SH(1) v0.85.4 | General Commands Manual
% mountaineerbr
% November 2024

Expand Down Expand Up @@ -948,7 +948,13 @@ Bash "read command" may not correctly display input buffers larger than
the TTY screen size during editing. However, input buffers remain
unaffected. Use the text editor interface for big prompt editing.

File paths containing spaces may not work correctly with some script features.
File paths containing spaces may not work correctly in the chat interface.
Make sure to backslash-escape filepaths with white spaces.

Folding the response at white spaces may not worked correctly if the user
has changed his terminal tabstop setting. Reset it with command `tabs -8`
or `reset` before starting the script, or set one of these in the
script configuration file.

Bash truncates input on "\\000" (null).

Expand Down
13 changes: 9 additions & 4 deletions man/chatgpt.sh.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<meta name="author" content="mountaineerbr" />
<title>CHATGPT.SH(1) v0.85 | General Commands Manual</title>
<title>CHATGPT.SH(1) v0.85.4 | General Commands Manual</title>
<style>
html {
color: #1a1a1a;
Expand Down Expand Up @@ -171,7 +171,7 @@
</head>
<body>
<header id="title-block-header">
<h1 class="title">CHATGPT.SH(1) v0.85 | General Commands Manual</h1>
<h1 class="title">CHATGPT.SH(1) v0.85.4 | General Commands Manual</h1>
<p class="author">mountaineerbr</p>
<p class="date">November 2024</p>
</header>
Expand Down Expand Up @@ -1327,8 +1327,13 @@ <h3 id="bugs">BUGS</h3>
<p>Bash “read command” may not correctly display input buffers larger
than the TTY screen size during editing. However, input buffers remain
unaffected. Use the text editor interface for big prompt editing.</p>
<p>File paths containing spaces may not work correctly with some script
features.</p>
<p>File paths containing spaces may not work correctly in the chat
interface. Make sure to backslash-escape filepaths with white
spaces.</p>
<p>Folding the response at white spaces may not worked correctly if the
user has changed his terminal tabstop setting. Reset it with command
<code>tabs -8</code> or <code>reset</code> before starting the script,
or set one of these in the script configuration file.</p>
<p>Bash truncates input on “\000” (null).</p>
<p>The script logic resembles a bowl of spaghetti code after a cat
fight.</p>
Expand Down
11 changes: 8 additions & 3 deletions man/chatgpt.sh.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CHATGPT.SH(1) v0.85 | General Commands Manual
CHATGPT.SH(1) v0.85.4 | General Commands Manual
mountaineerbr
November 2024

Expand Down Expand Up @@ -829,8 +829,13 @@ Bash “read command” may not correctly display input buffers larger than
the TTY screen size during editing. However, input buffers remain
unaffected. Use the text editor interface for big prompt editing.

File paths containing spaces may not work correctly with some script
features.
File paths containing spaces may not work correctly in the chat
interface. Make sure to backslash-escape filepaths with white spaces.

Folding the response at white spaces may not worked correctly if the
user has changed his terminal tabstop setting. Reset it with command
tabs -8 or reset before starting the script, or set one of these in the
script configuration file.

Bash truncates input on “\000” (null).

Expand Down

0 comments on commit 0cb7376

Please sign in to comment.