Created
December 17, 2022 15:22
-
-
Save elsayed85/61197752b665fa87792774254cd7494d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env bash | |
# | |
TEMPERATURE=${TEMPERATURE:-0} | |
MAX_TOKENS=${MAX_TOKENS:-1000} | |
MODEL=${MODEL:-"text-davinci-003"} | |
message="$*" | |
token="" | |
clear_command="wipe" | |
clear_all_command="clear" | |
default_msg="You are now chatting with a assistant named AI, seprate any list with \n." | |
clear | |
if [ "$clear_command" == "$message" ]; then | |
> /home/sayed/Desktop/chat.log | |
echo "$default_msg" > /home/sayed/Desktop/chat.log | |
exit | |
fi | |
if [ "$clear_all_command" == "$message" ]; then | |
> /home/sayed/Desktop/chat.log | |
exit | |
fi | |
chatlog="You:$message" | |
chatlog="$(cat /home/sayed/Desktop/chat.log) $chatlog." | |
prompt="$chatlog AI:" | |
output=$(jq -n \ | |
--arg model "$MODEL" \ | |
--argjson temp $TEMPERATURE \ | |
--argjson tokens $MAX_TOKENS \ | |
--arg prompt "$( | |
echo "$prompt"; | |
)" '{model: $model, temperature: $temp, max_tokens: $tokens, prompt: $prompt}' \ | |
| http https://api.openai.com/v1/completions Authorization:"Bearer $token" \ | |
| jq -r '.choices[0].text' | sed '/./,$!d') | |
chatlog="$chatlog Ai:$output." | |
> /home/sayed/Desktop/chat.log | |
echo "$chatlog" > /home/sayed/Desktop/chat.log | |
echo "----------------- You ----------------" | |
printf "$message\n\n" | |
echo "----------------- AI -----------------" | |
echo "$output" | |
echo "--------------------------------------" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment