gpt-batch 0.1.3__py3-none-any.whl → 0.1.6__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
@@ -42,37 +42,45 @@ class GPTBatcher:
42
42
 
43
43
  def get_attitude(self, ask_text):
44
44
  index, ask_text = ask_text
45
-
46
- completion = self.client.chat.completions.create(
47
- model=self.model_name,
48
- messages=[
49
- {"role": "system", "content": self.system_prompt},
50
- {"role": "user", "content": ask_text}
51
- ],
52
- temperature=self.temperature,
53
- )
54
- return (index, completion.choices[0].message.content)
45
+ try:
46
+ completion = self.client.chat.completions.create(
47
+ model=self.model_name,
48
+ messages=[
49
+ {"role": "system", "content": self.system_prompt},
50
+ {"role": "user", "content": ask_text}
51
+ ],
52
+ temperature=self.temperature,
53
+ )
54
+ return (index, completion.choices[0].message.content)
55
+ except Exception as e:
56
+ print(f"Error occurred: {e}")
57
+ self.miss_index.append(index)
58
+ return (index, None)
55
59
 
56
60
  def process_attitude(self, message_list):
57
61
  new_list = []
58
62
  num_workers = self.num_workers
59
63
  timeout_duration = self.timeout_duration
60
- retry_attempts=2
61
-
64
+ retry_attempts = 2
65
+
62
66
  executor = ThreadPoolExecutor(max_workers=num_workers)
63
67
  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
68
+ try:
69
+ for chunk in tqdm(message_chunks, desc="Processing messages"):
70
+ future_to_message = {executor.submit(self.get_attitude, message): message for message in chunk}
71
+ for _ in range(retry_attempts):
72
+ done, not_done = wait(future_to_message.keys(), timeout=timeout_duration)
73
+ for future in not_done:
74
+ future.cancel()
75
+ new_list.extend(future.result() for future in done if future.done())
76
+ if len(not_done) == 0:
77
+ break
78
+ future_to_message = {executor.submit(self.get_attitude, future_to_message[future]): future for future in not_done}
79
+ except Exception as e:
80
+ print(f"Error occurred: {e}")
81
+ finally:
82
+ executor.shutdown(wait=False)
83
+ return new_list
76
84
 
77
85
  def complete_attitude_list(self,attitude_list, max_length):
78
86
  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.6
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=jKLK-iuByg3Mc2ZungT5aZYzO60c5yO-YXCOf_70O6w,7591
3
+ tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ tests/test_batcher.py,sha256=N88RZrSuBaDti6Lry7xipyGXHn3jKg85O12mjcHHZA0,3006
5
+ gpt_batch-0.1.6.dist-info/METADATA,sha256=Q0EhkVe8YbKac3JjhASu3_wY3y9hV_YJqqwVEzlf9wc,2932
6
+ gpt_batch-0.1.6.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
7
+ gpt_batch-0.1.6.dist-info/top_level.txt,sha256=FtvJB_L9W_S6jL4G8Em_YWphG1wdKAF20BHUrf4B0yM,16
8
+ gpt_batch-0.1.6.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,,