🔧 fix: OpenAIClient Response Handling for Legacy /v1/completions (#4128)

This commit is contained in:
Danny Avila 2024-09-19 13:20:29 -04:00 committed by GitHub
parent 8dc5b320bc
commit 5f28682314
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -644,6 +644,12 @@ class OpenAIClient extends BaseClient {
if (completionResult && typeof completionResult === 'string') {
reply = completionResult;
} else if (
completionResult &&
typeof completionResult === 'object' &&
Array.isArray(completionResult.choices)
) {
reply = completionResult.choices[0]?.text?.replace(this.endToken, '');
}
} else if (typeof opts.onProgress === 'function' || this.options.useChatCompletion) {
reply = await this.chatCompletion({