-
Notifications
You must be signed in to change notification settings - Fork 0
/
chewie-chat
executable file
·60 lines (55 loc) · 1.98 KB
/
chewie-chat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
#
# chewie-chat
#
# wrapper that uses chewie to implement a general-purpose chat bot.
#
echo "Setting up chewie-chat... "
if [ x"$CHEWIECHAT_API" == "x" ] ; then
CHEWIECHAT_API="openai"
fi
if [ x"$CHEWIECHAT_MODEL" == "x" ] ; then
CHEWIECHAT_MODEL="gpt-4o"
fi
if [ x"$CHEWIECHAT_API" == "xopenai" ] ; then
CHEWIECHAT_HOST="https://api.openai.com"
fi
echo "Using API \"$CHEWIECHAT_API\""
echo "Using model \"$CHEWIECHAT_MODEL\""
CHEWIECHAT_CONTEXT_FILENAME=chewie-chat-context.json
CHEWIECHAT_CONTEXT_PATH=~/.cache/chewie
export CHEWIECHAT_CONTEXT_FILE=$CHEWIECHAT_CONTEXT_PATH/$CHEWIECHAT_CONTEXT_FILENAME
echo "Using context file \"$CHEWIECHAT_CONTEXT_FILE\""
mkdir -p $CHEWIECHAT_CONTEXT_PATH
if [ ! -f $CHEWIECHAT_CONTEXT_FILE ] ; then
echo "Creating context file..."
chewie r u ctx="$CHEWIECHAT_CONTEXT_FILE" > /dev/null
chewie u aip="$CHEWIECHAT_API" mdl="$CHEWIECHAT_MODEL" ctx="$CHEWIECHAT_CONTEXT_FILE" sys="You are a helpful assistant." > /dev/null
echo "context file created"
fi
echo "Enter /h for command help."
echo "Press Ctrl-C or enter /q to exit."
while [ 1 ] ; do
read -p "$USER > " input
if [ x"$input" == "x/h" ] ; then
echo "commands:"
echo "/h - help (this) text"
echo "/l - show context history"
echo "/q - quit"
echo "/r - reset context file"
continue
elif [ x"$input" == "x/l" ] ; then
chewie ctx="$CHEWIECHAT_CONTEXT_FILE" his
continue
elif [ x"$input" == "x/q" ] ; then
exit 0
elif [ x"$input" == "x/r" ] ; then
echo "Resetting context..."
chewie r u ctx="$CHEWIECHAT_CONTEXT_FILE" > /dev/null
chewie u aip="$CHEWIECHAT_API" mdl="$CHEWIECHAT_MODEL" ctx="$CHEWIECHAT_CONTEXT_FILE" sys="You are a helpful assistant." > /dev/null
echo "context file reset"
continue
fi
echo -n "chewie > "
echo "$input" | chewie aip="$CHEWIECHAT_API" mdl="$CHEWIECHAT_MODEL" aih="$CHEWIECHAT_HOST" ctx="$CHEWIECHAT_CONTEXT_FILE"
done