Skip to content

Commit

Permalink
Adjust success response to handle nulls in response
Browse files Browse the repository at this point in the history
  • Loading branch information
zwarm committed Jun 18, 2024
1 parent acfa196 commit 464544d
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ class VoiceToContentUseCase @Inject constructor(

when(response) {
is JetpackAIQueryResponse.Success -> {
val finalContent: String = response.choices[0].message.content
val finalContent: String? = response.choices[0].message?.content
// __JETPACK_AI_ERROR__ is a special marker we ask GPT to add to the request when it can’t
// understand the request for any reason, so maybe something confused GPT on some requests.
if (finalContent == JETPACK_AI_ERROR) {
if (finalContent == null || finalContent == JETPACK_AI_ERROR) {
// Send back the transcribed text here
logger.logError(JETPACK_AI_ERROR)
return@withContext Success(content = transcribed)
} else {
return@withContext Success(content = response.choices[0].message.content)
return@withContext Success(content = finalContent)
}
}

Expand Down

0 comments on commit 464544d

Please sign in to comment.