-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkiba.sh
More file actions
executable file
·31 lines (25 loc) · 861 Bytes
/
kiba.sh
File metadata and controls
executable file
·31 lines (25 loc) · 861 Bytes
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
#!/bin/bash
redraw_current_line() {
local current_line="$READLINE_LINE"
local current_point="$READLINE_POINT"
READLINE_LINE=$COMMAND
READLINE_POINT=${#READLINE_LINE}
}
# Add current command to history so it can be retrieved/edited
history -s "$READLINE_LINE"
# Set defaults from environment or fallback
provider="${KIBASH_PROVIDER}"
model="${KIBASH_MODEL}"
system="${KIBASH_SYSTEM}"
json_schema="{'type':'object','properties':{'command':{'type':'string'}},'required':['command']}"
JSON=$(cai --raw --system "$system" --json-schema "$json_schema" "$provider" "$model" "$READLINE_LINE")
COMMAND=$(echo "$JSON" | jq -r '.command')
if [[ -z "$COMMAND" || "$COMMAND" == "null" ]]; then
if [[ -z "$JSON" ]]; then
echo "ERROR: received no response from API"
else
echo "ERROR: $JSON"
fi
else
redraw_current_line
fi