Skip to content

Commit

Permalink
feat: Add support for overrides in the file search tool in openai_dart (
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmigloz authored Jul 18, 2024
1 parent 90c9ccd commit 8960563
Show file tree
Hide file tree
Showing 9 changed files with 637 additions and 146 deletions.
4 changes: 2 additions & 2 deletions packages/openai_dart/lib/src/generated/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class OpenAIClientException implements Exception {
// CLASS: OpenAIClient
// ==========================================

/// Client for OpenAI API (v.2.0.0)
/// Client for OpenAI API (v.2.1.0)
///
/// The OpenAI REST API. Please see https://platform.openai.com/docs/api-reference for more details.
class OpenAIClient {
Expand Down Expand Up @@ -1846,7 +1846,7 @@ class OpenAIClient {
// METHOD: cancelBatch
// ------------------------------------------

/// Cancels an in-progress batch.
/// Cancels an in-progress batch. The batch will be in status `cancelling` for up to 10 minutes, before changing to `cancelled`, where it will have partial results (if any) available in the output file.
///
/// `batchId`: The ID of the batch to cancel.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ sealed class AssistantTools with _$AssistantTools {
/// FileSearch tool
const factory AssistantTools.fileSearch({
/// The type of tool being defined: `file_search`
@Default('file_search') String type,
required String type,

/// Overrides for the file search tool.
@JsonKey(name: 'file_search', includeIfNull: false)
AssistantToolsFileSearchFileSearch? fileSearch,
}) = AssistantToolsFileSearch;

// ------------------------------------------
Expand Down Expand Up @@ -63,3 +67,54 @@ enum AssistantToolsEnumType {
@JsonValue('function')
function,
}

// ==========================================
// CLASS: AssistantToolsFileSearchFileSearch
// ==========================================

/// Overrides for the file search tool.
@freezed
class AssistantToolsFileSearchFileSearch
with _$AssistantToolsFileSearchFileSearch {
const AssistantToolsFileSearchFileSearch._();

/// Factory constructor for AssistantToolsFileSearchFileSearch
const factory AssistantToolsFileSearchFileSearch({
/// The maximum number of results the file search tool should output. The default is 20 for gpt-4* models
/// and 5 for gpt-3.5-turbo. This number should be between 1 and 50 inclusive.
///
/// Note that the file search tool may output fewer than `max_num_results` results. See the [file search
/// tool documentation](/docs/assistants/tools/file-search/number-of-chunks-returned) for more information.
@JsonKey(name: 'max_num_results', includeIfNull: false) int? maxNumResults,
}) = _AssistantToolsFileSearchFileSearch;

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

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

/// Validation constants
static const maxNumResultsMinValue = 1;
static const maxNumResultsMaxValue = 50;

/// Perform validations on the schema property values
String? validateSchema() {
if (maxNumResults != null && maxNumResults! < maxNumResultsMinValue) {
return "The value of 'maxNumResults' cannot be < $maxNumResultsMinValue";
}
if (maxNumResults != null && maxNumResults! > maxNumResultsMaxValue) {
return "The value of 'maxNumResults' cannot be > $maxNumResultsMaxValue";
}
return null;
}

/// Map representation of object (not serialized)
Map<String, dynamic> toMap() {
return {
'max_num_results': maxNumResults,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class CreateBatchRequest with _$CreateBatchRequest {
///
/// See [upload file](https://platform.openai.com/docs/api-reference/files/create) for how to upload a file.
///
/// Your input file must be formatted as a JSONL file, and must be uploaded with the purpose `batch`.
/// Your input file must be formatted as a [JSONL file](https://platform.openai.com/docs/api-reference/batch/request-input), and must be uploaded with the purpose `batch`. The file can contain up to 50,000 requests, and can be up to 100 MB in size.
@JsonKey(name: 'input_file_id') required String inputFileId,

/// The endpoint to be used for all requests in the batch. Currently `/v1/chat/completions`, `/v1/embeddings`, and `/v1/completions` are supported. Note that `/v1/embeddings` batches are also restricted to a maximum of 50,000 embedding inputs across all requests in the batch.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ class CreateFineTuningJobRequest with _$CreateFineTuningJobRequest {
///
/// See [upload file](https://platform.openai.com/docs/api-reference/files/create) for how to upload a file.
///
/// Your dataset must be formatted as a JSONL file. Additionally, you must upload your file with the purpose `fine-tune`.
/// Your dataset must be formatted as a JSONL file. Additionally, you must upload your file with the purpose
/// `fine-tune`.
///
/// The contents of the file should differ depending on if the model uses the
/// [chat](https://platform.openai.com/docs/api-reference/fine-tuning/chat-input) or
/// [completions](https://platform.openai.com/docs/api-reference/fine-tuning/completions-input) format.
///
/// See the [fine-tuning guide](https://platform.openai.com/docs/guides/fine-tuning) for more details.
@JsonKey(name: 'training_file') required String trainingFile,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ class MessageContentTextAnnotationsFileCitation
const factory MessageContentTextAnnotationsFileCitation({
/// The ID of the specific File the citation is from.
@JsonKey(name: 'file_id') required String fileId,

/// The specific quote in the file.
@JsonKey(includeIfNull: false) String? quote,
}) = _MessageContentTextAnnotationsFileCitation;

/// Object construction from a JSON representation
Expand All @@ -29,7 +26,7 @@ class MessageContentTextAnnotationsFileCitation
_$MessageContentTextAnnotationsFileCitationFromJson(json);

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

/// Perform validations on the schema property values
String? validateSchema() {
Expand All @@ -40,7 +37,6 @@ class MessageContentTextAnnotationsFileCitation
Map<String, dynamic> toMap() {
return {
'file_id': fileId,
'quote': quote,
};
}
}
Loading

0 comments on commit 8960563

Please sign in to comment.