Refactor API URL building in OpenAI and Claude components
- Update `buildAPIURL` function in OpenAI provider to delegate URL construction to `connector.BuildAPIURL`, ensuring consistent URL formatting across the agent LLM and sandbox proxy paths. - Modify backend URL construction in Claude's `BuildProxyConfig` to utilize the shared `connector.BuildAPIURL` helper, applying the necessary `/v1` prefix for compatibility. This change enhances code maintainability and consistency in API URL handling across different components.
This commit is contained in:
parent
fea1ac0708
commit
31a75f0161
2 changed files with 8 additions and 15 deletions
|
|
@ -129,17 +129,11 @@ type Provider struct {
|
|||
adapters []adapters.CapabilityAdapter
|
||||
}
|
||||
|
||||
// buildAPIURL builds the complete API URL from host and endpoint
|
||||
// If host ends with /, it's used as-is (user has specified full path)
|
||||
// Otherwise, /v1 prefix is added automatically (standard for OpenAI-compatible APIs)
|
||||
// buildAPIURL builds the complete API URL from host and endpoint.
|
||||
// Delegates to the shared connector.BuildAPIURL for consistent URL building
|
||||
// across the agent LLM path and the sandbox proxy path.
|
||||
func buildAPIURL(host, endpoint string) string {
|
||||
// If host ends with /, use it as-is (user has specified full path like /v1/ or /api/)
|
||||
// Otherwise, add /v1 prefix (standard for OpenAI-compatible APIs)
|
||||
if !strings.HasSuffix(host, "/") {
|
||||
endpoint = "/v1" + endpoint
|
||||
}
|
||||
host = strings.TrimSuffix(host, "/")
|
||||
return host + endpoint
|
||||
return connector.BuildAPIURL(host, endpoint)
|
||||
}
|
||||
|
||||
// New create a new OpenAI provider with capability adapters
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/yaoapp/gou/connector"
|
||||
agentContext "github.com/yaoapp/yao/agent/context"
|
||||
)
|
||||
|
||||
|
|
@ -355,11 +356,9 @@ func BuildProxyConfig(opts *Options) ([]byte, error) {
|
|||
return nil, fmt.Errorf("options is required")
|
||||
}
|
||||
|
||||
// Build backend URL - ensure it ends with /chat/completions
|
||||
backendURL := opts.ConnectorHost
|
||||
if !strings.HasSuffix(backendURL, "/chat/completions") {
|
||||
backendURL = strings.TrimSuffix(backendURL, "/") + "/chat/completions"
|
||||
}
|
||||
// Build backend URL using the shared connector.BuildAPIURL helper
|
||||
// so that the /v1 prefix is applied consistently with the agent LLM path.
|
||||
backendURL := connector.BuildAPIURL(opts.ConnectorHost, "/chat/completions")
|
||||
|
||||
config := map[string]interface{}{
|
||||
"backend": backendURL,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue