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 <noreply@anthropic.com>
This commit is contained in:
Frad LEE 2026-02-05 11:25:31 +08:00
commit f43786cafd
4 changed files with 11 additions and 9 deletions

View file

@ -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)
```

View file

@ -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} )) &&

View file

@ -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

View file

@ -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