From 801b481beb5b235eaf9f390155422b9db733fd40 Mon Sep 17 00:00:00 2001 From: Chakib Benziane Date: Sun, 17 Mar 2024 09:43:20 +0100 Subject: [PATCH] fixes #1051: handle openai presence and request penalty parameters (#1817) * fix request debugging, disable marshalling of context fields Signed-off-by: blob42 * merge frequency_penalty request parm with config Signed-off-by: blob42 * openai: add presence_penalty parameter Signed-off-by: blob42 --------- Signed-off-by: blob42 --- core/http/endpoints/openai/request.go | 8 ++++++++ core/schema/openai.go | 2 +- core/schema/prediction.go | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/core/http/endpoints/openai/request.go b/core/http/endpoints/openai/request.go index 505244c4..1f845c6f 100644 --- a/core/http/endpoints/openai/request.go +++ b/core/http/endpoints/openai/request.go @@ -185,6 +185,14 @@ func updateRequestConfig(config *config.BackendConfig, input *schema.OpenAIReque config.RepeatPenalty = input.RepeatPenalty } + if input.FrequencyPenalty!= 0 { + config.FrequencyPenalty = input.FrequencyPenalty + } + + if input.PresencePenalty!= 0 { + config.PresencePenalty = input.PresencePenalty + } + if input.Keep != 0 { config.Keep = input.Keep } diff --git a/core/schema/openai.go b/core/schema/openai.go index 1c13847c..6aa0f1b0 100644 --- a/core/schema/openai.go +++ b/core/schema/openai.go @@ -108,7 +108,7 @@ type ChatCompletionResponseFormat struct { type OpenAIRequest struct { PredictionOptions - Context context.Context `json:"-"` + Context context.Context `json:"-"` Cancel context.CancelFunc `json:"-"` // whisper diff --git a/core/schema/prediction.go b/core/schema/prediction.go index d75e5eb8..4933f2d2 100644 --- a/core/schema/prediction.go +++ b/core/schema/prediction.go @@ -25,6 +25,7 @@ type PredictionOptions struct { Keep int `json:"n_keep" yaml:"n_keep"` FrequencyPenalty float64 `json:"frequency_penalty" yaml:"frequency_penalty"` + PresencePenalty float64 `json:"presence_penalty" yaml:"presence_penalty"` TFZ float64 `json:"tfz" yaml:"tfz"` TypicalP float64 `json:"typical_p" yaml:"typical_p"`