summaryrefslogtreecommitdiffstats
path: root/Argcfile.sh
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-04-30 05:15:13 +0000
committersigoden <sigoden@gmail.com>2024-04-30 05:16:45 +0000
commit83ca74bf8a7be2df39663670735ee45726dda661 (patch)
tree6e325da275b419faa88d324b155ff8bdacd4945a /Argcfile.sh
parent8dba46becfbcc4669867db4487aa9b91c51e4afa (diff)
downloadaichat-83ca74bf8a7be2df39663670735ee45726dda661.tar.gz
chore: minor refinement
Diffstat (limited to 'Argcfile.sh')
-rwxr-xr-xArgcfile.sh37
1 files changed, 24 insertions, 13 deletions
diff --git a/Argcfile.sh b/Argcfile.sh
index 112b8bf..68f222c 100755
--- a/Argcfile.sh
+++ b/Argcfile.sh
@@ -17,7 +17,7 @@ test-init-config() {
cargo run -- "$@"
}
-# @cmd Test running with AICHAT_PLATFORM environment varialbe
+# @cmd Test running with AICHAT_PLATFORM environment variable
# @env AICHAT_PLATFORM!
# @arg args~
test-platform-env() {
@@ -50,7 +50,7 @@ test-server() {
"$@"
}
-OPEIA_COMPATIBLE_CLIENTS=( \
+OPENAI_COMPATIBLE_PLATFORMS=( \
openai,gpt-3.5-turbo,https://api.openai.com/v1 \
anyscale,meta-llama/Meta-Llama-3-8B-Instruct,https://api.endpoints.anyscale.com/v1 \
deepinfra,meta-llama/Meta-Llama-3-8B-Instruct,https://api.deepinfra.com/v1/openai \
@@ -64,14 +64,20 @@ OPEIA_COMPATIBLE_CLIENTS=( \
together,meta-llama/Llama-3-8b-chat-hf,https://api.together.xyz/v1 \
)
-# @cmd Chat with openai-comptabile api
+# @cmd Chat with any LLM api
# @flag -S --no-stream
-# @arg platform![`_choice_platform`]
+# @arg platform_model![?`_choice_platform_model`]
# @arg text~
chat() {
- for client_config in "${OPEIA_COMPATIBLE_CLIENTS[@]}"; do
- if [[ "$argc_platform" == "${client_config%%,*}" ]]; then
- api_base="${client_config##*,}"
+ if [[ "$argc_platform_model" == *':'* ]]; then
+ model="${argc_platform_model##*:}"
+ argc_platform="${argc_platform_model%:*}"
+ else
+ argc_platform="${argc_platform_model}"
+ fi
+ for platform_config in "${OPENAI_COMPATIBLE_PLATFORMS[@]}"; do
+ if [[ "$argc_platform" == "${platform_config%%,*}" ]]; then
+ api_base="${platform_config##*,}"
break
fi
done
@@ -80,7 +86,7 @@ chat() {
api_key_env="${env_prefix}_API_KEY"
api_key="${!api_key_env}"
if [[ -z "$model" ]]; then
- model="$(echo "$client_config" | cut -d, -f2)"
+ model="$(echo "$platform_config" | cut -d, -f2)"
fi
if [[ -z "$model" ]]; then
model_env="${env_prefix}_MODEL"
@@ -99,9 +105,9 @@ chat() {
# @cmd List models by openai-comptabile api
# @arg platform![`_choice_platform`]
models() {
- for client_config in "${OPEIA_COMPATIBLE_CLIENTS[@]}"; do
- if [[ "$argc_platform" == "${client_config%%,*}" ]]; then
- api_base="${client_config##*,}"
+ for platform_config in "${OPENAI_COMPATIBLE_PLATFORMS[@]}"; do
+ if [[ "$argc_platform" == "${platform_config%%,*}" ]]; then
+ api_base="${platform_config##*,}"
break
fi
done
@@ -432,6 +438,11 @@ _choice_model() {
aichat --list-models
}
+_choice_platform_model() {
+ _choice_platform
+ _choice_model
+}
+
_choice_platform() {
_choice_client
_choice_openai_compatible_platform
@@ -442,8 +453,8 @@ _choice_client() {
}
_choice_openai_compatible_platform() {
- for v in "${OPEIA_COMPATIBLE_CLIENTS[@]}"; do
- echo "${v%%,*}"
+ for platform_config in "${OPENAI_COMPATIBLE_PLATFORMS[@]}"; do
+ echo "${platform_config%%,*}"
done
}