diff --git a/api.go b/api.go index 45e1980..7265ac8 100644 --- a/api.go +++ b/api.go @@ -36,6 +36,7 @@ func (this *Application) POST_Chat(w http.ResponseWriter, r *http.Request) { ConversationID string APIKey string Content string + MaxTokens int } var apiParams requestBody err := json.NewDecoder(r.Body).Decode(&apiParams) @@ -44,6 +45,11 @@ func (this *Application) POST_Chat(w http.ResponseWriter, r *http.Request) { return } + if apiParams.MaxTokens < 0 { + http.Error(w, "MaxTokens should be 0 or positive", 400) + return + } + // Verify API key // TODO @@ -94,7 +100,12 @@ func (this *Application) POST_Chat(w http.ResponseWriter, r *http.Request) { // We've consumed all the input. - for i := int(llast_n_tokens_used_size); i < ParamContextSize; i += 1 { + EndPos := ParamContextSize + if apiParams.MaxTokens != 0 && (int(llast_n_tokens_used_size)+apiParams.MaxTokens) < ParamContextSize { + EndPos = int(llast_n_tokens_used_size) + apiParams.MaxTokens + } + + for i := int(llast_n_tokens_used_size); i < EndPos; i += 1 { if err := r.Context().Err(); err != nil { return }