gpt-batch 0.1.3__py3-none-any.whl → 0.1.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
gpt_batch/batcher.py CHANGED
@@ -57,22 +57,26 @@ class GPTBatcher:
57
57
  new_list = []
58
58
  num_workers = self.num_workers
59
59
  timeout_duration = self.timeout_duration
60
- retry_attempts=2
61
-
60
+ retry_attempts = 2
61
+
62
62
  executor = ThreadPoolExecutor(max_workers=num_workers)
63
63
  message_chunks = list(self.chunk_list(message_list, num_workers))
64
- for chunk in tqdm(message_chunks, desc="Processing messages"):
65
- future_to_message = {executor.submit(self.get_attitude, message): message for message in chunk}
66
- for _ in range(retry_attempts):
67
- done, not_done = wait(future_to_message.keys(), timeout=timeout_duration)
68
- for future in not_done:
69
- future.cancel()
70
- new_list.extend(future.result() for future in done if future.done())
71
- if len(not_done) == 0:
72
- break
73
- future_to_message = {executor.submit(self.get_attitude, future_to_message[future]): future_to_message[future] for future in not_done}
74
- executor.shutdown(wait=False)
75
- return new_list
64
+ try:
65
+ for chunk in tqdm(message_chunks, desc="Processing messages"):
66
+ future_to_message = {executor.submit(self.get_attitude, message): message for message in chunk}
67
+ for _ in range(retry_attempts):
68
+ done, not_done = wait(future_to_message.keys(), timeout=timeout_duration)
69
+ for future in not_done:
70
+ future.cancel()
71
+ new_list.extend(future.result() for future in done if future.done())
72
+ if len(not_done) == 0:
73
+ break
74
+ future_to_message = {executor.submit(self.get_attitude, future_to_message[future]): future for future in not_done}
75
+ except Exception as e:
76
+ print(f"Error occurred: {e}")
77
+ finally:
78
+ executor.shutdown(wait=False)
79
+ return new_list
76
80
 
77
81
  def complete_attitude_list(self,attitude_list, max_length):
78
82
  completed_list = []
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: gpt-batch
3
- Version: 0.1.3
3
+ Version: 0.1.5
4
4
  Summary: A package for batch processing with OpenAI API.
5
5
  Home-page: https://github.com/fengsxy/gpt_batch
6
6
  Author: Ted Yu
@@ -0,0 +1,8 @@
1
+ gpt_batch/__init__.py,sha256=zGDItktTxKLSQr44GY78dl5LKsSJig0Q59dzusqhU0U,59
2
+ gpt_batch/batcher.py,sha256=YvOX1V_9iX5jTX7xZOhjOWeT0IUlv9c-_UkLW2s1wFo,7395
3
+ tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ tests/test_batcher.py,sha256=N88RZrSuBaDti6Lry7xipyGXHn3jKg85O12mjcHHZA0,3006
5
+ gpt_batch-0.1.5.dist-info/METADATA,sha256=kb524fTeHxmmYZM6MnhG_G_gqwLRy4ptdVmjIcaIdac,2932
6
+ gpt_batch-0.1.5.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
7
+ gpt_batch-0.1.5.dist-info/top_level.txt,sha256=FtvJB_L9W_S6jL4G8Em_YWphG1wdKAF20BHUrf4B0yM,16
8
+ gpt_batch-0.1.5.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- gpt_batch/__init__.py,sha256=zGDItktTxKLSQr44GY78dl5LKsSJig0Q59dzusqhU0U,59
2
- gpt_batch/batcher.py,sha256=DeW9xmD2FIRryLXOKnvfMfDYitW1U3WOfew9A6ljD7A,7258
3
- tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- tests/test_batcher.py,sha256=N88RZrSuBaDti6Lry7xipyGXHn3jKg85O12mjcHHZA0,3006
5
- gpt_batch-0.1.3.dist-info/METADATA,sha256=cEtCNyQJVBk1TzFz7x8lcrL2Ih8zyM0Cm8eEI8KOrQo,2932
6
- gpt_batch-0.1.3.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
7
- gpt_batch-0.1.3.dist-info/top_level.txt,sha256=FtvJB_L9W_S6jL4G8Em_YWphG1wdKAF20BHUrf4B0yM,16
8
- gpt_batch-0.1.3.dist-info/RECORD,,