Skip to content

Commit f80e06c

Browse files
committed
Merge commit '44dac23bf65aeec6ba91c37685a8784e58a1920a'
2 parents 52c230c + 44dac23 commit f80e06c

16 files changed

+1142
-989
lines changed

OpenAI_API/APIAuthentication.cs

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ public class APIAuthentication
1717
/// The API key, required to access the API endpoint.
1818
/// </summary>
1919
public string ApiKey { get; set; }
20-
/// <summary>
21-
/// The Organization ID to count API requests against. This can be found at https://beta.openai.com/account/org-settings.
22-
/// </summary>
23-
public string OpenAIOrganization { get; set; }
20+
/// <summary>
21+
/// The Organization ID to count API requests against. This can be found at https://beta.openai.com/account/org-settings.
22+
/// </summary>
23+
public string OpenAIOrganization { get; set; }
2424

2525
/// <summary>
2626
/// Allows implicit casting from a string, so that a simple string API key can be provided in place of an instance of <see cref="APIAuthentication"/>
@@ -41,18 +41,18 @@ public APIAuthentication(string apiKey)
4141
}
4242

4343

44-
/// <summary>
45-
/// Instantiates a new Authentication object with the given <paramref name="apiKey"/>, which may be <see langword="null"/>. For users who belong to multiple organizations, you can specify which organization is used. Usage from these API requests will count against the specified organization's subscription quota.
46-
/// </summary>
47-
/// <param name="apiKey">The API key, required to access the API endpoint.</param>
48-
/// <param name="openAIOrganization">The Organization ID to count API requests against. This can be found at https://beta.openai.com/account/org-settings.</param>
49-
public APIAuthentication(string apiKey, string openAIOrganization)
50-
{
51-
this.ApiKey = apiKey;
44+
/// <summary>
45+
/// Instantiates a new Authentication object with the given <paramref name="apiKey"/>, which may be <see langword="null"/>. For users who belong to multiple organizations, you can specify which organization is used. Usage from these API requests will count against the specified organization's subscription quota.
46+
/// </summary>
47+
/// <param name="apiKey">The API key, required to access the API endpoint.</param>
48+
/// <param name="openAIOrganization">The Organization ID to count API requests against. This can be found at https://beta.openai.com/account/org-settings.</param>
49+
public APIAuthentication(string apiKey, string openAIOrganization)
50+
{
51+
this.ApiKey = apiKey;
5252
this.OpenAIOrganization = openAIOrganization;
53-
}
53+
}
5454

55-
private static APIAuthentication cachedDefault = null;
55+
private static APIAuthentication cachedDefault = null;
5656

5757
/// <summary>
5858
/// The default authentication to use when no other auth is specified. This can be set manually, or automatically loaded via environment variables or a config file. <seealso cref="LoadFromEnv"/><seealso cref="LoadFromPath(string, string, bool)"/>
@@ -79,25 +79,25 @@ public static APIAuthentication Default
7979
}
8080
}
8181

82-
/// <summary>
83-
/// Attempts to load api key from environment variables, as "OPENAI_KEY" or "OPENAI_API_KEY". Also loads org if from "OPENAI_ORGANIZATION" if present.
84-
/// </summary>
85-
/// <returns>Returns the loaded <see cref="APIAuthentication"/> any api keys were found, or <see langword="null"/> if there were no matching environment vars.</returns>
86-
public static APIAuthentication LoadFromEnv()
82+
/// <summary>
83+
/// Attempts to load api key from environment variables, as "OPENAI_KEY" or "OPENAI_API_KEY". Also loads org if from "OPENAI_ORGANIZATION" if present.
84+
/// </summary>
85+
/// <returns>Returns the loaded <see cref="APIAuthentication"/> any api keys were found, or <see langword="null"/> if there were no matching environment vars.</returns>
86+
public static APIAuthentication LoadFromEnv()
8787
{
88-
string key = Environment.GetEnvironmentVariable("OPENAI_KEY");
88+
string key = Environment.GetEnvironmentVariable("OPENAI_KEY");
8989

9090
if (string.IsNullOrEmpty(key))
9191
{
92-
key = Environment.GetEnvironmentVariable("OPENAI_API_KEY");
92+
key = Environment.GetEnvironmentVariable("OPENAI_API_KEY");
9393

9494
if (string.IsNullOrEmpty(key))
95-
return null;
95+
return null;
9696
}
9797

98-
string org = Environment.GetEnvironmentVariable("OPENAI_ORGANIZATION");
98+
string org = Environment.GetEnvironmentVariable("OPENAI_ORGANIZATION");
9999

100-
return new APIAuthentication(key, org);
100+
return new APIAuthentication(key, org);
101101
}
102102

