mirascope 1.22.5__py3-none-any.whl → 1.23.0__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.
@@ -8,28 +8,51 @@ from ..call_response_chunk import GoogleCallResponseChunk
8
8
  from ..tool import GoogleTool
9
9
 
10
10
 
11
+ def _handle_chunk(
12
+ chunk: GenerateContentResponse, tool_types: list[type[GoogleTool]] | None = None
13
+ ) -> Generator[tuple[GoogleCallResponseChunk, GoogleTool | None], None, None]:
14
+ """Handles a chunk of the stream and yields any tools that are found.
15
+
16
+ Note: google seems to only ever return full tool calls, so no partial possible here.
17
+ """
18
+ call_response_chunk = GoogleCallResponseChunk(chunk=chunk)
19
+ has_tools = False
20
+ if tool_types and (
21
+ (candidates := chunk.candidates)
22
+ and (content := candidates[0].content)
23
+ and (parts := content.parts)
24
+ ):
25
+ for part in parts:
26
+ if function_call := part.function_call:
27
+ has_tools = True
28
+ for tool_type in tool_types:
29
+ if tool_type._name() == function_call.name:
30
+ tool = tool_type.from_tool_call(function_call)
31
+ yield (call_response_chunk, tool)
32
+ if not has_tools:
33
+ yield call_response_chunk, None
34
+
35
+
11
36
  def handle_stream(
12
37
  stream: Generator[GenerateContentResponse, None, None],
13
38
  tool_types: list[type[GoogleTool]] | None = None,
14
39
  partial_tools: bool = False,
15
- ) -> Generator[tuple[GoogleCallResponseChunk, None], None, None]:
16
- """Iterator over the stream and constructs tools as they are streamed.
17
-
18
- Note: google does not currently support streaming tools.
19
- """
40
+ ) -> Generator[tuple[GoogleCallResponseChunk, GoogleTool | None], None, None]:
41
+ """Iterator over the stream and constructs tools as they are streamed."""
20
42
  for chunk in stream:
21
- yield GoogleCallResponseChunk(chunk=chunk), None
43
+ yield from _handle_chunk(chunk, tool_types)
22
44
 
23
45
 
24
46
  async def handle_stream_async(
25
47
  stream: AsyncGenerator[GenerateContentResponse, None],
26
48
  tool_types: list[type[GoogleTool]] | None = None,
27
49
  partial_tools: bool = False,
28
- ) -> AsyncGenerator[tuple[GoogleCallResponseChunk, None], None]:
50
+ ) -> AsyncGenerator[tuple[GoogleCallResponseChunk, GoogleTool | None], None]:
29
51
  """
30
52
  Async iterator over the stream and constructs tools as they are streamed.
31
53
 
32
54
  Note: google does not currently support streaming tools.
33
55
  """
34
56
  async for chunk in stream:
