diff --git a/README.md b/README.md index 41302da..db1222a 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ upstream_url: "https://api.z.ai/api/anthropic" - `port`: Port to listen on (default: 8080) - `upstream_url`: Base URL for the Anthropic-compatible upstream API +- `temperature` (optional): Override temperature for all requests. If set, this value is used instead of client-specified temperatures. Remove this line to respect client temperatures. ## Building diff --git a/config.yaml b/config.yaml index 28beb39..da433a6 100644 --- a/config.yaml +++ b/config.yaml @@ -1,6 +1,11 @@ port: 8080 upstream_url: "https://api.z.ai/api/anthropic" +# Temperature override for all requests (optional) +# If set, this temperature will be used instead of what clients request +# Remove this line or set to null to use client-specified temperatures +# temperature: 0.7 + models: - id: "glm-4.7" owned_by: "zhipu" diff --git a/converter.go b/converter.go index d7b9bcf..2f52fe9 100644 --- a/converter.go +++ b/converter.go @@ -7,7 +7,8 @@ import ( ) // ConvertOpenAIRequest converts an OpenAI ChatCompletionRequest to Anthropic format -func ConvertOpenAIRequest(req *ChatCompletionRequest) *AnthropicRequest { +// tempOverride, if provided, overrides any temperature from the request +func ConvertOpenAIRequest(req *ChatCompletionRequest, tempOverride *float64) *AnthropicRequest { system, remainingMessages := extractSystemMessage(req.Messages) anthropicReq := &AnthropicRequest{ @@ -27,7 +28,10 @@ func ConvertOpenAIRequest(req *ChatCompletionRequest) *AnthropicRequest { if req.Stream != nil { anthropicReq.Stream = *req.Stream } - if req.Temperature != nil { + // Use temperature override if configured, otherwise use request temperature + if tempOverride != nil { + anthropicReq.Temperature = tempOverride + } else if req.Temperature != nil { anthropicReq.Temperature = req.Temperature } if req.TopP != nil { diff --git a/handler.go b/handler.go index 4324de8..b5768ce 100644 --- a/handler.go +++ b/handler.go @@ -12,15 +12,16 @@ import ( ) type ModelConfig struct { - ID string `yaml:"id"` - OwnedBy string `yaml:"owned_by"` + ID string `yaml:"id"` + OwnedBy string `yaml:"owned_by"` } // Config holds the application configuration type Config struct { - Port int `yaml:"port"` - UpstreamURL string `yaml:"upstream_url"` - Models []ModelConfig `yaml:"models"` + Port int `yaml:"port"` + UpstreamURL string `yaml:"upstream_url"` + Models []ModelConfig `yaml:"models"` + Temperature *float64 `yaml:"temperature,omitempty"` } var config *Config @@ -124,7 +125,7 @@ func handleChatCompletions(w http.ResponseWriter, r *http.Request) { // Convert to Anthropic format — always non-streaming to upstream // (ZAI's streaming returns empty for GLM models) - anthropicReq := ConvertOpenAIRequest(&req) + anthropicReq := ConvertOpenAIRequest(&req, config.Temperature) anthropicReq.Stream = false reqBody, _ := json.Marshal(anthropicReq) diff --git a/proxx b/proxx index 93268a2..2cd5c56 100755 Binary files a/proxx and b/proxx differ