promptbuilder 0.4.29__py3-none-any.whl → 0.4.30__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.
@@ -121,9 +121,10 @@ class BaseLLMClient(ABC, utils.InheritDecoratorsMixin):
121
121
  total_count += BaseLLMClient._response_out_tokens(response)
122
122
  if max_tokens is not None and total_count >= max_tokens:
123
123
  break
124
- if response.candidates:
125
- BaseLLMClient._append_generated_part(messages, response)
126
- response.candidates[0].content = messages[-1] if len(messages) > 0 else None
124
+ if response.candidates and response.candidates[0].content:
125
+ appended_message = BaseLLMClient._append_generated_part(messages, response)
126
+ if appended_message is not None:
127
+ response.candidates[0].content = appended_message
127
128
  return response
128
129
 
129
130
  @logfire_decorators.create
@@ -245,7 +246,7 @@ class BaseLLMClient(ABC, utils.InheritDecoratorsMixin):
245
246
 
246
247
 
247
248
  @staticmethod
248
- def _append_generated_part(messages: list[Content], response: Response):
249
+ def _append_generated_part(messages: list[Content], response: Response) -> Content | None:
249
250
  assert(response.candidates and response.candidates[0].content), "Response must contain at least one candidate with content."
250
251
 
251
252
  text_parts = [
@@ -262,7 +263,7 @@ class BaseLLMClient(ABC, utils.InheritDecoratorsMixin):
262
263
  response_text = "".join(part.text for part in thought_parts)
263
264
  is_thought = True
264
265
  else:
265
- raise ValueError("No text or thought found in the response parts.")
266
+ return None
266
267
 
267
268
  if len(messages) > 0 and messages[-1].role == "model":
268
269
  message_to_append = messages[-1]
@@ -274,6 +275,7 @@ class BaseLLMClient(ABC, utils.InheritDecoratorsMixin):
274
275
  message_to_append.parts.append(Part(text=response_text, thought=is_thought))
275
276
  else:
276
277
  messages.append(Content(parts=[Part(text=response_text, thought=is_thought)], role="model"))
278
+ return messages[-1]
277
279
 
278
280
  @staticmethod
279
281
  def _response_out_tokens(response: Response):
@@ -458,9 +460,10 @@ class BaseLLMClientAsync(ABC, utils.InheritDecoratorsMixin):
458
460
  total_count += BaseLLMClient._response_out_tokens(response)
459
461
  if max_tokens is not None and total_count >= max_tokens:
460
462
  break
461
- if response.candidates:
462
- BaseLLMClient._append_generated_part(messages, response)
463
- response.candidates[0].content = messages[-1] if len(messages) > 0 else None
463
+ if response.candidates and response.candidates[0].content:
464
+ appended_message = BaseLLMClient._append_generated_part(messages, response)
465
+ if appended_message is not None:
466
+ response.candidates[0].content = appended_message
464
467
  return response
465
468
 
466
469
  @logfire_decorators.create_async
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: promptbuilder
3
- Version: 0.4.29
3
+ Version: 0.4.30
4
4
  Summary: Library for building prompts for LLMs
5
5
  Home-page: https://github.com/kapulkin/promptbuilder
6
6
  Author: Kapulkin Stanislav
@@ -9,7 +9,7 @@ promptbuilder/agent/utils.py,sha256=vTkphKw04v_QDIJtoB2JKK0RGY6iI1t_0LbmuStunzI,
9
9
  promptbuilder/llm_client/__init__.py,sha256=wJ33cnRtZX_YPsbcGxEu3SEZMOhPX7-fHI59MEPUe7I,517
10
10
  promptbuilder/llm_client/aisuite_client.py,sha256=_TfB1xv73kIn4n8ulV3bj8bHOVm4DOD5uIdX-pbYoXY,15563
11
11
  promptbuilder/llm_client/anthropic_client.py,sha256=HSIAZVOQoi3hinjhBVGqpt91k0x38xj6EUsPSUrlAA0,28076
12
- promptbuilder/llm_client/base_client.py,sha256=T-51WbVuMktCdoI0Z7Mk4LcaqV6GRqoDiZeZJPKoimI,28763
12
+ promptbuilder/llm_client/base_client.py,sha256=2VXc3Jw1ugu8VTTeK72Ntvh2Zobg23uxw1a6qY6W6HI,28908
13
13
  promptbuilder/llm_client/bedrock_client.py,sha256=rJMzVV7x_sNJ1nVVqWU1sU-Pq7xlxFxIa_hTD2wtM1Y,27943
14
14
  promptbuilder/llm_client/config.py,sha256=exQEm35wp7lK5SfXNpN5H9VZEb2LVa4pyZ-cxGt1U-U,1124
15
15
  promptbuilder/llm_client/exceptions.py,sha256=t-X7r_a8B1jNu8eEavde1jXu5dz97yV3IG4YHOtgh0Y,4836
@@ -20,8 +20,8 @@ promptbuilder/llm_client/main.py,sha256=m-9jM2IYMFy6aZBUmPb52wpFlIK0H1aRj293oFmx
20
20
  promptbuilder/llm_client/openai_client.py,sha256=lT0RCiixJBoCtzUbL_0J5NQ5G8KGONzK3dQ73_NgL78,24789
21
21
  promptbuilder/llm_client/types.py,sha256=kgbg5FRzvZwu98y1OhAZJDneXBNPnsFZueQCr9HXIY4,8063
22
22
  promptbuilder/llm_client/utils.py,sha256=79lvSppjrrItHB5MIozbp_5Oq7TsOK4Qzt9Ae3XMLFw,7624
23
- promptbuilder-0.4.29.dist-info/licenses/LICENSE,sha256=fqXmInzgsvEOIaKSBgcrwKyYCGYF0MKErJ0YivtODcc,1096
24
- promptbuilder-0.4.29.dist-info/METADATA,sha256=rfxQaTbrKl5se6wrV6b2QfMDhtSrxG7WbkG06fGtNCo,3729
25
- promptbuilder-0.4.29.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
26
- promptbuilder-0.4.29.dist-info/top_level.txt,sha256=UBVcYn4UgrPy3O3fmmnPEU_kieuplBMgheetIMei4EI,14
27
- promptbuilder-0.4.29.dist-info/RECORD,,
23
+ promptbuilder-0.4.30.dist-info/licenses/LICENSE,sha256=fqXmInzgsvEOIaKSBgcrwKyYCGYF0MKErJ0YivtODcc,1096
24
+ promptbuilder-0.4.30.dist-info/METADATA,sha256=wKv1yEjLK2Zm8jOyXaY0_7mNcug1ZorhfHlPDFw3sA4,3729
25
+ promptbuilder-0.4.30.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
26
+ promptbuilder-0.4.30.dist-info/top_level.txt,sha256=UBVcYn4UgrPy3O3fmmnPEU_kieuplBMgheetIMei4EI,14
27
+ promptbuilder-0.4.30.dist-info/RECORD,,