Skip to content

Commit 9c040d8

Browse files
authored
Merge branch 'master' into new-branch-8
2 parents 54003d8 + 2bebefa commit 9c040d8

File tree

5 files changed

+42
-18
lines changed

5 files changed

+42
-18
lines changed

examples/async/completions/batch.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

94101
if __name__ == '__main__':

examples/sync/completions/batch.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,19 @@ def main() -> None:
6060

6161
# There are only specific models supports batch runs,
6262
# please refer to Yandex Foundation Models doctumentation
63-
model = sdk.models.completions('gemma-3-12b-it')
63+
model = sdk.models.completions('qwen2.5-32b-instruct')
6464

6565
# Batch run returns an operation object you could
6666
# follow or just call .wait method
67-
operation = model.batch.run_deferred(dataset)
67+
task = model.batch.run_deferred(dataset)
6868

69-
resulting_dataset = operation.wait()
69+
# You also could use "structured output feature".
70+
# Look for details in examples/sync/completions/structured_output.py
71+
model = model.configure(response_format='json')
72+
json_task = model.batch.run_deferred(dataset)
73+
74+
resulting_dataset = task.wait()
75+
json_dataset = json_task.wait()
7076

7177
# NB: Resulting dataset have task_type="TextToTextGeneration" and could be used as an input
7278
# for tuning.
@@ -77,11 +83,19 @@ def main() -> None:
7783
print('Resulting dataset lines:')
7884
for line in resulting_dataset.read():
7985
print(line)
86+
87+
print('Json dataset lines:')
88+
for line in json_dataset.read():
89+
print(line)
8090
except ImportError:
81-
print('skipping dataset read; istall yandex-cloud-ml-sdk[datasets] to be able to read')
91+
print('skipping dataset read; install yandex-cloud-ml-sdk[datasets] to be able to read')
8292

83-
# Removing final dataset to not to increase chaos.
93+
# Removing all the data to not to increase chaos.
8494
resulting_dataset.delete()
95+
json_dataset.delete()
96+
task.delete()
97+
json_task.delete()
98+
8599

86100
if __name__ == '__main__':
87101
main()

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ classifiers = [
3333
requires-python = ">=3.9"
3434
dynamic = ["version"]
3535
dependencies = [
36-
"yandexcloud>=0.350.0",
36+
"yandexcloud>=0.354.0",
3737
"grpcio>=1.70.0",
3838
"get-annotations",
3939
"httpx>=0.27,<1",

src/yandex_cloud_ml_sdk/_models/completions/model.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def _make_request(
183183
)
184184

185185
def _make_batch_request(self, dataset_id: str) -> BatchCompletionRequest:
186-
for field in ('tools', 'response_format', 'tool_choice', 'parallel_tool_calls'):
186+
for field in ('tools', 'tool_choice', 'parallel_tool_calls'):
187187
value = getattr(self.config, field)
188188
if value is not None:
189189
warnings.warn(
@@ -192,10 +192,13 @@ def _make_batch_request(self, dataset_id: str) -> BatchCompletionRequest:
192192
UserWarning, 4
193193
)
194194

195+
response_format_kwargs = make_response_format_kwargs(self._config.response_format)
196+
195197
return BatchCompletionRequest(
196198
model_uri=self.uri,
197199
completion_options=self._make_completion_options(stream=False),
198-
source_dataset_id=dataset_id
200+
source_dataset_id=dataset_id,
201+
**response_format_kwargs,
199202
)
200203

201204
async def _run_sync_impl(

src/yandex_cloud_ml_sdk/_types/batch/domain.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async def _run_deferred(self, dataset: DatasetType, *, timeout: float = 60) -> B
4040
stub_class = m._batch_service_stub
4141
proto_metadata_type = m._batch_proto_metadata_type
4242

43-
logger.debug(
43+
logger.info(
4444
'going to create batch task at %r service with a %r request',
4545
stub_class.__name__, request
4646
)

0 commit comments

Comments
 (0)