From cded428910eb1340b38387b1a63af0006e2e8828 Mon Sep 17 00:00:00 2001 From: David Miguel Date: Tue, 22 Oct 2024 22:35:11 +0200 Subject: [PATCH] feat: Add support for Message Batches in anthropic_sdk_dart --- packages/anthropic_sdk_dart/README.md | 65 ++ .../anthropic_sdk_dart/lib/src/client.dart | 1 + .../lib/src/generated/client.dart | 59 + .../schema/batch_message_request.dart | 47 + .../lib/src/generated/schema/block.dart | 2 +- .../schema/create_message_batch_request.dart | 40 + .../src/generated/schema/message_batch.dart | 98 ++ .../schema/message_batch_request_counts.dart | 62 + .../lib/src/generated/schema/schema.dart | 4 + .../src/generated/schema/schema.freezed.dart | 1013 ++++++++++++++++- .../lib/src/generated/schema/schema.g.dart | 93 ++ .../oas/anthropic_openapi_curated.yaml | 139 ++- .../test/messages_test.dart | 62 + 13 files changed, 1680 insertions(+), 5 deletions(-) create mode 100644 packages/anthropic_sdk_dart/lib/src/generated/schema/batch_message_request.dart create mode 100644 packages/anthropic_sdk_dart/lib/src/generated/schema/create_message_batch_request.dart create mode 100644 packages/anthropic_sdk_dart/lib/src/generated/schema/message_batch.dart create mode 100644 packages/anthropic_sdk_dart/lib/src/generated/schema/message_batch_request_counts.dart diff --git a/packages/anthropic_sdk_dart/README.md b/packages/anthropic_sdk_dart/README.md index d60965fa..83fc9f01 100644 --- a/packages/anthropic_sdk_dart/README.md +++ b/packages/anthropic_sdk_dart/README.md @@ -17,6 +17,7 @@ Unofficial Dart client for [Anthropic](https://docs.anthropic.com/en/api) API (a **Supported endpoints:** - Messages (with tools and streaming support) +- Message Batches ## Table of contents @@ -24,6 +25,7 @@ Unofficial Dart client for [Anthropic](https://docs.anthropic.com/en/api) API (a * [Authentication](#authentication) * [Messages](#messages) * [Tool use](#tool-use) + * [Message Batches](#message-batches) - [Advance Usage](#advance-usage) * [Default HTTP client](#default-http-client) * [Custom HTTP client](#custom-http-client) @@ -242,6 +244,69 @@ await for (final res in stream) { // {"location": "Boston, MA", "unit": "fahrenheit"} ``` +### Message Batches + +The Message Batches API is a powerful, cost-effective way to asynchronously process large volumes of Messages requests. This approach is well-suited to tasks that do not require immediate responses, reducing costs by 50% while increasing throughput. + +Refer to the [official documentation](https://docs.anthropic.com/en/docs/build-with-claude/message-batches) for more information. + +**Prepare and create your batch:** + +```dart +const batchRequest = CreateMessageBatchRequest( + requests: [ + BatchMessageRequest( + customId: 'request1', + params: CreateMessageRequest( + model: Model.model(Models.claudeInstant12), + temperature: 0, + maxTokens: 1024, + messages: [ + Message( + role: MessageRole.user, + content: MessageContent.text( + 'List the numbers from 1 to 9 in order.'), + ), + ], + ), + ), + BatchMessageRequest( + customId: 'request2', + params: CreateMessageRequest( + model: Model.model(Models.claudeInstant12), + temperature: 0, + maxTokens: 1024, + messages: [ + Message( + role: MessageRole.user, + content: MessageContent.text( + 'List the numbers from 10 to 19 in order.'), + ), + ], + ), + ), + ], +); +var batch = await client.createMessageBatch(request: batchRequest); +print(batch.id); +``` + +**Tracking your batch:** + +```dart +do { + await Future.delayed(const Duration(seconds: 5)); + batch = await client.retrieveMessageBatch(id: batch.id); +} while (batch.processingStatus == MessageBatchProcessingStatus.inProgress); +``` + +**Retrieving batch results:** + +```dart +batch = await client.retrieveMessageBatch(id: batch.id); +print(batch.resultsUrl); +``` + ## Advance Usage ### Default HTTP client diff --git a/packages/anthropic_sdk_dart/lib/src/client.dart b/packages/anthropic_sdk_dart/lib/src/client.dart index 3d02a34b..bfc95ad3 100644 --- a/packages/anthropic_sdk_dart/lib/src/client.dart +++ b/packages/anthropic_sdk_dart/lib/src/client.dart @@ -38,6 +38,7 @@ class AnthropicClient extends g.AnthropicClient { baseUrl: baseUrl, headers: { 'anthropic-version': '2023-06-01', + 'anthropic-beta': 'message-batches-2024-09-24', ...?headers, }, queryParams: queryParams ?? const {}, diff --git a/packages/anthropic_sdk_dart/lib/src/generated/client.dart b/packages/anthropic_sdk_dart/lib/src/generated/client.dart index 0f3e82a8..80e9efcc 100644 --- a/packages/anthropic_sdk_dart/lib/src/generated/client.dart +++ b/packages/anthropic_sdk_dart/lib/src/generated/client.dart @@ -392,4 +392,63 @@ class AnthropicClient { ); return Message.fromJson(_jsonDecode(r)); } + + // ------------------------------------------ + // METHOD: createMessageBatch + // ------------------------------------------ + + /// Create a Message Batch + /// + /// Send a batch of Message creation requests. + /// + /// `request`: The request parameters for creating a message batch. + /// + /// `POST` `https://api.anthropic.com/v1/messages/batches` + Future createMessageBatch({ + required CreateMessageBatchRequest request, + }) async { + final r = await makeRequest( + baseUrl: 'https://api.anthropic.com/v1', + path: '/messages/batches', + method: HttpMethod.post, + isMultipart: false, + requestType: 'application/json', + responseType: 'application/json', + body: request, + headerParams: { + if (apiKey.isNotEmpty) 'x-api-key': apiKey, + }, + ); + return MessageBatch.fromJson(_jsonDecode(r)); + } + + // ------------------------------------------ + // METHOD: retrieveMessageBatch + // ------------------------------------------ + + /// Retrieve a Message Batch + /// + /// This endpoint is idempotent and can be used to poll for Message Batch + /// completion. To access the results of a Message Batch, make a request to the + /// `results_url` field in the response. + /// + /// `id`: The ID of the message batch to retrieve. + /// + /// `GET` `https://api.anthropic.com/v1/messages/batches/{id}` + Future retrieveMessageBatch({ + required String id, + }) async { + final r = await makeRequest( + baseUrl: 'https://api.anthropic.com/v1', + path: '/messages/batches/$id', + method: HttpMethod.get, + isMultipart: false, + requestType: '', + responseType: 'application/json', + headerParams: { + if (apiKey.isNotEmpty) 'x-api-key': apiKey, + }, + ); + return MessageBatch.fromJson(_jsonDecode(r)); + } } diff --git a/packages/anthropic_sdk_dart/lib/src/generated/schema/batch_message_request.dart b/packages/anthropic_sdk_dart/lib/src/generated/schema/batch_message_request.dart new file mode 100644 index 00000000..7becb941 --- /dev/null +++ b/packages/anthropic_sdk_dart/lib/src/generated/schema/batch_message_request.dart @@ -0,0 +1,47 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: invalid_annotation_target +part of anthropic_schema; + +// ========================================== +// CLASS: BatchMessageRequest +// ========================================== + +/// An individual message request within a batch. +@freezed +class BatchMessageRequest with _$BatchMessageRequest { + const BatchMessageRequest._(); + + /// Factory constructor for BatchMessageRequest + const factory BatchMessageRequest({ + /// Developer-provided ID created for each request in a Message Batch. Useful for + /// matching results to requests, as results may be given out of request order. + /// + /// Must be unique for each request within the Message Batch. + @JsonKey(name: 'custom_id') required String customId, + + /// The request parameters for creating a message. + required CreateMessageRequest params, + }) = _BatchMessageRequest; + + /// Object construction from a JSON representation + factory BatchMessageRequest.fromJson(Map json) => + _$BatchMessageRequestFromJson(json); + + /// List of all property names of schema + static const List propertyNames = ['custom_id', 'params']; + + /// Perform validations on the schema property values + String? validateSchema() { + return null; + } + + /// Map representation of object (not serialized) + Map toMap() { + return { + 'custom_id': customId, + 'params': params, + }; + } +} diff --git a/packages/anthropic_sdk_dart/lib/src/generated/schema/block.dart b/packages/anthropic_sdk_dart/lib/src/generated/schema/block.dart index e15126a3..cfcae33a 100644 --- a/packages/anthropic_sdk_dart/lib/src/generated/schema/block.dart +++ b/packages/anthropic_sdk_dart/lib/src/generated/schema/block.dart @@ -52,7 +52,7 @@ sealed class Block with _$Block { /// The name of the tool being used. required String name, - /// An object containing the input being passed to the tool, conforming to the tool’s `input_schema`. + /// An object containing the input being passed to the tool, conforming to the tool's `input_schema`. required Map input, /// The type of content block. diff --git a/packages/anthropic_sdk_dart/lib/src/generated/schema/create_message_batch_request.dart b/packages/anthropic_sdk_dart/lib/src/generated/schema/create_message_batch_request.dart new file mode 100644 index 00000000..e9db448c --- /dev/null +++ b/packages/anthropic_sdk_dart/lib/src/generated/schema/create_message_batch_request.dart @@ -0,0 +1,40 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: invalid_annotation_target +part of anthropic_schema; + +// ========================================== +// CLASS: CreateMessageBatchRequest +// ========================================== + +/// The request parameters for creating a message batch. +@freezed +class CreateMessageBatchRequest with _$CreateMessageBatchRequest { + const CreateMessageBatchRequest._(); + + /// Factory constructor for CreateMessageBatchRequest + const factory CreateMessageBatchRequest({ + /// List of requests for prompt completion. Each is an individual request to create a Message. + required List requests, + }) = _CreateMessageBatchRequest; + + /// Object construction from a JSON representation + factory CreateMessageBatchRequest.fromJson(Map json) => + _$CreateMessageBatchRequestFromJson(json); + + /// List of all property names of schema + static const List propertyNames = ['requests']; + + /// Perform validations on the schema property values + String? validateSchema() { + return null; + } + + /// Map representation of object (not serialized) + Map toMap() { + return { + 'requests': requests, + }; + } +} diff --git a/packages/anthropic_sdk_dart/lib/src/generated/schema/message_batch.dart b/packages/anthropic_sdk_dart/lib/src/generated/schema/message_batch.dart new file mode 100644 index 00000000..3b94c3fb --- /dev/null +++ b/packages/anthropic_sdk_dart/lib/src/generated/schema/message_batch.dart @@ -0,0 +1,98 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: invalid_annotation_target +part of anthropic_schema; + +// ========================================== +// CLASS: MessageBatch +// ========================================== + +/// A batch of message requests. +@freezed +class MessageBatch with _$MessageBatch { + const MessageBatch._(); + + /// Factory constructor for MessageBatch + const factory MessageBatch({ + /// Unique object identifier for the message batch. + required String id, + + /// RFC 3339 datetime string representing the time at which the Message Batch was created. + @JsonKey(name: 'created_at') required String createdAt, + + /// RFC 3339 datetime string representing the time at which the Message Batch will expire and end processing, which is 24 hours after creation. + @JsonKey(name: 'expires_at') required String expiresAt, + + /// Processing status of the Message Batch. + @JsonKey(name: 'processing_status') + required MessageBatchProcessingStatus processingStatus, + + /// Tallies requests within the Message Batch, categorized by their status. + @JsonKey(name: 'request_counts') + required MessageBatchRequestCounts requestCounts, + + /// URL to a `.jsonl` file containing the results of the Message Batch requests. Specified only once processing ends. + @JsonKey(name: 'results_url', includeIfNull: false) String? resultsUrl, + + /// Object type. For Message Batches, this is always `"message_batch"`. + required MessageBatchType type, + }) = _MessageBatch; + + /// Object construction from a JSON representation + factory MessageBatch.fromJson(Map json) => + _$MessageBatchFromJson(json); + + /// List of all property names of schema + static const List propertyNames = [ + 'id', + 'created_at', + 'expires_at', + 'processing_status', + 'request_counts', + 'results_url', + 'type' + ]; + + /// Perform validations on the schema property values + String? validateSchema() { + return null; + } + + /// Map representation of object (not serialized) + Map toMap() { + return { + 'id': id, + 'created_at': createdAt, + 'expires_at': expiresAt, + 'processing_status': processingStatus, + 'request_counts': requestCounts, + 'results_url': resultsUrl, + 'type': type, + }; + } +} + +// ========================================== +// ENUM: MessageBatchProcessingStatus +// ========================================== + +/// Processing status of the Message Batch. +enum MessageBatchProcessingStatus { + @JsonValue('in_progress') + inProgress, + @JsonValue('canceling') + canceling, + @JsonValue('ended') + ended, +} + +// ========================================== +// ENUM: MessageBatchType +// ========================================== + +/// Object type. For Message Batches, this is always `"message_batch"`. +enum MessageBatchType { + @JsonValue('message_batch') + messageBatch, +} diff --git a/packages/anthropic_sdk_dart/lib/src/generated/schema/message_batch_request_counts.dart b/packages/anthropic_sdk_dart/lib/src/generated/schema/message_batch_request_counts.dart new file mode 100644 index 00000000..496c61ef --- /dev/null +++ b/packages/anthropic_sdk_dart/lib/src/generated/schema/message_batch_request_counts.dart @@ -0,0 +1,62 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: invalid_annotation_target +part of anthropic_schema; + +// ========================================== +// CLASS: MessageBatchRequestCounts +// ========================================== + +/// Tallies requests within the Message Batch, categorized by their status. +@freezed +class MessageBatchRequestCounts with _$MessageBatchRequestCounts { + const MessageBatchRequestCounts._(); + + /// Factory constructor for MessageBatchRequestCounts + const factory MessageBatchRequestCounts({ + /// Number of requests in the Message Batch that are processing. + required int processing, + + /// Number of requests in the Message Batch that have completed successfully. + required int succeeded, + + /// Number of requests in the Message Batch that encountered an error. + required int errored, + + /// Number of requests in the Message Batch that have been canceled. + required int canceled, + + /// Number of requests in the Message Batch that have expired. + required int expired, + }) = _MessageBatchRequestCounts; + + /// Object construction from a JSON representation + factory MessageBatchRequestCounts.fromJson(Map json) => + _$MessageBatchRequestCountsFromJson(json); + + /// List of all property names of schema + static const List propertyNames = [ + 'processing', + 'succeeded', + 'errored', + 'canceled', + 'expired' + ]; + + /// Perform validations on the schema property values + String? validateSchema() { + return null; + } + + /// Map representation of object (not serialized) + Map toMap() { + return { + 'processing': processing, + 'succeeded': succeeded, + 'errored': errored, + 'canceled': canceled, + 'expired': expired, + }; + } +} diff --git a/packages/anthropic_sdk_dart/lib/src/generated/schema/schema.dart b/packages/anthropic_sdk_dart/lib/src/generated/schema/schema.dart index b9d2ef26..d202f758 100644 --- a/packages/anthropic_sdk_dart/lib/src/generated/schema/schema.dart +++ b/packages/anthropic_sdk_dart/lib/src/generated/schema/schema.dart @@ -20,6 +20,10 @@ part 'tool.dart'; part 'image_block_source.dart'; part 'stop_reason.dart'; part 'usage.dart'; +part 'create_message_batch_request.dart'; +part 'batch_message_request.dart'; +part 'message_batch.dart'; +part 'message_batch_request_counts.dart'; part 'message_stream_event_type.dart'; part 'message_delta.dart'; part 'message_delta_usage.dart'; diff --git a/packages/anthropic_sdk_dart/lib/src/generated/schema/schema.freezed.dart b/packages/anthropic_sdk_dart/lib/src/generated/schema/schema.freezed.dart index 0c9d5fd9..fd2449a1 100644 --- a/packages/anthropic_sdk_dart/lib/src/generated/schema/schema.freezed.dart +++ b/packages/anthropic_sdk_dart/lib/src/generated/schema/schema.freezed.dart @@ -3724,6 +3724,1013 @@ abstract class _Usage extends Usage { throw _privateConstructorUsedError; } +CreateMessageBatchRequest _$CreateMessageBatchRequestFromJson( + Map json) { + return _CreateMessageBatchRequest.fromJson(json); +} + +/// @nodoc +mixin _$CreateMessageBatchRequest { + /// List of requests for prompt completion. Each is an individual request to create a Message. + List get requests => throw _privateConstructorUsedError; + + /// Serializes this CreateMessageBatchRequest to a JSON map. + Map toJson() => throw _privateConstructorUsedError; + + /// Create a copy of CreateMessageBatchRequest + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $CreateMessageBatchRequestCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $CreateMessageBatchRequestCopyWith<$Res> { + factory $CreateMessageBatchRequestCopyWith(CreateMessageBatchRequest value, + $Res Function(CreateMessageBatchRequest) then) = + _$CreateMessageBatchRequestCopyWithImpl<$Res, CreateMessageBatchRequest>; + @useResult + $Res call({List requests}); +} + +/// @nodoc +class _$CreateMessageBatchRequestCopyWithImpl<$Res, + $Val extends CreateMessageBatchRequest> + implements $CreateMessageBatchRequestCopyWith<$Res> { + _$CreateMessageBatchRequestCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of CreateMessageBatchRequest + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? requests = null, + }) { + return _then(_value.copyWith( + requests: null == requests + ? _value.requests + : requests // ignore: cast_nullable_to_non_nullable + as List, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$CreateMessageBatchRequestImplCopyWith<$Res> + implements $CreateMessageBatchRequestCopyWith<$Res> { + factory _$$CreateMessageBatchRequestImplCopyWith( + _$CreateMessageBatchRequestImpl value, + $Res Function(_$CreateMessageBatchRequestImpl) then) = + __$$CreateMessageBatchRequestImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({List requests}); +} + +/// @nodoc +class __$$CreateMessageBatchRequestImplCopyWithImpl<$Res> + extends _$CreateMessageBatchRequestCopyWithImpl<$Res, + _$CreateMessageBatchRequestImpl> + implements _$$CreateMessageBatchRequestImplCopyWith<$Res> { + __$$CreateMessageBatchRequestImplCopyWithImpl( + _$CreateMessageBatchRequestImpl _value, + $Res Function(_$CreateMessageBatchRequestImpl) _then) + : super(_value, _then); + + /// Create a copy of CreateMessageBatchRequest + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? requests = null, + }) { + return _then(_$CreateMessageBatchRequestImpl( + requests: null == requests + ? _value._requests + : requests // ignore: cast_nullable_to_non_nullable + as List, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$CreateMessageBatchRequestImpl extends _CreateMessageBatchRequest { + const _$CreateMessageBatchRequestImpl( + {required final List requests}) + : _requests = requests, + super._(); + + factory _$CreateMessageBatchRequestImpl.fromJson(Map json) => + _$$CreateMessageBatchRequestImplFromJson(json); + + /// List of requests for prompt completion. Each is an individual request to create a Message. + final List _requests; + + /// List of requests for prompt completion. Each is an individual request to create a Message. + @override + List get requests { + if (_requests is EqualUnmodifiableListView) return _requests; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_requests); + } + + @override + String toString() { + return 'CreateMessageBatchRequest(requests: $requests)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$CreateMessageBatchRequestImpl && + const DeepCollectionEquality().equals(other._requests, _requests)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => + Object.hash(runtimeType, const DeepCollectionEquality().hash(_requests)); + + /// Create a copy of CreateMessageBatchRequest + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$CreateMessageBatchRequestImplCopyWith<_$CreateMessageBatchRequestImpl> + get copyWith => __$$CreateMessageBatchRequestImplCopyWithImpl< + _$CreateMessageBatchRequestImpl>(this, _$identity); + + @override + Map toJson() { + return _$$CreateMessageBatchRequestImplToJson( + this, + ); + } +} + +abstract class _CreateMessageBatchRequest extends CreateMessageBatchRequest { + const factory _CreateMessageBatchRequest( + {required final List requests}) = + _$CreateMessageBatchRequestImpl; + const _CreateMessageBatchRequest._() : super._(); + + factory _CreateMessageBatchRequest.fromJson(Map json) = + _$CreateMessageBatchRequestImpl.fromJson; + + /// List of requests for prompt completion. Each is an individual request to create a Message. + @override + List get requests; + + /// Create a copy of CreateMessageBatchRequest + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$CreateMessageBatchRequestImplCopyWith<_$CreateMessageBatchRequestImpl> + get copyWith => throw _privateConstructorUsedError; +} + +BatchMessageRequest _$BatchMessageRequestFromJson(Map json) { + return _BatchMessageRequest.fromJson(json); +} + +/// @nodoc +mixin _$BatchMessageRequest { + /// Developer-provided ID created for each request in a Message Batch. Useful for + /// matching results to requests, as results may be given out of request order. + /// + /// Must be unique for each request within the Message Batch. + @JsonKey(name: 'custom_id') + String get customId => throw _privateConstructorUsedError; + + /// The request parameters for creating a message. + CreateMessageRequest get params => throw _privateConstructorUsedError; + + /// Serializes this BatchMessageRequest to a JSON map. + Map toJson() => throw _privateConstructorUsedError; + + /// Create a copy of BatchMessageRequest + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $BatchMessageRequestCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $BatchMessageRequestCopyWith<$Res> { + factory $BatchMessageRequestCopyWith( + BatchMessageRequest value, $Res Function(BatchMessageRequest) then) = + _$BatchMessageRequestCopyWithImpl<$Res, BatchMessageRequest>; + @useResult + $Res call( + {@JsonKey(name: 'custom_id') String customId, + CreateMessageRequest params}); + + $CreateMessageRequestCopyWith<$Res> get params; +} + +/// @nodoc +class _$BatchMessageRequestCopyWithImpl<$Res, $Val extends BatchMessageRequest> + implements $BatchMessageRequestCopyWith<$Res> { + _$BatchMessageRequestCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of BatchMessageRequest + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? customId = null, + Object? params = null, + }) { + return _then(_value.copyWith( + customId: null == customId + ? _value.customId + : customId // ignore: cast_nullable_to_non_nullable + as String, + params: null == params + ? _value.params + : params // ignore: cast_nullable_to_non_nullable + as CreateMessageRequest, + ) as $Val); + } + + /// Create a copy of BatchMessageRequest + /// with the given fields replaced by the non-null parameter values. + @override + @pragma('vm:prefer-inline') + $CreateMessageRequestCopyWith<$Res> get params { + return $CreateMessageRequestCopyWith<$Res>(_value.params, (value) { + return _then(_value.copyWith(params: value) as $Val); + }); + } +} + +/// @nodoc +abstract class _$$BatchMessageRequestImplCopyWith<$Res> + implements $BatchMessageRequestCopyWith<$Res> { + factory _$$BatchMessageRequestImplCopyWith(_$BatchMessageRequestImpl value, + $Res Function(_$BatchMessageRequestImpl) then) = + __$$BatchMessageRequestImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {@JsonKey(name: 'custom_id') String customId, + CreateMessageRequest params}); + + @override + $CreateMessageRequestCopyWith<$Res> get params; +} + +/// @nodoc +class __$$BatchMessageRequestImplCopyWithImpl<$Res> + extends _$BatchMessageRequestCopyWithImpl<$Res, _$BatchMessageRequestImpl> + implements _$$BatchMessageRequestImplCopyWith<$Res> { + __$$BatchMessageRequestImplCopyWithImpl(_$BatchMessageRequestImpl _value, + $Res Function(_$BatchMessageRequestImpl) _then) + : super(_value, _then); + + /// Create a copy of BatchMessageRequest + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? customId = null, + Object? params = null, + }) { + return _then(_$BatchMessageRequestImpl( + customId: null == customId + ? _value.customId + : customId // ignore: cast_nullable_to_non_nullable + as String, + params: null == params + ? _value.params + : params // ignore: cast_nullable_to_non_nullable + as CreateMessageRequest, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$BatchMessageRequestImpl extends _BatchMessageRequest { + const _$BatchMessageRequestImpl( + {@JsonKey(name: 'custom_id') required this.customId, + required this.params}) + : super._(); + + factory _$BatchMessageRequestImpl.fromJson(Map json) => + _$$BatchMessageRequestImplFromJson(json); + + /// Developer-provided ID created for each request in a Message Batch. Useful for + /// matching results to requests, as results may be given out of request order. + /// + /// Must be unique for each request within the Message Batch. + @override + @JsonKey(name: 'custom_id') + final String customId; + + /// The request parameters for creating a message. + @override + final CreateMessageRequest params; + + @override + String toString() { + return 'BatchMessageRequest(customId: $customId, params: $params)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$BatchMessageRequestImpl && + (identical(other.customId, customId) || + other.customId == customId) && + (identical(other.params, params) || other.params == params)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash(runtimeType, customId, params); + + /// Create a copy of BatchMessageRequest + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$BatchMessageRequestImplCopyWith<_$BatchMessageRequestImpl> get copyWith => + __$$BatchMessageRequestImplCopyWithImpl<_$BatchMessageRequestImpl>( + this, _$identity); + + @override + Map toJson() { + return _$$BatchMessageRequestImplToJson( + this, + ); + } +} + +abstract class _BatchMessageRequest extends BatchMessageRequest { + const factory _BatchMessageRequest( + {@JsonKey(name: 'custom_id') required final String customId, + required final CreateMessageRequest params}) = _$BatchMessageRequestImpl; + const _BatchMessageRequest._() : super._(); + + factory _BatchMessageRequest.fromJson(Map json) = + _$BatchMessageRequestImpl.fromJson; + + /// Developer-provided ID created for each request in a Message Batch. Useful for + /// matching results to requests, as results may be given out of request order. + /// + /// Must be unique for each request within the Message Batch. + @override + @JsonKey(name: 'custom_id') + String get customId; + + /// The request parameters for creating a message. + @override + CreateMessageRequest get params; + + /// Create a copy of BatchMessageRequest + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$BatchMessageRequestImplCopyWith<_$BatchMessageRequestImpl> get copyWith => + throw _privateConstructorUsedError; +} + +MessageBatch _$MessageBatchFromJson(Map json) { + return _MessageBatch.fromJson(json); +} + +/// @nodoc +mixin _$MessageBatch { + /// Unique object identifier for the message batch. + String get id => throw _privateConstructorUsedError; + + /// RFC 3339 datetime string representing the time at which the Message Batch was created. + @JsonKey(name: 'created_at') + String get createdAt => throw _privateConstructorUsedError; + + /// RFC 3339 datetime string representing the time at which the Message Batch will expire and end processing, which is 24 hours after creation. + @JsonKey(name: 'expires_at') + String get expiresAt => throw _privateConstructorUsedError; + + /// Processing status of the Message Batch. + @JsonKey(name: 'processing_status') + MessageBatchProcessingStatus get processingStatus => + throw _privateConstructorUsedError; + + /// Tallies requests within the Message Batch, categorized by their status. + @JsonKey(name: 'request_counts') + MessageBatchRequestCounts get requestCounts => + throw _privateConstructorUsedError; + + /// URL to a `.jsonl` file containing the results of the Message Batch requests. Specified only once processing ends. + @JsonKey(name: 'results_url', includeIfNull: false) + String? get resultsUrl => throw _privateConstructorUsedError; + + /// Object type. For Message Batches, this is always `"message_batch"`. + MessageBatchType get type => throw _privateConstructorUsedError; + + /// Serializes this MessageBatch to a JSON map. + Map toJson() => throw _privateConstructorUsedError; + + /// Create a copy of MessageBatch + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $MessageBatchCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $MessageBatchCopyWith<$Res> { + factory $MessageBatchCopyWith( + MessageBatch value, $Res Function(MessageBatch) then) = + _$MessageBatchCopyWithImpl<$Res, MessageBatch>; + @useResult + $Res call( + {String id, + @JsonKey(name: 'created_at') String createdAt, + @JsonKey(name: 'expires_at') String expiresAt, + @JsonKey(name: 'processing_status') + MessageBatchProcessingStatus processingStatus, + @JsonKey(name: 'request_counts') MessageBatchRequestCounts requestCounts, + @JsonKey(name: 'results_url', includeIfNull: false) String? resultsUrl, + MessageBatchType type}); + + $MessageBatchRequestCountsCopyWith<$Res> get requestCounts; +} + +/// @nodoc +class _$MessageBatchCopyWithImpl<$Res, $Val extends MessageBatch> + implements $MessageBatchCopyWith<$Res> { + _$MessageBatchCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of MessageBatch + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? createdAt = null, + Object? expiresAt = null, + Object? processingStatus = null, + Object? requestCounts = null, + Object? resultsUrl = freezed, + Object? type = null, + }) { + return _then(_value.copyWith( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as String, + createdAt: null == createdAt + ? _value.createdAt + : createdAt // ignore: cast_nullable_to_non_nullable + as String, + expiresAt: null == expiresAt + ? _value.expiresAt + : expiresAt // ignore: cast_nullable_to_non_nullable + as String, + processingStatus: null == processingStatus + ? _value.processingStatus + : processingStatus // ignore: cast_nullable_to_non_nullable + as MessageBatchProcessingStatus, + requestCounts: null == requestCounts + ? _value.requestCounts + : requestCounts // ignore: cast_nullable_to_non_nullable + as MessageBatchRequestCounts, + resultsUrl: freezed == resultsUrl + ? _value.resultsUrl + : resultsUrl // ignore: cast_nullable_to_non_nullable + as String?, + type: null == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as MessageBatchType, + ) as $Val); + } + + /// Create a copy of MessageBatch + /// with the given fields replaced by the non-null parameter values. + @override + @pragma('vm:prefer-inline') + $MessageBatchRequestCountsCopyWith<$Res> get requestCounts { + return $MessageBatchRequestCountsCopyWith<$Res>(_value.requestCounts, + (value) { + return _then(_value.copyWith(requestCounts: value) as $Val); + }); + } +} + +/// @nodoc +abstract class _$$MessageBatchImplCopyWith<$Res> + implements $MessageBatchCopyWith<$Res> { + factory _$$MessageBatchImplCopyWith( + _$MessageBatchImpl value, $Res Function(_$MessageBatchImpl) then) = + __$$MessageBatchImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {String id, + @JsonKey(name: 'created_at') String createdAt, + @JsonKey(name: 'expires_at') String expiresAt, + @JsonKey(name: 'processing_status') + MessageBatchProcessingStatus processingStatus, + @JsonKey(name: 'request_counts') MessageBatchRequestCounts requestCounts, + @JsonKey(name: 'results_url', includeIfNull: false) String? resultsUrl, + MessageBatchType type}); + + @override + $MessageBatchRequestCountsCopyWith<$Res> get requestCounts; +} + +/// @nodoc +class __$$MessageBatchImplCopyWithImpl<$Res> + extends _$MessageBatchCopyWithImpl<$Res, _$MessageBatchImpl> + implements _$$MessageBatchImplCopyWith<$Res> { + __$$MessageBatchImplCopyWithImpl( + _$MessageBatchImpl _value, $Res Function(_$MessageBatchImpl) _then) + : super(_value, _then); + + /// Create a copy of MessageBatch + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? createdAt = null, + Object? expiresAt = null, + Object? processingStatus = null, + Object? requestCounts = null, + Object? resultsUrl = freezed, + Object? type = null, + }) { + return _then(_$MessageBatchImpl( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as String, + createdAt: null == createdAt + ? _value.createdAt + : createdAt // ignore: cast_nullable_to_non_nullable + as String, + expiresAt: null == expiresAt + ? _value.expiresAt + : expiresAt // ignore: cast_nullable_to_non_nullable + as String, + processingStatus: null == processingStatus + ? _value.processingStatus + : processingStatus // ignore: cast_nullable_to_non_nullable + as MessageBatchProcessingStatus, + requestCounts: null == requestCounts + ? _value.requestCounts + : requestCounts // ignore: cast_nullable_to_non_nullable + as MessageBatchRequestCounts, + resultsUrl: freezed == resultsUrl + ? _value.resultsUrl + : resultsUrl // ignore: cast_nullable_to_non_nullable + as String?, + type: null == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as MessageBatchType, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$MessageBatchImpl extends _MessageBatch { + const _$MessageBatchImpl( + {required this.id, + @JsonKey(name: 'created_at') required this.createdAt, + @JsonKey(name: 'expires_at') required this.expiresAt, + @JsonKey(name: 'processing_status') required this.processingStatus, + @JsonKey(name: 'request_counts') required this.requestCounts, + @JsonKey(name: 'results_url', includeIfNull: false) this.resultsUrl, + required this.type}) + : super._(); + + factory _$MessageBatchImpl.fromJson(Map json) => + _$$MessageBatchImplFromJson(json); + + /// Unique object identifier for the message batch. + @override + final String id; + + /// RFC 3339 datetime string representing the time at which the Message Batch was created. + @override + @JsonKey(name: 'created_at') + final String createdAt; + + /// RFC 3339 datetime string representing the time at which the Message Batch will expire and end processing, which is 24 hours after creation. + @override + @JsonKey(name: 'expires_at') + final String expiresAt; + + /// Processing status of the Message Batch. + @override + @JsonKey(name: 'processing_status') + final MessageBatchProcessingStatus processingStatus; + + /// Tallies requests within the Message Batch, categorized by their status. + @override + @JsonKey(name: 'request_counts') + final MessageBatchRequestCounts requestCounts; + + /// URL to a `.jsonl` file containing the results of the Message Batch requests. Specified only once processing ends. + @override + @JsonKey(name: 'results_url', includeIfNull: false) + final String? resultsUrl; + + /// Object type. For Message Batches, this is always `"message_batch"`. + @override + final MessageBatchType type; + + @override + String toString() { + return 'MessageBatch(id: $id, createdAt: $createdAt, expiresAt: $expiresAt, processingStatus: $processingStatus, requestCounts: $requestCounts, resultsUrl: $resultsUrl, type: $type)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$MessageBatchImpl && + (identical(other.id, id) || other.id == id) && + (identical(other.createdAt, createdAt) || + other.createdAt == createdAt) && + (identical(other.expiresAt, expiresAt) || + other.expiresAt == expiresAt) && + (identical(other.processingStatus, processingStatus) || + other.processingStatus == processingStatus) && + (identical(other.requestCounts, requestCounts) || + other.requestCounts == requestCounts) && + (identical(other.resultsUrl, resultsUrl) || + other.resultsUrl == resultsUrl) && + (identical(other.type, type) || other.type == type)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash(runtimeType, id, createdAt, expiresAt, + processingStatus, requestCounts, resultsUrl, type); + + /// Create a copy of MessageBatch + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$MessageBatchImplCopyWith<_$MessageBatchImpl> get copyWith => + __$$MessageBatchImplCopyWithImpl<_$MessageBatchImpl>(this, _$identity); + + @override + Map toJson() { + return _$$MessageBatchImplToJson( + this, + ); + } +} + +abstract class _MessageBatch extends MessageBatch { + const factory _MessageBatch( + {required final String id, + @JsonKey(name: 'created_at') required final String createdAt, + @JsonKey(name: 'expires_at') required final String expiresAt, + @JsonKey(name: 'processing_status') + required final MessageBatchProcessingStatus processingStatus, + @JsonKey(name: 'request_counts') + required final MessageBatchRequestCounts requestCounts, + @JsonKey(name: 'results_url', includeIfNull: false) + final String? resultsUrl, + required final MessageBatchType type}) = _$MessageBatchImpl; + const _MessageBatch._() : super._(); + + factory _MessageBatch.fromJson(Map json) = + _$MessageBatchImpl.fromJson; + + /// Unique object identifier for the message batch. + @override + String get id; + + /// RFC 3339 datetime string representing the time at which the Message Batch was created. + @override + @JsonKey(name: 'created_at') + String get createdAt; + + /// RFC 3339 datetime string representing the time at which the Message Batch will expire and end processing, which is 24 hours after creation. + @override + @JsonKey(name: 'expires_at') + String get expiresAt; + + /// Processing status of the Message Batch. + @override + @JsonKey(name: 'processing_status') + MessageBatchProcessingStatus get processingStatus; + + /// Tallies requests within the Message Batch, categorized by their status. + @override + @JsonKey(name: 'request_counts') + MessageBatchRequestCounts get requestCounts; + + /// URL to a `.jsonl` file containing the results of the Message Batch requests. Specified only once processing ends. + @override + @JsonKey(name: 'results_url', includeIfNull: false) + String? get resultsUrl; + + /// Object type. For Message Batches, this is always `"message_batch"`. + @override + MessageBatchType get type; + + /// Create a copy of MessageBatch + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$MessageBatchImplCopyWith<_$MessageBatchImpl> get copyWith => + throw _privateConstructorUsedError; +} + +MessageBatchRequestCounts _$MessageBatchRequestCountsFromJson( + Map json) { + return _MessageBatchRequestCounts.fromJson(json); +} + +/// @nodoc +mixin _$MessageBatchRequestCounts { + /// Number of requests in the Message Batch that are processing. + int get processing => throw _privateConstructorUsedError; + + /// Number of requests in the Message Batch that have completed successfully. + int get succeeded => throw _privateConstructorUsedError; + + /// Number of requests in the Message Batch that encountered an error. + int get errored => throw _privateConstructorUsedError; + + /// Number of requests in the Message Batch that have been canceled. + int get canceled => throw _privateConstructorUsedError; + + /// Number of requests in the Message Batch that have expired. + int get expired => throw _privateConstructorUsedError; + + /// Serializes this MessageBatchRequestCounts to a JSON map. + Map toJson() => throw _privateConstructorUsedError; + + /// Create a copy of MessageBatchRequestCounts + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $MessageBatchRequestCountsCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $MessageBatchRequestCountsCopyWith<$Res> { + factory $MessageBatchRequestCountsCopyWith(MessageBatchRequestCounts value, + $Res Function(MessageBatchRequestCounts) then) = + _$MessageBatchRequestCountsCopyWithImpl<$Res, MessageBatchRequestCounts>; + @useResult + $Res call( + {int processing, int succeeded, int errored, int canceled, int expired}); +} + +/// @nodoc +class _$MessageBatchRequestCountsCopyWithImpl<$Res, + $Val extends MessageBatchRequestCounts> + implements $MessageBatchRequestCountsCopyWith<$Res> { + _$MessageBatchRequestCountsCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of MessageBatchRequestCounts + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? processing = null, + Object? succeeded = null, + Object? errored = null, + Object? canceled = null, + Object? expired = null, + }) { + return _then(_value.copyWith( + processing: null == processing + ? _value.processing + : processing // ignore: cast_nullable_to_non_nullable + as int, + succeeded: null == succeeded + ? _value.succeeded + : succeeded // ignore: cast_nullable_to_non_nullable + as int, + errored: null == errored + ? _value.errored + : errored // ignore: cast_nullable_to_non_nullable + as int, + canceled: null == canceled + ? _value.canceled + : canceled // ignore: cast_nullable_to_non_nullable + as int, + expired: null == expired + ? _value.expired + : expired // ignore: cast_nullable_to_non_nullable + as int, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$MessageBatchRequestCountsImplCopyWith<$Res> + implements $MessageBatchRequestCountsCopyWith<$Res> { + factory _$$MessageBatchRequestCountsImplCopyWith( + _$MessageBatchRequestCountsImpl value, + $Res Function(_$MessageBatchRequestCountsImpl) then) = + __$$MessageBatchRequestCountsImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {int processing, int succeeded, int errored, int canceled, int expired}); +} + +/// @nodoc +class __$$MessageBatchRequestCountsImplCopyWithImpl<$Res> + extends _$MessageBatchRequestCountsCopyWithImpl<$Res, + _$MessageBatchRequestCountsImpl> + implements _$$MessageBatchRequestCountsImplCopyWith<$Res> { + __$$MessageBatchRequestCountsImplCopyWithImpl( + _$MessageBatchRequestCountsImpl _value, + $Res Function(_$MessageBatchRequestCountsImpl) _then) + : super(_value, _then); + + /// Create a copy of MessageBatchRequestCounts + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? processing = null, + Object? succeeded = null, + Object? errored = null, + Object? canceled = null, + Object? expired = null, + }) { + return _then(_$MessageBatchRequestCountsImpl( + processing: null == processing + ? _value.processing + : processing // ignore: cast_nullable_to_non_nullable + as int, + succeeded: null == succeeded + ? _value.succeeded + : succeeded // ignore: cast_nullable_to_non_nullable + as int, + errored: null == errored + ? _value.errored + : errored // ignore: cast_nullable_to_non_nullable + as int, + canceled: null == canceled + ? _value.canceled + : canceled // ignore: cast_nullable_to_non_nullable + as int, + expired: null == expired + ? _value.expired + : expired // ignore: cast_nullable_to_non_nullable + as int, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$MessageBatchRequestCountsImpl extends _MessageBatchRequestCounts { + const _$MessageBatchRequestCountsImpl( + {required this.processing, + required this.succeeded, + required this.errored, + required this.canceled, + required this.expired}) + : super._(); + + factory _$MessageBatchRequestCountsImpl.fromJson(Map json) => + _$$MessageBatchRequestCountsImplFromJson(json); + + /// Number of requests in the Message Batch that are processing. + @override + final int processing; + + /// Number of requests in the Message Batch that have completed successfully. + @override + final int succeeded; + + /// Number of requests in the Message Batch that encountered an error. + @override + final int errored; + + /// Number of requests in the Message Batch that have been canceled. + @override + final int canceled; + + /// Number of requests in the Message Batch that have expired. + @override + final int expired; + + @override + String toString() { + return 'MessageBatchRequestCounts(processing: $processing, succeeded: $succeeded, errored: $errored, canceled: $canceled, expired: $expired)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$MessageBatchRequestCountsImpl && + (identical(other.processing, processing) || + other.processing == processing) && + (identical(other.succeeded, succeeded) || + other.succeeded == succeeded) && + (identical(other.errored, errored) || other.errored == errored) && + (identical(other.canceled, canceled) || + other.canceled == canceled) && + (identical(other.expired, expired) || other.expired == expired)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash( + runtimeType, processing, succeeded, errored, canceled, expired); + + /// Create a copy of MessageBatchRequestCounts + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$MessageBatchRequestCountsImplCopyWith<_$MessageBatchRequestCountsImpl> + get copyWith => __$$MessageBatchRequestCountsImplCopyWithImpl< + _$MessageBatchRequestCountsImpl>(this, _$identity); + + @override + Map toJson() { + return _$$MessageBatchRequestCountsImplToJson( + this, + ); + } +} + +abstract class _MessageBatchRequestCounts extends MessageBatchRequestCounts { + const factory _MessageBatchRequestCounts( + {required final int processing, + required final int succeeded, + required final int errored, + required final int canceled, + required final int expired}) = _$MessageBatchRequestCountsImpl; + const _MessageBatchRequestCounts._() : super._(); + + factory _MessageBatchRequestCounts.fromJson(Map json) = + _$MessageBatchRequestCountsImpl.fromJson; + + /// Number of requests in the Message Batch that are processing. + @override + int get processing; + + /// Number of requests in the Message Batch that have completed successfully. + @override + int get succeeded; + + /// Number of requests in the Message Batch that encountered an error. + @override + int get errored; + + /// Number of requests in the Message Batch that have been canceled. + @override + int get canceled; + + /// Number of requests in the Message Batch that have expired. + @override + int get expired; + + /// Create a copy of MessageBatchRequestCounts + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$MessageBatchRequestCountsImplCopyWith<_$MessageBatchRequestCountsImpl> + get copyWith => throw _privateConstructorUsedError; +} + MessageDelta _$MessageDeltaFromJson(Map json) { return _MessageDelta.fromJson(json); } @@ -4781,10 +5788,10 @@ class _$ToolUseBlockImpl extends ToolUseBlock { @override final String name; - /// An object containing the input being passed to the tool, conforming to the tool’s `input_schema`. + /// An object containing the input being passed to the tool, conforming to the tool's `input_schema`. final Map _input; - /// An object containing the input being passed to the tool, conforming to the tool’s `input_schema`. + /// An object containing the input being passed to the tool, conforming to the tool's `input_schema`. @override Map get input { if (_input is EqualUnmodifiableMapView) return _input; @@ -4947,7 +5954,7 @@ abstract class ToolUseBlock extends Block { /// The name of the tool being used. String get name; - /// An object containing the input being passed to the tool, conforming to the tool’s `input_schema`. + /// An object containing the input being passed to the tool, conforming to the tool's `input_schema`. Map get input; /// The type of content block. diff --git a/packages/anthropic_sdk_dart/lib/src/generated/schema/schema.g.dart b/packages/anthropic_sdk_dart/lib/src/generated/schema/schema.g.dart index 686e3527..5d6f5e8a 100644 --- a/packages/anthropic_sdk_dart/lib/src/generated/schema/schema.g.dart +++ b/packages/anthropic_sdk_dart/lib/src/generated/schema/schema.g.dart @@ -284,6 +284,99 @@ Map _$$UsageImplToJson(_$UsageImpl instance) => 'output_tokens': instance.outputTokens, }; +_$CreateMessageBatchRequestImpl _$$CreateMessageBatchRequestImplFromJson( + Map json) => + _$CreateMessageBatchRequestImpl( + requests: (json['requests'] as List) + .map((e) => BatchMessageRequest.fromJson(e as Map)) + .toList(), + ); + +Map _$$CreateMessageBatchRequestImplToJson( + _$CreateMessageBatchRequestImpl instance) => + { + 'requests': instance.requests.map((e) => e.toJson()).toList(), + }; + +_$BatchMessageRequestImpl _$$BatchMessageRequestImplFromJson( + Map json) => + _$BatchMessageRequestImpl( + customId: json['custom_id'] as String, + params: + CreateMessageRequest.fromJson(json['params'] as Map), + ); + +Map _$$BatchMessageRequestImplToJson( + _$BatchMessageRequestImpl instance) => + { + 'custom_id': instance.customId, + 'params': instance.params.toJson(), + }; + +_$MessageBatchImpl _$$MessageBatchImplFromJson(Map json) => + _$MessageBatchImpl( + id: json['id'] as String, + createdAt: json['created_at'] as String, + expiresAt: json['expires_at'] as String, + processingStatus: $enumDecode( + _$MessageBatchProcessingStatusEnumMap, json['processing_status']), + requestCounts: MessageBatchRequestCounts.fromJson( + json['request_counts'] as Map), + resultsUrl: json['results_url'] as String?, + type: $enumDecode(_$MessageBatchTypeEnumMap, json['type']), + ); + +Map _$$MessageBatchImplToJson(_$MessageBatchImpl instance) { + final val = { + 'id': instance.id, + 'created_at': instance.createdAt, + 'expires_at': instance.expiresAt, + 'processing_status': + _$MessageBatchProcessingStatusEnumMap[instance.processingStatus]!, + 'request_counts': instance.requestCounts.toJson(), + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('results_url', instance.resultsUrl); + val['type'] = _$MessageBatchTypeEnumMap[instance.type]!; + return val; +} + +const _$MessageBatchProcessingStatusEnumMap = { + MessageBatchProcessingStatus.inProgress: 'in_progress', + MessageBatchProcessingStatus.canceling: 'canceling', + MessageBatchProcessingStatus.ended: 'ended', +}; + +const _$MessageBatchTypeEnumMap = { + MessageBatchType.messageBatch: 'message_batch', +}; + +_$MessageBatchRequestCountsImpl _$$MessageBatchRequestCountsImplFromJson( + Map json) => + _$MessageBatchRequestCountsImpl( + processing: (json['processing'] as num).toInt(), + succeeded: (json['succeeded'] as num).toInt(), + errored: (json['errored'] as num).toInt(), + canceled: (json['canceled'] as num).toInt(), + expired: (json['expired'] as num).toInt(), + ); + +Map _$$MessageBatchRequestCountsImplToJson( + _$MessageBatchRequestCountsImpl instance) => + { + 'processing': instance.processing, + 'succeeded': instance.succeeded, + 'errored': instance.errored, + 'canceled': instance.canceled, + 'expired': instance.expired, + }; + _$MessageDeltaImpl _$$MessageDeltaImplFromJson(Map json) => _$MessageDeltaImpl( stopReason: $enumDecodeNullable(_$StopReasonEnumMap, json['stop_reason'], diff --git a/packages/anthropic_sdk_dart/oas/anthropic_openapi_curated.yaml b/packages/anthropic_sdk_dart/oas/anthropic_openapi_curated.yaml index 214edd03..fececadf 100644 --- a/packages/anthropic_sdk_dart/oas/anthropic_openapi_curated.yaml +++ b/packages/anthropic_sdk_dart/oas/anthropic_openapi_curated.yaml @@ -38,6 +38,51 @@ paths: application/json: schema: $ref: "#/components/schemas/Message" + /messages/batches: + post: + operationId: createMessageBatch + tags: + - Messages + summary: Create a Message Batch + description: Send a batch of Message creation requests. + requestBody: + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/CreateMessageBatchRequest" + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/MessageBatch" + /messages/batches/{id}: + get: + operationId: retrieveMessageBatch + tags: + - Messages + summary: Retrieve a Message Batch + description: | + This endpoint is idempotent and can be used to poll for Message Batch + completion. To access the results of a Message Batch, make a request to the + `results_url` field in the response. + parameters: + - name: id + in: path + required: true + schema: + type: string + description: The ID of the message batch to retrieve. + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/MessageBatch" + components: securitySchemes: ApiKeyAuth: @@ -522,7 +567,7 @@ components: example: get_weather input: type: object - description: An object containing the input being passed to the tool, conforming to the tool’s `input_schema`. + description: An object containing the input being passed to the tool, conforming to the tool's `input_schema`. additionalProperties: true type: type: string @@ -605,6 +650,98 @@ components: required: - input_tokens - output_tokens + CreateMessageBatchRequest: + type: object + description: The request parameters for creating a message batch. + properties: + requests: + type: array + description: List of requests for prompt completion. Each is an individual request to create a Message. + items: + $ref: "#/components/schemas/BatchMessageRequest" + required: + - requests + BatchMessageRequest: + type: object + description: An individual message request within a batch. + properties: + custom_id: + type: string + description: | + Developer-provided ID created for each request in a Message Batch. Useful for + matching results to requests, as results may be given out of request order. + + Must be unique for each request within the Message Batch. + params: + $ref: "#/components/schemas/CreateMessageRequest" + required: + - custom_id + - params + MessageBatch: + type: object + description: A batch of message requests. + properties: + id: + type: string + description: Unique object identifier for the message batch. + created_at: + type: string + format: date-time + description: RFC 3339 datetime string representing the time at which the Message Batch was created. + expires_at: + type: string + format: date-time + description: RFC 3339 datetime string representing the time at which the Message Batch will expire and end processing, which is 24 hours after creation. + processing_status: + type: string + enum: + - in_progress + - canceling + - ended + description: Processing status of the Message Batch. + request_counts: + $ref: "#/components/schemas/MessageBatchRequestCounts" + results_url: + type: string + nullable: true + description: URL to a `.jsonl` file containing the results of the Message Batch requests. Specified only once processing ends. + type: + type: string + enum: + - message_batch + description: Object type. For Message Batches, this is always `"message_batch"`. + required: + - id + - created_at + - expires_at + - processing_status + - request_counts + - type + MessageBatchRequestCounts: + type: object + description: Tallies requests within the Message Batch, categorized by their status. + properties: + processing: + type: integer + description: Number of requests in the Message Batch that are processing. + succeeded: + type: integer + description: Number of requests in the Message Batch that have completed successfully. + errored: + type: integer + description: Number of requests in the Message Batch that encountered an error. + canceled: + type: integer + description: Number of requests in the Message Batch that have been canceled. + expired: + type: integer + description: Number of requests in the Message Batch that have expired. + required: + - processing + - succeeded + - errored + - canceled + - expired MessageStreamEvent: type: object description: A event in a streaming conversation. diff --git a/packages/anthropic_sdk_dart/test/messages_test.dart b/packages/anthropic_sdk_dart/test/messages_test.dart index 782061b0..6eaac1b5 100644 --- a/packages/anthropic_sdk_dart/test/messages_test.dart +++ b/packages/anthropic_sdk_dart/test/messages_test.dart @@ -313,5 +313,67 @@ void main() { expect(input['location'], contains('Boston')); expect(input['unit'], 'celsius'); }); + + test('Test createMessageBatch API', + skip: true, timeout: const Timeout(Duration(minutes: 5)), () async { + const batchRequest = CreateMessageBatchRequest( + requests: [ + BatchMessageRequest( + customId: 'request1', + params: CreateMessageRequest( + model: Model.model(Models.claudeInstant12), + temperature: 0, + maxTokens: 1024, + system: + 'You are a helpful assistant that replies only with numbers in order without any spaces, commas or additional explanations.', + messages: [ + Message( + role: MessageRole.user, + content: MessageContent.text( + 'List the numbers from 1 to 9 in order.', + ), + ), + ], + ), + ), + BatchMessageRequest( + customId: 'request2', + params: CreateMessageRequest( + model: Model.model(Models.claudeInstant12), + temperature: 0, + maxTokens: 1024, + system: + 'You are a helpful assistant that replies only with numbers in order without any spaces, commas or additional explanations.', + messages: [ + Message( + role: MessageRole.user, + content: MessageContent.text( + 'List the numbers from 10 to 19 in order.', + ), + ), + ], + ), + ), + ], + ); + + var batch = await client.createMessageBatch(request: batchRequest); + expect(batch.id, isNotEmpty); + expect(batch.createdAt, isNotEmpty); + expect(batch.expiresAt, isNotEmpty); + expect(batch.processingStatus, MessageBatchProcessingStatus.inProgress); + expect(batch.requestCounts.processing, 2); + expect(batch.type, MessageBatchType.messageBatch); + + do { + await Future.delayed(const Duration(seconds: 5)); + batch = await client.retrieveMessageBatch(id: batch.id); + } while ( + batch.processingStatus == MessageBatchProcessingStatus.inProgress); + + batch = await client.retrieveMessageBatch(id: batch.id); + expect(batch.processingStatus, MessageBatchProcessingStatus.ended); + expect(batch.resultsUrl, isNotEmpty); + }); }); }