Skip to content

Commit 773bde7

Browse files
authored
Merge pull request OkGoDoIt#33 from gotmike/unused-usings-add-properties
remove unused usings; add missing properties; Thanks @gotmike !
2 parents b49a217 + 7d8f04d commit 773bde7

File tree

1 file changed

+146
-30
lines changed

1 file changed

+146
-30
lines changed

OpenAI_API/Model/Model.cs

Lines changed: 146 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
using Newtonsoft.Json;
1+
using Newtonsoft.Json;
2+
using System;
3+
using System.Collections.Generic;
24
using System.Threading.Tasks;
35

46
namespace OpenAI_API
57
{
6-
/// <summary>
7-
/// Represents a language model
8-
/// </summary>
9-
public class Model
10-
{
8+
/// <summary>
9+
/// Represents a language model
10+
/// </summary>
11+
public class Model
12+
{
1113
/// <summary>
1214
/// The id/name of the model
1315
/// </summary>
@@ -21,41 +23,75 @@ public class Model
2123
public string OwnedBy { get; set; }
2224

2325
/// <summary>
24-
/// Allows an model to be implicitly cast to the string of its <see cref="ModelID"/>
26+
/// The type of object. Should always be 'model'.
2527
/// </summary>
26-
/// <param name="model">The <see cref="Model"/> to cast to a string.</param>
27-
public static implicit operator string(Model model)
28-
{
29-
return model?.ModelID;
30-
}
28+
[JsonProperty("object")]
29+
public string Object { get; set; }
30+
31+
/// The time when the model was created
32+
[JsonIgnore]
33+
public DateTime Created => DateTimeOffset.FromUnixTimeSeconds(CreatedUnixTime.Value).DateTime;
3134

3235
/// <summary>
33-
/// Allows a string to be implicitly cast as an <see cref="Model"/> with that <see cref="ModelID"/>
36+
/// The time when the model was created in unix epoch format
3437
/// </summary>
35-
/// <param name="name">The id/<see cref="ModelID"/> to use</param>
36-
public static implicit operator Model(string name)
37-
{
38-
return new Model(name);
39-
}
38+
[JsonProperty("created")]
39+
public long CreatedUnixTime { get; set; }
4040

4141
/// <summary>
42-
/// Represents an Model with the given id/<see cref="ModelID"/>
42+
/// Permissions for use of the model
4343
/// </summary>
44-
/// <param name="name">The id/<see cref="ModelID"/> to use.
45-
/// </param>
46-
public Model(string name)
47-
{
48-
this.ModelID = name;
49-
}
44+
[JsonProperty("permission")]
45+
public List<Permissions> Permission { get; set; } = new List<Permissions>();
5046

5147
/// <summary>
52-
/// Represents a generic Model/model
48+
/// Currently (2023-01-27) seems like this is duplicate of <see cref="ModelID"/> but including for completeness.
5349
/// </summary>
54-
public Model()
55-
{
50+
[JsonProperty("root")]
51+
public string Root { get; set; }
5652

53+
/// <summary>
54+
/// Currently (2023-01-27) seems unused, probably intended for nesting of models in a later release
55+
/// </summary>
56+
[JsonProperty("parent")]
57+
public string Parent { get; set; }
58+
59+
/// <summary>
60+
/// Allows an model to be implicitly cast to the string of its <see cref="ModelID"/>
61+
/// </summary>
62+
/// <param name="model">The <see cref="Model"/> to cast to a string.</param>
63+
public static implicit operator string(Model model)
64+
{
65+
return model?.ModelID;
5766
}
5867

68+
/// <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+
}
76+
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+
}
86+
87+
/// <summary>
88+
/// Represents a generic Model/model
89+
/// </summary>
90+
public Model()
91+
{
92+
93+
}
94+
5995
/// <summary>
6096
/// The default model to use in requests if no other model is specified.
6197
/// </summary>
@@ -98,7 +134,6 @@ public Model()
98134
public static Model AdaTextEmbedding => new Model("text-embedding-ada-002") { OwnedBy = "openai" };
99135

100136

101-
102137
/// <summary>
103138
/// Gets more details about this Model from the API, specifically properties such as <see cref="OwnedBy"/> and permissions.
104139
/// </summary>
@@ -108,5 +143,86 @@ public async Task<Model> RetrieveModelDetailsAsync(OpenAI_API.OpenAIAPI api)
108143
{
109144
return await api.Models.RetrieveModelDetailsAsync(this.ModelID);
110145
}
111-
}
146+
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; }
165+
166+
/// The time when the permission was created
167+
[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+
}
227+
112228
}

0 commit comments

Comments
 (0)