diff --git a/OpenAI_API/APIAuthentication.cs b/OpenAI_API/APIAuthentication.cs
index 4346281..fe916ad 100644
--- a/OpenAI_API/APIAuthentication.cs
+++ b/OpenAI_API/APIAuthentication.cs
@@ -9,7 +9,7 @@ namespace OpenAI_API
///
/// Represents authentication to the OpenAPI API endpoint
///
- public class APIAuthentication
+ public class APIAuthentication : IAPIAuthentication
{
///
/// The API key, required to access the API endpoint.
diff --git a/OpenAI_API/IAPIAuthentication.cs b/OpenAI_API/IAPIAuthentication.cs
new file mode 100644
index 0000000..855365b
--- /dev/null
+++ b/OpenAI_API/IAPIAuthentication.cs
@@ -0,0 +1,26 @@
+using System.Threading.Tasks;
+
+namespace OpenAI_API
+{
+ ///
+ /// Represents authentication to the OpenAPI API endpoint
+ ///
+ public interface IAPIAuthentication
+ {
+ ///
+ /// The API key, required to access the API endpoint.
+ ///
+ string ApiKey { get; set; }
+
+ ///
+ /// The Organization ID to count API requests against. This can be found at https://beta.openai.com/account/org-settings.
+ ///
+ string OpenAIOrganization { get; set; }
+
+ ///
+ /// Tests the api key against the OpenAI API, to ensure it is valid. This hits the models endpoint so should not be charged for usage.
+ ///
+ /// if the api key is valid, or if empty or not accepted by the OpenAI API.
+ Task ValidateAPIKey();
+ }
+}
\ No newline at end of file
diff --git a/OpenAI_API/IOpenAIAPI.cs b/OpenAI_API/IOpenAIAPI.cs
index 7b2de67..6bf1b9d 100644
--- a/OpenAI_API/IOpenAIAPI.cs
+++ b/OpenAI_API/IOpenAIAPI.cs
@@ -1,3 +1,4 @@
+using OpenAI_API.Chat;
using OpenAI_API.Completions;
using OpenAI_API.Embedding;
using OpenAI_API.Files;
@@ -25,26 +26,31 @@ public interface IOpenAIAPI
///
/// The API authentication information to use for API calls
///
- APIAuthentication Auth { get; set; }
+ IAPIAuthentication Auth { get; set; }
///
/// Text generation is the core function of the API. You give the API a prompt, and it generates a completion. The way you “program” the API to do a task is by simply describing the task in plain english or providing a few written examples. This simple approach works for a wide range of use cases, including summarization, translation, grammar correction, question answering, chatbots, composing emails, and much more (see the prompt library for inspiration).
///
- CompletionEndpoint Completions { get; }
+ ICompletionEndpoint Completions { get; }
///
/// The API lets you transform text into a vector (list) of floating point numbers. The distance between two vectors measures their relatedness. Small distances suggest high relatedness and large distances suggest low relatedness.
///
- EmbeddingEndpoint Embeddings { get; }
+ IEmbeddingEndpoint Embeddings { get; }
+
+ ///
+ /// Text generation in the form of chat messages. This interacts with the ChatGPT API.
+ ///
+ IChatEndpoint Chat { get; }
///
/// The API endpoint for querying available Engines/models
///
- ModelsEndpoint Models { get; }
+ IModelsEndpoint Models { get; }
///
/// The API lets you do operations with files. You can upload, delete or retrieve files. Files can be used for fine-tuning, search, etc.
///
- FilesEndpoint Files { get; }
+ IFilesEndpoint Files { get; }
}
}
\ No newline at end of file
diff --git a/OpenAI_API/OpenAIAPI.cs b/OpenAI_API/OpenAIAPI.cs
index f415410..6159b4e 100644
--- a/OpenAI_API/OpenAIAPI.cs
+++ b/OpenAI_API/OpenAIAPI.cs
@@ -29,7 +29,7 @@ public class OpenAIAPI : IOpenAIAPI
///
/// The API authentication information to use for API calls
///
- public APIAuthentication Auth { get; set; }
+ public IAPIAuthentication Auth { get; set; }
///
/// Creates a new entry point to the OpenAPI API, handling auth and allowing access to the various API endpoints
@@ -65,37 +65,37 @@ public static OpenAIAPI ForAzure(string YourResourceName, string deploymentId, A
///
/// Text generation is the core function of the API. You give the API a prompt, and it generates a completion. The way you “program” the API to do a task is by simply describing the task in plain english or providing a few written examples. This simple approach works for a wide range of use cases, including summarization, translation, grammar correction, question answering, chatbots, composing emails, and much more (see the prompt library for inspiration).
///
- public CompletionEndpoint Completions { get; }
+ public ICompletionEndpoint Completions { get; }
///
/// The API lets you transform text into a vector (list) of floating point numbers. The distance between two vectors measures their relatedness. Small distances suggest high relatedness and large distances suggest low relatedness.
///
- public EmbeddingEndpoint Embeddings { get; }
+ public IEmbeddingEndpoint Embeddings { get; }
///
/// Text generation in the form of chat messages. This interacts with the ChatGPT API.
///
- public ChatEndpoint Chat { get; }
+ public IChatEndpoint Chat { get; }
///
/// Classify text against the OpenAI Content Policy.
///
- public ModerationEndpoint Moderation { get; }
+ public IModerationEndpoint Moderation { get; }
///
/// The API endpoint for querying available Engines/models
///
- public ModelsEndpoint Models { get; }
+ public IModelsEndpoint Models { get; }
///
/// The API lets you do operations with files. You can upload, delete or retrieve files. Files can be used for fine-tuning, search, etc.
///
- public FilesEndpoint Files { get; }
+ public IFilesEndpoint Files { get; }
///
/// The API lets you do operations with images. You can Given a prompt and/or an input image, the model will generate a new image.
///
- public ImageGenerationEndpoint ImageGenerations { get; }
+ public IImageGenerationEndpoint ImageGenerations { get; }
}
}
diff --git a/OpenAI_Tests/AuthTests.cs b/OpenAI_Tests/AuthTests.cs
index e791c81..32da514 100644
--- a/OpenAI_Tests/AuthTests.cs
+++ b/OpenAI_Tests/AuthTests.cs
@@ -67,14 +67,14 @@ public void testHelper()
OpenAI_API.APIAuthentication defaultAuth = OpenAI_API.APIAuthentication.Default;
OpenAI_API.APIAuthentication manualAuth = new OpenAI_API.APIAuthentication("pk-testAA");
OpenAI_API.OpenAIAPI api = new OpenAI_API.OpenAIAPI();
- OpenAI_API.APIAuthentication shouldBeDefaultAuth = api.Auth;
+ OpenAI_API.IAPIAuthentication shouldBeDefaultAuth = api.Auth;
Assert.IsNotNull(shouldBeDefaultAuth);
Assert.IsNotNull(shouldBeDefaultAuth.ApiKey);
Assert.AreEqual(defaultAuth.ApiKey, shouldBeDefaultAuth.ApiKey);
OpenAI_API.APIAuthentication.Default = new OpenAI_API.APIAuthentication("pk-testAA");
api = new OpenAI_API.OpenAIAPI();
- OpenAI_API.APIAuthentication shouldBeManualAuth = api.Auth;
+ OpenAI_API.IAPIAuthentication shouldBeManualAuth = api.Auth;
Assert.IsNotNull(shouldBeManualAuth);
Assert.IsNotNull(shouldBeManualAuth.ApiKey);
Assert.AreEqual(manualAuth.ApiKey, shouldBeManualAuth.ApiKey);