mirascope 1.22.6__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.
- mirascope/core/google/_utils/_handle_stream.py +31 -8
- {mirascope-1.22.6.dist-info → mirascope-1.23.0.dist-info}/METADATA +1 -1
- {mirascope-1.22.6.dist-info → mirascope-1.23.0.dist-info}/RECORD +5 -5
- {mirascope-1.22.6.dist-info → mirascope-1.23.0.dist-info}/WHEEL +0 -0
- {mirascope-1.22.6.dist-info → mirascope-1.23.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -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
|
|
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
|
-
|
|
57
|
+
for call_response_chunk, tool in _handle_chunk(chunk, tool_types):
|
|
58
|
+
yield call_response_chunk, tool
|
|
@@ -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=
|
|
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.
|
|
375
|
-
mirascope-1.
|
|
376
|
-
mirascope-1.
|
|
377
|
-
mirascope-1.
|
|
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,,
|
|
File without changes
|
|
File without changes
|