gpt-batch 0.1.3__tar.gz → 0.1.6__tar.gz
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-0.1.3 → gpt_batch-0.1.6}/PKG-INFO +1 -1
- {gpt_batch-0.1.3 → gpt_batch-0.1.6}/gpt_batch/batcher.py +32 -24
- {gpt_batch-0.1.3 → gpt_batch-0.1.6}/gpt_batch.egg-info/PKG-INFO +1 -1
- {gpt_batch-0.1.3 → gpt_batch-0.1.6}/setup.py +1 -1
- {gpt_batch-0.1.3 → gpt_batch-0.1.6}/README.md +0 -0
- {gpt_batch-0.1.3 → gpt_batch-0.1.6}/gpt_batch/__init__.py +0 -0
- {gpt_batch-0.1.3 → gpt_batch-0.1.6}/gpt_batch.egg-info/SOURCES.txt +0 -0
- {gpt_batch-0.1.3 → gpt_batch-0.1.6}/gpt_batch.egg-info/dependency_links.txt +0 -0
- {gpt_batch-0.1.3 → gpt_batch-0.1.6}/gpt_batch.egg-info/requires.txt +0 -0
- {gpt_batch-0.1.3 → gpt_batch-0.1.6}/gpt_batch.egg-info/top_level.txt +0 -0
- {gpt_batch-0.1.3 → gpt_batch-0.1.6}/setup.cfg +0 -0
- {gpt_batch-0.1.3 → gpt_batch-0.1.6}/tests/__init__.py +0 -0
- {gpt_batch-0.1.3 → gpt_batch-0.1.6}/tests/test_batcher.py +0 -0
@@ -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
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
future
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
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 = []
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|