From 70caf9bf8ca1bf7a9c1e487611fe290f6e706352 Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Tue, 2 May 2023 23:30:00 +0200 Subject: [PATCH] feat: support stopwords both string and arrays (#154) --- api/openai.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/api/openai.go b/api/openai.go index 9547cf6..bbb26ea 100644 --- a/api/openai.go +++ b/api/openai.go @@ -63,7 +63,7 @@ type OpenAIRequest struct { Instruction string `json:"instruction" yaml:"instruction"` Input string `json:"input" yaml:"input"` - Stop []string `json:"stop" yaml:"stop"` + Stop interface{} `json:"stop" yaml:"stop"` // Messages is read only by chat/completion API calls Messages []Message `json:"messages" yaml:"messages"` @@ -117,8 +117,12 @@ func updateConfig(config *Config, input *OpenAIRequest) { config.Maxtokens = input.Maxtokens } - if len(input.Stop) != 0 { - config.StopWords = append(config.StopWords, input.Stop...) + switch stop := input.Stop.(type) { + case string: + config.StopWords = append(config.StopWords, stop) + case []string: + config.StopWords = append(config.StopWords, stop...) + } if input.RepeatPenalty != 0 {