Skip to content

Commit

Permalink
feat: Add usage to Run/RunStep in openai_dart client (#302)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmigloz committed Jan 20, 2024
1 parent 4a6e104 commit cc6538b
Show file tree
Hide file tree
Showing 11 changed files with 861 additions and 51 deletions.
2 changes: 1 addition & 1 deletion packages/openai_dart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Unofficial Dart client for [OpenAI](https://platform.openai.com/docs/api-referen
- Custom base URL, headers and query params support (e.g. HTTP proxies)
- Custom HTTP client support (e.g. SOCKS5 proxies or advanced use cases)
- Partial Azure OpenAI API support
- It can be used to consume OpenAI-compatible APIs like [OpenRouter](https://openrouter.ai), [Together AI](https://www.together.ai), [One API](https://github.com/songquanpeng/one-api), etc.
- It can be used to consume OpenAI-compatible APIs like [TogetherAI](https://www.together.ai/), [Anyscale](https://www.anyscale.com/), [OpenRouter](https://openrouter.ai), [One API](https://github.com/songquanpeng/one-api), etc.

**Supported endpoints:**

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// 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: RunCompletionUsage
// ==========================================

/// Usage statistics related to the run. This value will be `null` if the run is not in a terminal state (i.e. `in_progress`, `queued`, etc.).
@freezed
class RunCompletionUsage with _$RunCompletionUsage {
const RunCompletionUsage._();

/// Factory constructor for RunCompletionUsage
const factory RunCompletionUsage({
/// Number of completion tokens used over the course of the run.
@JsonKey(name: 'completion_tokens') required int completionTokens,

/// Number of prompt tokens used over the course of the run.
@JsonKey(name: 'prompt_tokens') required int promptTokens,

/// Total number of tokens used (prompt + completion).
@JsonKey(name: 'total_tokens') required int totalTokens,
}) = _RunCompletionUsage;

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

/// List of all property names of schema
static const List<String> propertyNames = [
'completion_tokens',
'prompt_tokens',
'total_tokens'
];

/// Perform validations on the schema property values
String? validateSchema() {
return null;
}

/// Map representation of object (not serialized)
Map<String, dynamic> toMap() {
return {
'completion_tokens': completionTokens,
'prompt_tokens': promptTokens,
'total_tokens': totalTokens,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ class RunObject with _$RunObject {

/// 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.
required Map<String, dynamic>? metadata,

/// Usage statistics related to the run. This value will be `null` if the run is not in a terminal state (i.e. `in_progress`, `queued`, etc.).
required RunCompletionUsage? usage,
}) = _RunObject;

/// Object construction from a JSON representation
Expand All @@ -94,7 +97,8 @@ class RunObject with _$RunObject {
'instructions',
'tools',
'file_ids',
'metadata'
'metadata',
'usage'
];

/// Perform validations on the schema property values
Expand Down Expand Up @@ -123,6 +127,7 @@ class RunObject with _$RunObject {
'tools': tools,
'file_ids': fileIds,
'metadata': metadata,
'usage': usage,
};
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// 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: RunStepCompletionUsage
// ==========================================

/// Usage statistics related to the run step. This value will be `null` while the run step's status is `in_progress`.
@freezed
class RunStepCompletionUsage with _$RunStepCompletionUsage {
const RunStepCompletionUsage._();

/// Factory constructor for RunStepCompletionUsage
const factory RunStepCompletionUsage({
/// Number of completion tokens used over the course of the run step.
@JsonKey(name: 'completion_tokens') required int completionTokens,

/// Number of prompt tokens used over the course of the run step.
@JsonKey(name: 'prompt_tokens') required int promptTokens,

/// Total number of tokens used (prompt + completion).
@JsonKey(name: 'total_tokens') required int totalTokens,
}) = _RunStepCompletionUsage;

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

/// List of all property names of schema
static const List<String> propertyNames = [
'completion_tokens',
'prompt_tokens',
'total_tokens'
];

/// Perform validations on the schema property values
String? validateSchema() {
return null;
}

/// Map representation of object (not serialized)
Map<String, dynamic> toMap() {
return {
'completion_tokens': completionTokens,
'prompt_tokens': promptTokens,
'total_tokens': totalTokens,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class RunStepObject with _$RunStepObject {

/// 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.
required Map<String, dynamic>? metadata,

/// Usage statistics related to the run step. This value will be `null` while the run step's status is `in_progress`.
required RunStepCompletionUsage? usage,
}) = _RunStepObject;

/// Object construction from a JSON representation
Expand All @@ -82,7 +85,8 @@ class RunStepObject with _$RunStepObject {
'cancelled_at',
'failed_at',
'completed_at',
'metadata'
'metadata',
'usage'
];

/// Perform validations on the schema property values
Expand All @@ -108,6 +112,7 @@ class RunStepObject with _$RunStepObject {
'failed_at': failedAt,
'completed_at': completedAt,
'metadata': metadata,
'usage': usage,
};
}
}
Expand Down
2 changes: 2 additions & 0 deletions packages/openai_dart/lib/src/generated/schema/schema.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ part 'modify_assistant_request.dart';
part 'delete_assistant_response.dart';
part 'list_assistants_response.dart';
part 'run_object.dart';
part 'run_completion_usage.dart';
part 'create_run_request.dart';
part 'list_runs_response.dart';
part 'modify_run_request.dart';
Expand All @@ -92,6 +93,7 @@ part 'list_run_steps_response.dart';
part 'run_step_details_message_creation.dart';
part 'run_step_details_tool_calls_code_object_code_interpreter.dart';
part 'run_step_details_tool_calls_code_output_image.dart';
part 'run_step_completion_usage.dart';
part 'assistant_file_object.dart';
part 'create_assistant_file_request.dart';
part 'delete_assistant_file_response.dart';
Expand Down
Loading

0 comments on commit cc6538b

Please sign in to comment.