Skip to content

Commit

Permalink
feat: Support chunking strategy in file_search tool in openai_dart (d…
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmigloz authored and KennethKnudsen97 committed Oct 1, 2024
1 parent 3bc788d commit 31106fe
Show file tree
Hide file tree
Showing 13 changed files with 2,088 additions and 47 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: invalid_annotation_target
part of open_a_i_schema;

// ==========================================
// CLASS: ChunkingStrategyRequestParam
// ==========================================

/// The chunking strategy used to chunk the file(s). If not set, will use the `auto` strategy.
@Freezed(unionKey: 'type', unionValueCase: FreezedUnionCase.snake)
sealed class ChunkingStrategyRequestParam with _$ChunkingStrategyRequestParam {
const ChunkingStrategyRequestParam._();

// ------------------------------------------
// UNION: AutoChunkingStrategyRequestParam
// ------------------------------------------

/// Auto Chunking Strategy, the default strategy. This strategy currently uses a `max_chunk_size_tokens` of `800`
/// and `chunk_overlap_tokens` of `400`.
const factory ChunkingStrategyRequestParam.auto({
/// Always `auto`.
required String type,
}) = AutoChunkingStrategyRequestParam;

// ------------------------------------------
// UNION: StaticChunkingStrategyRequestParam
// ------------------------------------------

/// Static chunking strategy
const factory ChunkingStrategyRequestParam.static({
/// Always `static`.
required String type,

/// Static chunking strategy
required StaticChunkingStrategy static,
}) = StaticChunkingStrategyRequestParam;

/// Object construction from a JSON representation
factory ChunkingStrategyRequestParam.fromJson(Map<String, dynamic> json) =>
_$ChunkingStrategyRequestParamFromJson(json);
}

// ==========================================
// ENUM: ChunkingStrategyRequestParamEnumType
// ==========================================

enum ChunkingStrategyRequestParamEnumType {
@JsonValue('auto')
auto,
@JsonValue('static')
static,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: invalid_annotation_target
part of open_a_i_schema;

// ==========================================
// CLASS: ChunkingStrategyResponseParam
// ==========================================

/// The chunking strategy used to chunk the file(s).
@Freezed(unionKey: 'type', unionValueCase: FreezedUnionCase.snake)
sealed class ChunkingStrategyResponseParam
with _$ChunkingStrategyResponseParam {
const ChunkingStrategyResponseParam._();

// ------------------------------------------
// UNION: StaticChunkingStrategyResponseParam
// ------------------------------------------

/// Static Chunking Strategy.
const factory ChunkingStrategyResponseParam.static({
/// Always `static`.
required String type,

/// Static chunking strategy
required StaticChunkingStrategy static,
}) = StaticChunkingStrategyResponseParam;

// ------------------------------------------
// UNION: OtherChunkingStrategyResponseParam
// ------------------------------------------

/// Other Chunking Strategy. This is returned when the chunking strategy is unknown. Typically, this is because
/// the file was indexed before the `chunking_strategy` concept was introduced in the API.
const factory ChunkingStrategyResponseParam.other({
/// Always `other`.
required String type,
}) = OtherChunkingStrategyResponseParam;

/// Object construction from a JSON representation
factory ChunkingStrategyResponseParam.fromJson(Map<String, dynamic> json) =>
_$ChunkingStrategyResponseParamFromJson(json);
}

// ==========================================
// ENUM: ChunkingStrategyResponseParamEnumType
// ==========================================

enum ChunkingStrategyResponseParamEnumType {
@JsonValue('static')
static,
@JsonValue('other')
other,
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ class CreateVectorStoreFileBatchRequest
const factory CreateVectorStoreFileBatchRequest({
/// A list of [File](https://platform.openai.com/docs/api-reference/files) IDs that the vector store should use. Useful for tools like `file_search` that can access files.
@JsonKey(name: 'file_ids') required List<String> fileIds,

/// The chunking strategy used to chunk the file(s). If not set, will use the `auto` strategy.
/// Any of: [AutoChunkingStrategyRequestParam], [StaticChunkingStrategyRequestParam]
@JsonKey(name: 'chunking_strategy', includeIfNull: false)
ChunkingStrategyRequestParam? chunkingStrategy,
}) = _CreateVectorStoreFileBatchRequest;

/// Object construction from a JSON representation
Expand All @@ -26,7 +31,7 @@ class CreateVectorStoreFileBatchRequest
_$CreateVectorStoreFileBatchRequestFromJson(json);

/// List of all property names of schema
static const List<String> propertyNames = ['file_ids'];
static const List<String> propertyNames = ['file_ids', 'chunking_strategy'];

/// Perform validations on the schema property values
String? validateSchema() {
Expand All @@ -37,6 +42,7 @@ class CreateVectorStoreFileBatchRequest
Map<String, dynamic> toMap() {
return {
'file_ids': fileIds,
'chunking_strategy': chunkingStrategy,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@ class CreateVectorStoreFileRequest with _$CreateVectorStoreFileRequest {
const factory CreateVectorStoreFileRequest({
/// A [File](https://platform.openai.com/docs/api-reference/files) ID that the vector store should use. Useful for tools like `file_search` that can access files.
@JsonKey(name: 'file_id') required String fileId,

/// The chunking strategy used to chunk the file(s). If not set, will use the `auto` strategy.
/// Any of: [AutoChunkingStrategyRequestParam], [StaticChunkingStrategyRequestParam]
@JsonKey(name: 'chunking_strategy', includeIfNull: false)
ChunkingStrategyRequestParam? chunkingStrategy,
}) = _CreateVectorStoreFileRequest;

/// Object construction from a JSON representation
factory CreateVectorStoreFileRequest.fromJson(Map<String, dynamic> json) =>
_$CreateVectorStoreFileRequestFromJson(json);

/// List of all property names of schema
static const List<String> propertyNames = ['file_id'];
static const List<String> propertyNames = ['file_id', 'chunking_strategy'];

/// Perform validations on the schema property values
String? validateSchema() {
Expand All @@ -35,6 +40,7 @@ class CreateVectorStoreFileRequest with _$CreateVectorStoreFileRequest {
Map<String, dynamic> toMap() {
return {
'file_id': fileId,
'chunking_strategy': chunkingStrategy,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ class CreateVectorStoreRequest with _$CreateVectorStoreRequest {
@JsonKey(name: 'expires_after', includeIfNull: false)
VectorStoreExpirationAfter? expiresAfter,

/// The chunking strategy used to chunk the file(s). If not set, will use the `auto` strategy.
/// Any of: [AutoChunkingStrategyRequestParam], [StaticChunkingStrategyRequestParam]
@JsonKey(name: 'chunking_strategy', includeIfNull: false)
ChunkingStrategyRequestParam? chunkingStrategy,

/// Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long.
@JsonKey(includeIfNull: false) dynamic metadata,
}) = _CreateVectorStoreRequest;
Expand All @@ -38,6 +43,7 @@ class CreateVectorStoreRequest with _$CreateVectorStoreRequest {
'name',
'file_ids',
'expires_after',
'chunking_strategy',
'metadata'
];

Expand All @@ -52,6 +58,7 @@ class CreateVectorStoreRequest with _$CreateVectorStoreRequest {
'name': name,
'file_ids': fileIds,
'expires_after': expiresAfter,
'chunking_strategy': chunkingStrategy,
'metadata': metadata,
};
}
Expand Down
3 changes: 3 additions & 0 deletions packages/openai_dart/lib/src/generated/schema/schema.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ part 'update_vector_store_request.dart';
part 'list_vector_stores_response.dart';
part 'delete_vector_store_response.dart';
part 'vector_store_file_object.dart';
part 'static_chunking_strategy.dart';
part 'create_vector_store_file_request.dart';
part 'list_vector_store_files_response.dart';
part 'delete_vector_store_file_response.dart';
Expand All @@ -152,4 +153,6 @@ part 'run_step_details_tool_calls.dart';
part 'run_step_delta_step_details_tool_calls.dart';
part 'run_step_details_tool_calls_code_output.dart';
part 'run_step_delta_step_details_tool_calls_code_output.dart';
part 'chunking_strategy_request_param.dart';
part 'chunking_strategy_response_param.dart';
part 'assistant_stream_event.dart';
Loading

0 comments on commit 31106fe

Please sign in to comment.