summaryrefslogtreecommitdiffstats
path: root/Argcfile.sh
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-04-30 07:07:09 +0800
committerGitHub <noreply@github.com>2024-04-30 07:07:09 +0800
commit50eac8b59409f73655fc2b8cf8d783c6347209c3 (patch)
treea38a4b2bd8b60f743024f3bd5139dae3bb1d5fb2 /Argcfile.sh
parent4d4a100fe6fcde7ca3afcf7971ac387d355349eb (diff)
downloadaichat-50eac8b59409f73655fc2b8cf8d783c6347209c3.tar.gz
feat: support replicate client (#466)
Diffstat (limited to 'Argcfile.sh')
-rwxr-xr-xArgcfile.sh41
1 files changed, 41 insertions, 0 deletions
diff --git a/Argcfile.sh b/Argcfile.sh
index 7ba83d3..46ab0ec 100755
--- a/Argcfile.sh
+++ b/Argcfile.sh
@@ -325,6 +325,47 @@ chat-cloudflare() {
}'
}
+# @cmd Chat with replicate api
+# @env REPLICATE_API_KEY!
+# @option -m --model=meta/meta-llama-3-8b-instruct $REPLICATE_MODEL
+# @flag -S --no-stream
+# @arg text~
+chat-replicate() {
+ url="https://api.replicate.com/v1/models/$argc_model/predictions"
+ res="$(_wrapper curl -s $DEEPINFRA_CURL_ARGS "$url" \
+-X POST \
+-H "Authorization: Bearer $REPLICATE_API_KEY" \
+-H "Content-Type: application/json" \
+-d '{
+ "stream": '$stream',
+ "input": {
+ "prompt": "'"$*"'"
+ }
+}')"
+ echo "$res"
+ if [[ -n "$argc_no_stream" ]]; then
+ prediction_url="$(echo "$res" | jq -r '.urls.get')"
+ while true; do
+ output="$(_wrapper curl $DEEPINFRA_CURL_ARGS -s -H "Authorization: Bearer $REPLICATE_API_KEY" "$prediction_url")"
+ prediction_status=$(printf "%s" "$output" | jq -r .status)
+ if [ "$prediction_status"=="succeeded" ]; then
+ echo "$output"
+ break
+ fi
+ if [ "$prediction_status"=="failed" ]; then
+ exit 1
+ fi
+ sleep 2
+ done
+ else
+ stream_url="$(echo "$res" | jq -r '.urls.stream')"
+ _wrapper curl -i $DEEPINFRA_CURL_ARGS --no-buffer "$stream_url" \
+-H "Accept: text/event-stream" \
+
+ fi
+
+}
+
# @cmd Chat with ernie api
# @meta require-tools jq
# @env ERNIE_API_KEY!