api: support a MaxTokens parameter
This commit is contained in:
parent
6c6a5c602e
commit
0c96f2bf6b
13
api.go
13
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user