103103
/// <summary>
@@ -128,16 +128,16 @@ public static APIAuthentication LoadFromPath(string directory = null, string fil
128128
{
129129
switch (parts[0].ToUpper())
130130
{
131-
case "OPENAI_KEY":
132-
key = parts[1].Trim();
133-
break;
134-
case "OPENAI_API_KEY":
135-
key = parts[1].Trim();
136-
break;
137-
case "OPENAI_ORGANIZATION":
138-
org = parts[1].Trim();
139-
break;
140-
default:
131+
case "OPENAI_KEY":
132+
key = parts[1].Trim();
133+
break;
134+
case "OPENAI_API_KEY":
135+
key = parts[1].Trim();
136+
break;
137+
case "OPENAI_ORGANIZATION":
138+
org = parts[1].Trim();
139+
break;
140+
default:
141141
break;
142142
}
143143
}

OpenAI_API/ApiResultBase.cs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using Newtonsoft.Json;
2+
using System;
3+
4+
namespace OpenAI_API
5+
{
6+
/// <summary>
7+
/// Represents a result from calling the OpenAI API, with all the common metadata returned from every endpoint
8+
/// </summary>
9+
abstract public class ApiResultBase
10+
{
11+
12+
/// The time when the result was generated
13+
[JsonIgnore]
14+
public DateTime Created => DateTimeOffset.FromUnixTimeSeconds(CreatedUnixTime).DateTime;
15+
16+
/// <summary>
17+
/// The time when the result was generated in unix epoch format
18+
/// </summary>
19+
[JsonProperty("created")]
20+
public int CreatedUnixTime { get; set; }
21+
22+
/// <summary>
23+
/// Which model was used to generate this result.
24+
/// </summary>
25+
[JsonProperty("model")]
26+
public Model Model { get; set; }
27+
28+
/// <summary>
29+
/// Object type, ie: text_completion, file, fine-tune, list, etc
30+
/// </summary>
31+
[JsonProperty("object")]
32+
public string Object { get; set; }
33+
34+
/// <summary>
35+
/// The organization associated with the API request, as reported by the API.
36+
/// </summary>
37+
[JsonIgnore]
38+
public string Organization { get; internal set; }
39+
40+
/// <summary>
41+
/// The server-side processing time as reported by the API. This can be useful for debugging where a delay occurs.
42+
/// </summary>
43+
[JsonIgnore]
44+
public TimeSpan ProcessingTime { get; internal set; }
45+
46+
/// <summary>
47+
/// The request id of this API call, as reported in the response headers. This may be useful for troubleshooting or when contacting OpenAI support in reference to a specific request.
48+
/// </summary>
49+
[JsonIgnore]
50+
public string RequestId { get; internal set; }
51+
52+
/// <summary>
53+
/// The Openai-Version used to generate this response, as reported in the response headers. This may be useful for troubleshooting or when contacting OpenAI support in reference to a specific request.
54+
/// </summary>
55+
[JsonIgnore]
56+
public string OpenaiVersion { get; internal set; }
57+
}
58+
}

OpenAI_API/BaseEndpoint.cs

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)