-
Notifications
You must be signed in to change notification settings - Fork 431
/
Copy pathModelsEndpoint.cs
77 lines (69 loc) · 2.96 KB
/
ModelsEndpoint.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
namespace OpenAI_API.Models
{
/// <summary>
/// The API endpoint for querying available models
/// </summary>
public class ModelsEndpoint : EndpointBase, IModelsEndpoint
{
/// <summary>
/// The name of the endpoint, which is the final path segment in the API URL. For example, "models".
/// </summary>
protected override string Endpoint { get { return "models"; } }
/// <summary>
/// Constructor of the api endpoint. Rather than instantiating this yourself, access it through an instance of <see cref="OpenAIAPI"/> as <see cref="OpenAIAPI.Models"/>.
/// </summary>
/// <param name="api"></param>
internal ModelsEndpoint(OpenAIAPI api) : base(api) { }
/// <summary>
/// Constructor of the api endpoint. Rather than instantiating this yourself, access it through an instance of <see cref="OpenAIAPI"/> as <see cref="OpenAIAPI.Models"/>.
/// </summary>
/// <param name="httpClient"></param>
/// <param name="api"></param>
internal ModelsEndpoint(HttpClient httpClient, OpenAIAPI api) : base(httpClient, api) { }
/// <summary>
/// Get details about a particular Model from the API, specifically properties such as <see cref="Model.OwnedBy"/> and permissions.
/// </summary>
/// <param name="id">The id/name of the model to get more details about</param>
/// <returns>Asynchronously returns the <see cref="Model"/> with all available properties</returns>
public async Task<Model> RetrieveModelDetailsAsync(string id)
{
string resultAsString = await HttpGetContent<JsonHelperRoot>($"{Url}/{id}");
var model = JsonConvert.DeserializeObject<Model>(resultAsString);
return model;
}
/// <summary>
/// List all models via the API
/// </summary>
/// <returns>Asynchronously returns the list of all <see cref="Model"/>s</returns>
public async Task<List<Model>> GetModelsAsync()
{
return (await HttpGet<JsonHelperRoot>()).data;
}
/// <summary>
/// Get details about a particular Model from the API, specifically properties such as <see cref="Model.OwnedBy"/> and permissions.
/// </summary>
/// <param name="id">The id/name of the model to get more details about</param>
/// <param name="auth">Obsolete: IGNORED</param>
/// <returns>Asynchronously returns the <see cref="Model"/> with all available properties</returns>
[Obsolete("Use the overload without the APIAuthentication parameter instead, as custom auth is no longer used.", false)]
public async Task<Model> RetrieveModelDetailsAsync(string id, APIAuthentication auth = null)
{
return await this.RetrieveModelDetailsAsync(id);
}
/// <summary>
/// A helper class to deserialize the JSON API responses. This should not be used directly.
/// </summary>
private class JsonHelperRoot : ApiResultBase
{
[JsonProperty("data")]
public List<Model> data { get; set; }
[JsonProperty("object")]
public string obj { get; set; }
}
}
}