Skip to content

Commit

Permalink
standardized timekeeping
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenHodgson committed Nov 17, 2023
1 parent 6b5412e commit 8669e0f
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 21 deletions.
8 changes: 6 additions & 2 deletions OpenAI-DotNet/Files/FileData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@ public sealed class FileData : BaseResponse
/// </summary>
[JsonInclude]
[JsonPropertyName("created_at")]
public int CreatedUnixTime { get; private set; }
public int CreatedAtUnixTimeSeconds { get; private set; }

[JsonIgnore]
public DateTime CreatedAt => DateTimeOffset.FromUnixTimeSeconds(CreatedUnixTime).DateTime;
[Obsolete("Use CreatedAtUnixTimeSeconds")]
public int CreatedUnixTime => CreatedAtUnixTimeSeconds;

[JsonIgnore]
public DateTime CreatedAt => DateTimeOffset.FromUnixTimeSeconds(CreatedAtUnixTimeSeconds).DateTime;

/// <summary>
/// The name of the file.
Expand Down
22 changes: 18 additions & 4 deletions OpenAI-DotNet/FineTuning/FineTuneJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,31 @@ public sealed class FineTuneJob

[JsonInclude]
[JsonPropertyName("created_at")]
public int? CreatedAtUnixTime { get; private set; }
public int? CreateAtUnixTimeSeconds { get; private set; }

[JsonIgnore]
public DateTime CreatedAt => DateTimeOffset.FromUnixTimeSeconds(CreatedAtUnixTime ?? 0).DateTime;
[Obsolete("Use CreateAtUnixTimeSeconds")]
public int? CreatedAtUnixTime => CreateAtUnixTimeSeconds;

[JsonIgnore]
public DateTime? CreatedAt
=> CreateAtUnixTimeSeconds.HasValue
? DateTimeOffset.FromUnixTimeSeconds(CreateAtUnixTimeSeconds.Value).DateTime
: null;

[JsonInclude]
[JsonPropertyName("finished_at")]
public int? FinishedAtUnixTime { get; private set; }
public int? FinishedAtUnixTimeSeconds { get; private set; }

[JsonIgnore]
[Obsolete("Use FinishedAtUnixTimeSeconds")]
public int? FinishedAtUnixTime => CreateAtUnixTimeSeconds;

[JsonIgnore]
public DateTime FinishedAt => DateTimeOffset.FromUnixTimeSeconds(FinishedAtUnixTime ?? 0).DateTime;
public DateTime? FinishedAt
=> FinishedAtUnixTimeSeconds.HasValue
? DateTimeOffset.FromUnixTimeSeconds(FinishedAtUnixTimeSeconds.Value).DateTime
: null;

[JsonInclude]
[JsonPropertyName("fine_tuned_model")]
Expand Down
45 changes: 30 additions & 15 deletions OpenAI-DotNet/Threads/RunResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,6 @@ public sealed class RunResponse : BaseResponse
[JsonPropertyName("object")]
public string Object { get; private set; }

/// <summary>
/// The Unix timestamp (in seconds) for when the thread was created.
/// </summary>
[JsonInclude]
[JsonPropertyName("created_at")]
public int CreatedAtUnixTimeSeconds { get; private set; }

[JsonIgnore]
public DateTime CreatedAt => DateTimeOffset.FromUnixTimeSeconds(CreatedAtUnixTimeSeconds).DateTime;

/// <summary>
/// The thread ID that this run belongs to.
/// </summary>
Expand Down Expand Up @@ -74,6 +64,16 @@ public sealed class RunResponse : BaseResponse
[JsonPropertyName("last_error")]
public RunLastError LastError { get; private set; }

/// <summary>
/// The Unix timestamp (in seconds) for when the thread was created.
/// </summary>
[JsonInclude]
[JsonPropertyName("created_at")]
public int CreatedAtUnixTimeSeconds { get; private set; }

[JsonIgnore]
public DateTime CreatedAt => DateTimeOffset.FromUnixTimeSeconds(CreatedAtUnixTimeSeconds).DateTime;

/// <summary>
/// The Unix timestamp (in seconds) for when the run will expire.
/// </summary>
Expand All @@ -82,7 +82,10 @@ public sealed class RunResponse : BaseResponse
public int? ExpiresAtUnixTimeSeconds { get; private set; }

[JsonIgnore]
public DateTime ExpiresAt => DateTimeOffset.FromUnixTimeSeconds(ExpiresAtUnixTimeSeconds ?? 0).DateTime;
public DateTime? ExpiresAt
=> ExpiresAtUnixTimeSeconds.HasValue
? DateTimeOffset.FromUnixTimeSeconds(ExpiresAtUnixTimeSeconds.Value).DateTime
: null;

/// <summary>
/// The Unix timestamp (in seconds) for when the run was started.
Expand All @@ -92,7 +95,10 @@ public sealed class RunResponse : BaseResponse
public int? StartedAtUnixTimeSeconds { get; private set; }

[JsonIgnore]
public DateTime StartedAt => DateTimeOffset.FromUnixTimeSeconds(StartedAtUnixTimeSeconds ?? 0).DateTime;
public DateTime? StartedAt
=> StartedAtUnixTimeSeconds.HasValue
? DateTimeOffset.FromUnixTimeSeconds(StartedAtUnixTimeSeconds.Value).DateTime
: null;

/// <summary>
/// The Unix timestamp (in seconds) for when the run was cancelled.
Expand All @@ -102,7 +108,10 @@ public sealed class RunResponse : BaseResponse
public int? CancelledAtUnixTimeSeconds { get; private set; }

[JsonIgnore]
public DateTime CancelledAt => DateTimeOffset.FromUnixTimeSeconds(CancelledAtUnixTimeSeconds ?? 0).DateTime;
public DateTime? CancelledAt
=> CancelledAtUnixTimeSeconds.HasValue
? DateTimeOffset.FromUnixTimeSeconds(CancelledAtUnixTimeSeconds.Value).DateTime
: null;

/// <summary>
/// The Unix timestamp (in seconds) for when the run failed.
Expand All @@ -112,7 +121,10 @@ public sealed class RunResponse : BaseResponse
public int? FailedAtUnixTimeSeconds { get; private set; }

[JsonIgnore]
public DateTime FailedAt => DateTimeOffset.FromUnixTimeSeconds(FailedAtUnixTimeSeconds ?? 0).DateTime;
public DateTime? FailedAt
=> FailedAtUnixTimeSeconds.HasValue
? DateTimeOffset.FromUnixTimeSeconds(FailedAtUnixTimeSeconds.Value).DateTime
: null;

/// <summary>
/// The Unix timestamp (in seconds) for when the run was completed.
Expand All @@ -122,7 +134,10 @@ public sealed class RunResponse : BaseResponse
public int? CompletedAtUnixTimeSeconds { get; private set; }

[JsonIgnore]
public DateTime CompletedAt => DateTimeOffset.FromUnixTimeSeconds(CompletedAtUnixTimeSeconds ?? 0).DateTime;
public DateTime? CompletedAt
=> CompletedAtUnixTimeSeconds.HasValue
? DateTimeOffset.FromUnixTimeSeconds(CompletedAtUnixTimeSeconds.Value).DateTime
: null;

/// <summary>
/// The model that the assistant used for this run.
Expand Down

0 comments on commit 8669e0f

Please sign in to comment.