@@ -61,19 +61,19 @@ async def main() -> None:
6161
6262 # There are only specific models supports batch runs,
6363 # please refer to Yandex Foundation Models doctumentation
64- model = sdk .models .completions ('gemma-3-12b-it ' )
64+ model = sdk .models .completions ('qwen2.5-32b-instruct ' )
6565
6666 # Batch run returns an operation object you could
6767 # follow or just call .wait method
6868 task = await model .batch .run_deferred (dataset )
6969
70- try :
71- resulting_dataset = await task
72- except :
73- status = await task . get_status ( )
74- if status . is_running :
75- await task . cancel ()
76- raise
70+ # You also could use "structured output feature".
71+ # Look for details in examples/async/completions/structured_output.py
72+ model = model . configure ( response_format = 'json' )
73+ json_task = await model . batch . run_deferred ( dataset )
74+
75+ resulting_dataset = await task
76+ json_dataset = await json_task
7777
7878 # NB: Resulting dataset have task_type="TextToTextGeneration" and could be used as an input
7979 # for tuning.
@@ -84,11 +84,18 @@ async def main() -> None:
8484 print ('Resulting dataset lines:' )
8585 async for line in resulting_dataset .read ():
8686 print (line )
87+
88+ print ('Json dataset lines:' )
89+ async for line in json_dataset .read ():
90+ print (line )
8791 except ImportError :
8892 print ('skipping dataset read; install yandex-cloud-ml-sdk[datasets] to be able to read' )
8993
90- # Removing final dataset to not to increase chaos.
94+ # Removing all the data to not to increase chaos.
9195 await resulting_dataset .delete ()
96+ await json_dataset .delete ()
97+ await task .delete ()
98+ await json_task .delete ()
9299
93100
94101if __name__ == '__main__' :
0 commit comments