Skip to content

Commit 607f52c

Browse files
committed
Fix small date parsing bug in model details
1 parent 773bde7 commit 607f52c

File tree

3 files changed

+110
-107
lines changed

3 files changed

+110
-107
lines changed

OpenAI_API/Model/Model.cs

Lines changed: 106 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
namespace OpenAI_API
77
{
8-
/// <summary>
9-
/// Represents a language model
10-
/// </summary>
11-
public class Model
12-
{
8+
/// <summary>
9+
/// Represents a language model
10+
/// </summary>
11+
public class Model
12+
{
1313
/// <summary>
1414
/// The id/name of the model
1515
/// </summary>
@@ -30,7 +30,7 @@ public class Model
3030

3131
/// The time when the model was created
3232
[JsonIgnore]
33-
public DateTime Created => DateTimeOffset.FromUnixTimeSeconds(CreatedUnixTime.Value).DateTime;
33+
public DateTime Created => DateTimeOffset.FromUnixTimeSeconds(CreatedUnixTime).DateTime;
3434

3535
/// <summary>
3636
/// The time when the model was created in unix epoch format
@@ -62,35 +62,35 @@ public class Model
6262
/// <param name="model">The <see cref="Model"/> to cast to a string.</param>
6363
public static implicit operator string(Model model)
6464
{
65-
return model?.ModelID;
65+
return model?.ModelID;
6666
}
6767

6868
/// <summary>
69-
/// Allows a string to be implicitly cast as an <see cref="Model"/> with that <see cref="ModelID"/>
70-
/// </summary>
71-
/// <param name="name">The id/<see cref="ModelID"/> to use</param>
72-
public static implicit operator Model(string name)
73-
{
74-
return new Model(name);
75-
}
69+
/// Allows a string to be implicitly cast as an <see cref="Model"/> with that <see cref="ModelID"/>
70+
/// </summary>
71+
/// <param name="name">The id/<see cref="ModelID"/> to use</param>
72+
public static implicit operator Model(string name)
73+
{
74+
return new Model(name);
75+
}
7676

77-
/// <summary>
78-
/// Represents an Model with the given id/<see cref="ModelID"/>
79-
/// </summary>
80-
/// <param name="name">The id/<see cref="ModelID"/> to use.
81-
/// </param>
82-
public Model(string name)
83-
{
84-
this.ModelID = name;
85-
}
77+
/// <summary>
78+
/// Represents an Model with the given id/<see cref="ModelID"/>
79+
/// </summary>
80+
/// <param name="name">The id/<see cref="ModelID"/> to use.
81+
/// </param>
82+
public Model(string name)
83+
{
84+
this.ModelID = name;
85+
}
8686

87-
/// <summary>
88-
/// Represents a generic Model/model
89-
/// </summary>
90-
public Model()
91-
{
87+
/// <summary>
88+
/// Represents a generic Model/model
89+
/// </summary>
90+
public Model()
91+
{
9292

93-
}
93+
}
9494

9595
/// <summary>
9696
/// The default model to use in requests if no other model is specified.
@@ -144,85 +144,85 @@ public async Task<Model> RetrieveModelDetailsAsync(OpenAI_API.OpenAIAPI api)
144144
return await api.Models.RetrieveModelDetailsAsync(this.ModelID);
145145
}
146146

147-
}
148-
149-
/// <summary>
150-
/// Permissions for using the model
151-
/// </summary>
152-
public class Permissions
153-
{
154-
/// <summary>
155-
/// Permission Id (not to be confused with ModelId)
156-
/// </summary>
157-
[JsonProperty("id")]
158-
public string Id { get; set; }
159-
160-
/// <summary>
161-
/// Object type, should always be 'model_permission'
162-
/// </summary>
163-
[JsonProperty("object")]
164-
public string Object { get; set; }
147+
}
148+
149+
/// <summary>
150+
/// Permissions for using the model
151+
/// </summary>
152+
public class Permissions
153+
{
154+
/// <summary>
155+
/// Permission Id (not to be confused with ModelId)
156+
/// </summary>
157+
[JsonProperty("id")]
158+
public string Id { get; set; }
159+
160+
/// <summary>
161+
/// Object type, should always be 'model_permission'
162+
/// </summary>
163+
[JsonProperty("object")]
164+
public string Object { get; set; }
165165

166166
/// The time when the permission was created
167167
[JsonIgnore]
168-
public DateTime Created => DateTimeOffset.FromUnixTimeSeconds(CreatedUnixTime.Value).DateTime;
169-
170-
/// <summary>
171-
/// Unix timestamp for creation date/time
172-
/// </summary>
173-
[JsonProperty("created")]
174-
public long CreatedUnixTime { get; set; }
175-
176-
/// <summary>
177-
/// Can the model be created?
178-
/// </summary>
179-
[JsonProperty("allow_create_engine")]
180-
public bool AllowCreateEngine { get; set; }
181-
182-
/// <summary>
183-
/// Does the model support temperature sampling?
184-
/// https://beta.openai.com/docs/api-reference/completions/create#completions/create-temperature
185-
/// </summary>
186-
[JsonProperty("allow_sampling")]
187-
public bool AllowSampling { get; set; }
188-
189-
/// <summary>
190-
/// Does the model support logprobs?
191-
/// https://beta.openai.com/docs/api-reference/completions/create#completions/create-logprobs
192-
/// </summary>
193-
[JsonProperty("allow_logprobs")]
194-
public bool AllowLogProbs { get; set; }
195-
196-
/// <summary>
197-
/// Does the model support search indices?
198-
/// </summary>
199-
[JsonProperty("allow_search_indices")]
200-
public bool AllowSearchIndices { get; set; }
201-
202-
[JsonProperty("allow_view")]
203-
public bool AllowView { get; set; }
204-
205-
/// <summary>
206-
/// Does the model allow fine tuning?
207-
/// https://beta.openai.com/docs/api-reference/fine-tunes
208-
/// </summary>
209-
[JsonProperty("allow_fine_tuning")]
210-
public bool AllowFineTuning { get; set; }
211-
212-
/// <summary>
213-
/// Is the model only allowed for a particular organization? May not be implemented yet.
214-
/// </summary>
215-
[JsonProperty("organization")]
216-
public string Organization { get; set; }
217-
218-
/// <summary>
219-
/// Is the model part of a group? Seems not implemented yet. Always null.
220-
/// </summary>
221-
[JsonProperty("group")]
222-
public string Group { get; set; }
223-
224-
[JsonProperty("is_blocking")]
225-
public bool IsBlocking { get; set; }
226-
}
168+
public DateTime Created => DateTimeOffset.FromUnixTimeSeconds(CreatedUnixTime).DateTime;
169+
170+
/// <summary>
171+
/// Unix timestamp for creation date/time
172+
/// </summary>
173+
[JsonProperty("created")]
174+
public long CreatedUnixTime { get; set; }
175+
176+
/// <summary>
177+
/// Can the model be created?
178+
/// </summary>
179+
[JsonProperty("allow_create_engine")]
180+
public bool AllowCreateEngine { get; set; }
181+
182+
/// <summary>
183+
/// Does the model support temperature sampling?
184+
/// https://beta.openai.com/docs/api-reference/completions/create#completions/create-temperature
185+
/// </summary>
186+
[JsonProperty("allow_sampling")]
187+
public bool AllowSampling { get; set; }
188+
189+
/// <summary>
190+
/// Does the model support logprobs?
191+
/// https://beta.openai.com/docs/api-reference/completions/create#completions/create-logprobs
192+
/// </summary>
193+
[JsonProperty("allow_logprobs")]
194+
public bool AllowLogProbs { get; set; }
195+
196+
/// <summary>
197+
/// Does the model support search indices?
198+
/// </summary>
199+
[JsonProperty("allow_search_indices")]
200+
public bool AllowSearchIndices { get; set; }
201+
202+
[JsonProperty("allow_view")]
203+
public bool AllowView { get; set; }
204+
205+
/// <summary>
206+
/// Does the model allow fine tuning?
207+
/// https://beta.openai.com/docs/api-reference/fine-tunes
208+
/// </summary>
209+
[JsonProperty("allow_fine_tuning")]
210+
public bool AllowFineTuning { get; set; }
211+
212+
/// <summary>
213+
/// Is the model only allowed for a particular organization? May not be implemented yet.
214+
/// </summary>
215+
[JsonProperty("organization")]
216+
public string Organization { get; set; }
217+
218+
/// <summary>
219+
/// Is the model part of a group? Seems not implemented yet. Always null.
220+
/// </summary>
221+
[JsonProperty("group")]
222+
public string Group { get; set; }
223+
224+
[JsonProperty("is_blocking")]
225+
public bool IsBlocking { get; set; }
226+
}
227227

228228
}

OpenAI_Tests/CompletionEndpointTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,8 @@ public async Task StreamCompletionEnumerableAsync_MultipleParamShouldReturnTheSa
423423
}
424424

425425
public static class CompletionTestingHelper
426-
{ public static void ShouldNotBeEmpty(this CompletionResult results)
426+
{
427+
public static void ShouldNotBeEmpty(this CompletionResult results)
427428
{
428429
results.Should().NotBeNull("a result must be received");
429430
results.Completions.Should().NotBeNull("completions must be received");

OpenAI_Tests/ModelEndpointTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ public async Task RetrieveEngineDetailsAsync_ShouldRetrieveEngineDetails(string
7171
var api = new OpenAI_API.OpenAIAPI();
7272
var modelData = await api.Models.RetrieveModelDetailsAsync(modelId);
7373
modelData?.ModelID?.Should()?.Be(modelId);
74+
modelData.Created.Should().BeAfter(new DateTime(2018, 1, 1), "the model has a created date no earlier than 2018");
75+
modelData.Created.Should().BeBefore(DateTime.Now.AddDays(1), "the model has a created date before today");
7476
}
7577
}
7678
}

0 commit comments

Comments
 (0)