From f43786cafd2e40f465107b817f0440bde95b1a56 Mon Sep 17 00:00:00 2001 From: Frad LEE Date: Thu, 5 Feb 2026 11:25:31 +0800 Subject: [PATCH] refactor(ai): use base url for endpoint config Change endpoint configuration to use base URL pattern, automatically appending /chat/completions path. - Update default endpoint to base URL format - Add automatic path construction in strategy - Update README examples to use base URLs - Update endpoint description to "base URL" Follows OpenAI SDK standard pattern where users configure base URL and library appends specific paths. Co-Authored-By: Claude Sonnet 4.5 --- README.md | 6 +++--- src/config.zsh | 4 ++-- src/strategies/ai.zsh | 3 ++- zsh-autosuggestions.zsh | 7 ++++--- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 3e4583d..dfa1290 100644 --- a/README.md +++ b/README.md @@ -127,7 +127,7 @@ export ZSH_AUTOSUGGEST_STRATEGY=(ai history) | Variable | Default | Description | |----------|---------|-------------| | `ZSH_AUTOSUGGEST_AI_API_KEY` | (unset) | **Required.** API key for the LLM service. Strategy is disabled if unset. | -| `ZSH_AUTOSUGGEST_AI_ENDPOINT` | `https://api.openai.com/v1/chat/completions` | API endpoint URL | +| `ZSH_AUTOSUGGEST_AI_ENDPOINT` | `https://api.openai.com/v1` | API base URL | | `ZSH_AUTOSUGGEST_AI_MODEL` | `gpt-3.5-turbo` | Model name to use | | `ZSH_AUTOSUGGEST_AI_TIMEOUT` | `5` | Request timeout in seconds | | `ZSH_AUTOSUGGEST_AI_MIN_INPUT` | `0` | Minimum input length before querying | @@ -162,7 +162,7 @@ export ZSH_AUTOSUGGEST_STRATEGY=(ai history) **Ollama (local LLM):** ```sh export ZSH_AUTOSUGGEST_AI_API_KEY="not-needed" # Required but unused by Ollama -export ZSH_AUTOSUGGEST_AI_ENDPOINT="http://localhost:11434/v1/chat/completions" +export ZSH_AUTOSUGGEST_AI_ENDPOINT="http://localhost:11434/v1" export ZSH_AUTOSUGGEST_AI_MODEL="codellama" export ZSH_AUTOSUGGEST_STRATEGY=(ai history) ``` @@ -170,7 +170,7 @@ export ZSH_AUTOSUGGEST_STRATEGY=(ai history) **Custom OpenAI-compatible endpoint:** ```sh export ZSH_AUTOSUGGEST_AI_API_KEY="your-key" -export ZSH_AUTOSUGGEST_AI_ENDPOINT="https://your-endpoint.com/v1/chat/completions" +export ZSH_AUTOSUGGEST_AI_ENDPOINT="https://your-endpoint.com/v1" export ZSH_AUTOSUGGEST_AI_MODEL="your-model" export ZSH_AUTOSUGGEST_STRATEGY=(ai history) ``` diff --git a/src/config.zsh b/src/config.zsh index 102e40b..0fb9d37 100644 --- a/src/config.zsh +++ b/src/config.zsh @@ -95,9 +95,9 @@ typeset -g ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX=autosuggest-orig- typeset -g ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME=zsh_autosuggest_completion_pty # AI strategy configuration -# API endpoint for AI suggestions (OpenAI-compatible) +# API base URL for AI suggestions (OpenAI-compatible) (( ! ${+ZSH_AUTOSUGGEST_AI_ENDPOINT} )) && -typeset -g ZSH_AUTOSUGGEST_AI_ENDPOINT='https://api.openai.com/v1/chat/completions' +typeset -g ZSH_AUTOSUGGEST_AI_ENDPOINT='https://api.openai.com/v1' # AI model to use for suggestions (( ! ${+ZSH_AUTOSUGGEST_AI_MODEL} )) && diff --git a/src/strategies/ai.zsh b/src/strategies/ai.zsh index 8e28c8b..afcdfbe 100644 --- a/src/strategies/ai.zsh +++ b/src/strategies/ai.zsh @@ -217,7 +217,8 @@ _zsh_autosuggest_strategy_ai() { "$temperature") # Make API request - local endpoint="${ZSH_AUTOSUGGEST_AI_ENDPOINT:-https://api.openai.com/v1/chat/completions}" + local base_url="${ZSH_AUTOSUGGEST_AI_ENDPOINT:-https://api.openai.com/v1}" + local endpoint="${base_url}/chat/completions" local timeout="${ZSH_AUTOSUGGEST_AI_TIMEOUT:-5}" local response diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index 183b6df..56b0cc5 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -121,9 +121,9 @@ typeset -g ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX=autosuggest-orig- typeset -g ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME=zsh_autosuggest_completion_pty # AI strategy configuration -# API endpoint for AI suggestions (OpenAI-compatible) +# API base URL for AI suggestions (OpenAI-compatible) (( ! ${+ZSH_AUTOSUGGEST_AI_ENDPOINT} )) && -typeset -g ZSH_AUTOSUGGEST_AI_ENDPOINT='https://api.openai.com/v1/chat/completions' +typeset -g ZSH_AUTOSUGGEST_AI_ENDPOINT='https://api.openai.com/v1' # AI model to use for suggestions (( ! ${+ZSH_AUTOSUGGEST_AI_MODEL} )) && @@ -743,7 +743,8 @@ _zsh_autosuggest_strategy_ai() { "$temperature") # Make API request - local endpoint="${ZSH_AUTOSUGGEST_AI_ENDPOINT:-https://api.openai.com/v1/chat/completions}" + local base_url="${ZSH_AUTOSUGGEST_AI_ENDPOINT:-https://api.openai.com/v1}" + local endpoint="${base_url}/chat/completions" local timeout="${ZSH_AUTOSUGGEST_AI_TIMEOUT:-5}" local response