Skip to content

Commit

Permalink
rename attempt lock
Browse files Browse the repository at this point in the history
  • Loading branch information
David Motsonashvili committed Dec 18, 2023
1 parent 602cfb9 commit 18724d3
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Chat(private val model: GenerativeModel, val history: MutableList<Content>
*/
suspend fun sendMessage(prompt: Content): GenerateContentResponse {
prompt.assertComesFromUser()
assertNoOngoingCall()
attemptLock()

val response = model.generateContent(*history.toTypedArray(), prompt)

Expand Down Expand Up @@ -91,7 +91,7 @@ class Chat(private val model: GenerativeModel, val history: MutableList<Content>
*/
fun sendMessageStream(prompt: Content): Flow<GenerateContentResponse> {
prompt.assertComesFromUser()
assertNoOngoingCall()
attemptLock()

val flow = model.generateContentStream(*history.toTypedArray(), prompt)
val bitmaps = LinkedList<Bitmap>()
Expand Down Expand Up @@ -163,7 +163,7 @@ class Chat(private val model: GenerativeModel, val history: MutableList<Content>
}
}

private fun assertNoOngoingCall() {
private fun attemptLock() {
if (!lock.tryAcquire()) {
throw IllegalStateException(
"This chat instance currently has an ongoing request, please wait for it to complete " +
Expand Down

0 comments on commit 18724d3

Please sign in to comment.