From 95cd1769f860a9a12d96a7d2ca4b314360ed68da Mon Sep 17 00:00:00 2001 From: frendguo Date: Wed, 19 Apr 2023 21:18:05 +0800 Subject: [PATCH] Add ForCustomHost --- OpenAI_API/OpenAIAPI.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/OpenAI_API/OpenAIAPI.cs b/OpenAI_API/OpenAIAPI.cs index f1e2bda..ad20350 100644 --- a/OpenAI_API/OpenAIAPI.cs +++ b/OpenAI_API/OpenAIAPI.cs @@ -67,6 +67,20 @@ public static OpenAIAPI ForAzure(string YourResourceName, string deploymentId, A return api; } + /// + /// Instantiate an API version for connecting to a custom OpenAI endpoint instead of the main OpenAI endpoint. + /// + /// Custom host + /// The API authentication information to use for API calls, or to attempt to use the , potentially loading from environment vars or from a config file. Currently this library only supports the api-key flow, not the AD-Flow. + /// + public static OpenAIAPI ForCustomHost(string host, APIAuthentication apiKey = null) { + OpenAIAPI api = new OpenAIAPI(apiKey) { + ApiUrlFormat = $"https://{host}/" + "{0}/{1}" + }; + + return api; + } + /// /// 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). ///