fix: remove hardcoded /v1 from API base URL

Users now provide the full versioned path in --api-base (e.g. /v1, /v4).
Code only appends /chat/completions. Default changed to
http://127.0.0.1:8080/v1 for backward compatibility.
This commit is contained in:
BeaconCat 2026-04-13 11:11:08 +08:00
parent 8eca3139db
commit 0408bf84b9
2 changed files with 3 additions and 6 deletions

View file

@ -91,10 +91,7 @@ func (c *LLMClient) Complete(ctx context.Context, systemPrompt, userPrompt strin
return "", fmt.Errorf("marshal request: %w", err)
}
endpoint := c.BaseURL + "/v1/chat/completions"
if strings.HasSuffix(c.BaseURL, "/v1") || strings.HasSuffix(c.BaseURL, "/v1/") {
endpoint = strings.TrimRight(c.BaseURL, "/") + "/chat/completions"
}
endpoint := strings.TrimRight(c.BaseURL, "/") + "/chat/completions"
req, err := http.NewRequestWithContext(ctx, "POST", endpoint, bytes.NewReader(jsonBody))
if err != nil {
return "", fmt.Errorf("create request: %w", err)

View file

@ -289,13 +289,13 @@ func envOrFlag(flag, envKey string) string {
//
// Environment variables:
//
// MEMBENCH_API_BASE OpenAI-compatible base URL (default http://127.0.0.1:8080)
// MEMBENCH_API_BASE OpenAI-compatible base URL (default http://127.0.0.1:8080/v1)
// MEMBENCH_API_KEY Bearer token for the endpoint
// MEMBENCH_MODEL Model name to send in the request
func buildLLMOptions() (LLMClientOptions, error) {
base := envOrFlag(flagAPIBase, "MEMBENCH_API_BASE")
if base == "" {
base = "http://127.0.0.1:8080"
base = "http://127.0.0.1:8080/v1"
}
model := envOrFlag(flagModel, "MEMBENCH_MODEL")
if model == "" {