poma 0.2.1__tar.gz → 0.2.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: poma
3
- Version: 0.2.1
3
+ Version: 0.2.3
4
4
  Summary: Official Python SDK for the Poma document-processing API
5
5
  Author-email: "POMA AI GmbH, Berlin" <sdk@poma-ai.com>
6
6
  License-Expression: MPL-2.0
@@ -139,6 +139,8 @@ class Poma:
139
139
  """
140
140
  time.sleep(initial_delay)
141
141
  current_interval = poll_interval
142
+ last_status = None
143
+
142
144
  while True:
143
145
  time.sleep(current_interval)
144
146
  try:
@@ -181,9 +183,18 @@ class Poma:
181
183
  elif status == "processing":
182
184
  if show_progress:
183
185
  print(f"Job {job_id} is still processing...")
186
+ if last_status == "pending":
187
+ current_interval = poll_interval
188
+ current_interval = min(current_interval * 1.5, max_interval)
189
+ elif status == "pending":
190
+ if show_progress:
191
+ print(
192
+ f"Job {job_id} is pending (queued due to rate limiting, sequential processing - common on demo accounts)..."
193
+ )
184
194
  current_interval = min(current_interval * 1.5, max_interval)
185
195
  else:
186
196
  raise InvalidResponseError(f"Unexpected job status: {status}")
197
+ last_status = status
187
198
  except httpx.HTTPStatusError as error:
188
199
  raise RemoteServerError(
189
200
  f"HTTP error: {error.response.status_code} {error.response.text}"
@@ -224,14 +224,24 @@ def _get_relevant_chunks_for_ids(
224
224
  # idx1 must be before idx2 and have smaller depth
225
225
  if idx1 >= idx2:
226
226
  return False
227
+ if idx1 not in index_to_depth or idx2 not in index_to_depth:
228
+ return False
227
229
  depth1 = index_to_depth[idx1]
228
230
  depth2 = index_to_depth[idx2]
229
231
  if depth1 >= depth2:
230
232
  return False
231
233
  # scan from idx1+1 up to idx2, making sure all are deeper than depth1 until idx2
232
- for i in range(idx1 + 1, idx2 + 1):
233
- depth = index_to_depth[sorted_chunks[i]["chunk_index"]]
234
- if depth <= depth1 and sorted_chunks[i]["chunk_index"] != idx2:
234
+ # Use sorted_chunks to iterate in order, but check chunk_index values
235
+ for chunk in sorted_chunks:
236
+ chunk_idx = chunk["chunk_index"]
237
+ if chunk_idx <= idx1:
238
+ continue
239
+ if chunk_idx > idx2:
240
+ break
241
+ if chunk_idx == idx2:
242
+ continue # skip idx2 itself, we'll check it after
243
+ depth = index_to_depth[chunk_idx]
244
+ if depth <= depth1:
235
245
  return False
236
246
  return True
237
247
 
@@ -245,9 +255,20 @@ def _get_relevant_chunks_for_ids(
245
255
 
246
256
  # Standard subtree/parent finding routines
247
257
  def get_child_indices(chunk_index: int) -> list[int]:
258
+ if chunk_index not in index_to_depth:
259
+ return []
248
260
  base_depth = index_to_depth[chunk_index]
249
261
  children = []
250
- for i in range(chunk_index + 1, len(sorted_chunks)):
262
+ # Find the position of chunk_index in sorted_chunks
263
+ start_pos = None
264
+ for pos, chunk in enumerate(sorted_chunks):
265
+ if chunk["chunk_index"] == chunk_index:
266
+ start_pos = pos
267
+ break
268
+ if start_pos is None:
269
+ return []
270
+ # Iterate forward from the next position
271
+ for i in range(start_pos + 1, len(sorted_chunks)):
251
272
  idx = sorted_chunks[i]["chunk_index"]
252
273
  depth = sorted_chunks[i]["depth"]
253
274
  if depth <= base_depth:
@@ -256,9 +277,20 @@ def _get_relevant_chunks_for_ids(
256
277
  return children
257
278
 
258
279
  def get_parent_indices(chunk_index: int) -> list[int]:
280
+ if chunk_index not in index_to_depth:
281
+ return []
259
282
  parents = []
260
283
  current_depth = index_to_depth[chunk_index]
261
- for i in range(chunk_index - 1, -1, -1):
284
+ # Find the position of chunk_index in sorted_chunks
285
+ start_pos = None
286
+ for pos, chunk in enumerate(sorted_chunks):
287
+ if chunk["chunk_index"] == chunk_index:
288
+ start_pos = pos
289
+ break
290
+ if start_pos is None:
291
+ return []
292
+ # Iterate backward from the previous position
293
+ for i in range(start_pos - 1, -1, -1):
262
294
  idx = sorted_chunks[i]["chunk_index"]
263
295
  depth = sorted_chunks[i]["depth"]
264
296
  if depth < current_depth:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: poma
3
- Version: 0.2.1
3
+ Version: 0.2.3
4
4
  Summary: Official Python SDK for the Poma document-processing API
5
5
  Author-email: "POMA AI GmbH, Berlin" <sdk@poma-ai.com>
6
6
  License-Expression: MPL-2.0
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "poma"
3
- version = "0.2.1"
3
+ version = "0.2.3"
4
4
  description = "Official Python SDK for the Poma document-processing API"
5
5
  authors = [{ name = "POMA AI GmbH, Berlin", email = "sdk@poma-ai.com" }]
6
6
  readme = "README.md"
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
File without changes