davidberenstein1957 HF staff commited on
Commit
088561c
1 Parent(s): b2f617d

Add code separation getting generators

Browse files
Files changed (1) hide show
  1. chat_interface_preference.py +6 -6
chat_interface_preference.py CHANGED
@@ -641,16 +641,12 @@ class ChatInterface(Blocks):
641
 
642
  inputs, _, _ = special_args(self.fn, inputs=[message, history, *args], request=request)
643
 
644
- async def _get_response():
645
  if self.is_async:
646
  generator = self.fn(*inputs)
647
  else:
648
  generator = await anyio.to_thread.run_sync(self.fn, *inputs, limiter=self.limiter)
649
  generator = SyncToAsyncIterator(generator, self.limiter)
650
- return generator
651
-
652
- generator = await _get_response()
653
- try:
654
  first_response = await async_iteration(generator)
655
  if n_generations == 2:
656
  first_response_formatted = self._get_chat_message_comparison(first_response, "")
@@ -681,7 +677,11 @@ class ChatInterface(Blocks):
681
  yield update, update
682
 
683
  if n_generations == 2:
684
- generator_two = await _get_response()
 
 
 
 
685
  try:
686
  first_response_two = await async_iteration(generator_two)
687
  first_response_two = self._get_chat_message_comparison(response, first_response_two)
 
641
 
642
  inputs, _, _ = special_args(self.fn, inputs=[message, history, *args], request=request)
643
 
644
+ try:
645
  if self.is_async:
646
  generator = self.fn(*inputs)
647
  else:
648
  generator = await anyio.to_thread.run_sync(self.fn, *inputs, limiter=self.limiter)
649
  generator = SyncToAsyncIterator(generator, self.limiter)
 
 
 
 
650
  first_response = await async_iteration(generator)
651
  if n_generations == 2:
652
  first_response_formatted = self._get_chat_message_comparison(first_response, "")
 
677
  yield update, update
678
 
679
  if n_generations == 2:
680
+ if self.is_async:
681
+ generator_two = self.fn(*inputs)
682
+ else:
683
+ generator_two = await anyio.to_thread.run_sync(self.fn, *inputs, limiter=self.limiter)
684
+ generator_two = SyncToAsyncIterator(generator, self.limiter)
685
  try:
686
  first_response_two = await async_iteration(generator_two)
687
  first_response_two = self._get_chat_message_comparison(response, first_response_two)