35
- yield GoogleCallResponseChunk(chunk=chunk), None
57
+ for call_response_chunk, tool in _handle_chunk(chunk, tool_types):
58
+ yield call_response_chunk, tool
@@ -48,7 +48,14 @@ class GoogleCallResponseChunk(
48
48
  @property
49
49
  def content(self) -> str:
50
50
  """Returns the chunk content for the 0th choice."""
51
- return self.chunk.candidates[0].content.parts[0].text # pyright: ignore [reportOptionalMemberAccess, reportOptionalSubscript, reportReturnType]
51
+ if (
52
+ not (candidates := self.chunk.candidates)
53
+ or not (content := candidates[0].content)
54
+ or not (parts := content.parts)
55
+ or not (text := parts[0].text)
56
+ ):
57
+ return ""
58
+ return text
52
59
 
53
60
  @property
54
61
  def finish_reasons(self) -> list[GoogleFinishReason]:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mirascope
3
- Version: 1.22.5
3
+ Version: 1.23.0
4
4
  Summary: LLM abstractions that aren't obstructions
5
5
  Project-URL: Homepage, https://mirascope.com
6
6
  Project-URL: Documentation, https://mirascope.com/WELCOME
@@ -214,7 +214,7 @@ mirascope/core/google/_call.py,sha256=GJOPyvHzVlSXvJpgQhJFg4wFHFUYsvvrbjhNxU-nSl
214
214
  mirascope/core/google/_call_kwargs.py,sha256=baCYcxWsmV06ATw6nuQhh6FPm3k6oWmKOn0MyjESDGc,372
215
215
  mirascope/core/google/call_params.py,sha256=9Dt5m1pPVjpl5Qppz6Egl_9FyGjjz9aGCnXkVps7C_Q,538
216
216
  mirascope/core/google/call_response.py,sha256=nAlH1XWQMiMfCKgi6sG3qIA0YccxIzLWzY_NNl2JtqM,7372
217
- mirascope/core/google/call_response_chunk.py,sha256=oORYaGjOBv4U1IVhsR_ZS-Vr-B58I8G0-9d6Kcj9RM4,3427
217
+ mirascope/core/google/call_response_chunk.py,sha256=14ggxCYtl92LdyA3nxY8awKQVSBvFV1Wse2Jm7rfvJc,3535
218
218
  mirascope/core/google/dynamic_config.py,sha256=O6j8F0fLVFuuNwURneu5OpPuu_bMEtbDEFHhJXRT6V0,857
219
219
  mirascope/core/google/stream.py,sha256=bTxB8OUrKXxzmcX0C7_-LqtBfaAAazA5HjKZGSxxtLw,4466
220
220
  mirascope/core/google/tool.py,sha256=61a9Ejdxz41pwaab9VE2yvP_J1Aebua3BeRPJ_GJSnE,5138
@@ -223,7 +223,7 @@ mirascope/core/google/_utils/_convert_common_call_params.py,sha256=TF7GWBHcpfzb7
223
223
  mirascope/core/google/_utils/_convert_finish_reason_to_common_finish_reasons.py,sha256=ig4tb7Zanz-tyZpvc9Ncd47a2FNTOS7-wl1PYBq-4cY,879
224
224
  mirascope/core/google/_utils/_convert_message_params.py,sha256=9I7Q79Z8tBCLZtfjWJNQkuKgz0n2L43SzHB3cV3hNmY,8926
225
225
  mirascope/core/google/_utils/_get_json_output.py,sha256=sxDgT0Ra6YJynL5_hhakf0dNJEhZm0DfAgfcvC_DAFU,1596
226
- mirascope/core/google/_utils/_handle_stream.py,sha256=BxFuheAu1LKPrPsDxxiLWd2KoajkwJyx2_QT1NXwtWE,1212
226
+ mirascope/core/google/_utils/_handle_stream.py,sha256=xTaQvAWnJ195YI_h68USvit4-G8T_fogmtBZFhu1qoE,2238
227
227
  mirascope/core/google/_utils/_message_param_converter.py,sha256=qOj8bAdQusFhLg-mzQ1TJwbMQHvjY7DYrTGOIylu5hs,6661
228
228
  mirascope/core/google/_utils/_setup_call.py,sha256=UoV4McGgSS79PKErjArCmrq1HmpFvq2qegJYoyY4P5U,6469
229
229
  mirascope/core/google/_utils/_validate_media_type.py,sha256=sUOjKpC498L-NCiECejAAfSzMUAvZT84rf-2Yo-JE58,1042
@@ -371,7 +371,7 @@ mirascope/v0/base/ops_utils.py,sha256=1Qq-VIwgHBaYutiZsS2MUQ4OgPC3APyywI5bTiTAmA
371
371
  mirascope/v0/base/prompts.py,sha256=FM2Yz98cSnDceYogiwPrp4BALf3_F3d4fIOCGAkd-SE,1298
372
372
  mirascope/v0/base/types.py,sha256=ZfatJoX0Yl0e3jhv0D_MhiSVHLYUeJsdN3um3iE10zY,352
373
373
  mirascope/v0/base/utils.py,sha256=XREPENRQTu8gpMhHU8RC8qH_am3FfGUvY-dJ6x8i-mw,681
374
- mirascope-1.22.5.dist-info/METADATA,sha256=HIVPcLXEYG16Rr2SxAz1ogSCdHk5vQGGJZrcmmdB56M,8783
375
- mirascope-1.22.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
376
- mirascope-1.22.5.dist-info/licenses/LICENSE,sha256=LAs5Q8mdawTsVdONpDGukwsoc4KEUBmmonDEL39b23Y,1072
377
- mirascope-1.22.5.dist-info/RECORD,,
374
+ mirascope-1.23.0.dist-info/METADATA,sha256=IRI77JnWVALVxY382zMjwubZwgKE4IY5r52YSNoNYD8,8783
375
+ mirascope-1.23.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
376
+ mirascope-1.23.0.dist-info/licenses/LICENSE,sha256=LAs5Q8mdawTsVdONpDGukwsoc4KEUBmmonDEL39b23Y,1072
377
+ mirascope-1.23.0.dist-info/RECORD,,