Skip to content

OpenAI support for Azure and AIProxy

Compare
Choose a tag to compare
@jamesrochabrun jamesrochabrun released this 17 Apr 06:02
· 16 commits to main since this release

Adding LLMConfiguration definition to allow usage of Azure and AIPRoxy within PolyAI.

public enum LLMConfiguration {

   case openAI(OpenAI)
   
   public enum OpenAI {
      /// Configuration for accessing OpenAI's API.
      /// - Parameters:
      ///   - apiKey: The API key for authenticating requests to OpenAI.
      ///   - organizationID: Optional organization ID for OpenAI usage.
      ///   - configuration: The URLSession configuration to use for network requests. Defaults to `.default`.
      ///   - decoder: The JSON decoder used for decoding responses. Defaults to a new instance of `JSONDecoder`.
      case api(key: String, organizationID: String? = nil, configuration: URLSessionConfiguration = .default, decoder: JSONDecoder = .init())
      /// Configuration for accessing OpenAI's API.
      /// - Parameters:
      ///   - configuration: The AzureOpenAIConfiguration.
      ///   - urlSessionConfiguration: The URLSession configuration to use for network requests. Defaults to `.default`.
      ///   - decoder: The JSON decoder used for decoding responses. Defaults to a new instance of `JSONDecoder`.
      case azure(configuration: AzureOpenAIConfiguration, urlSessionConfiguration: URLSessionConfiguration = .default, decoder: JSONDecoder = .init())
      /// Configuration for accessing OpenAI's API.
      /// - Parameters:
      ///   - aiproxyPartialKey: The partial key provided in the 'API Keys' section of the AIProxy dashboard.
      ///   - aiproxyDeviceCheckBypass: The bypass token that is provided in the 'API Keys' section of the AIProxy dashboard.
      ///   - configuration: The URLSession configuration to use for network requests. Defaults to `.default`.
      ///   - decoder: The JSON decoder used for decoding responses. Defaults to a new instance of `JSONDecoder`.
      case aiProxy(aiproxyPartialKey: String, aiproxyDeviceCheckBypass: String? = nil, configuration: URLSessionConfiguration = .default, decoder: JSONDecoder = .init())
   }
   
   /// Configuration for accessing Anthropic's API.
   /// - Parameters:
   ///   - apiKey: The API key for authenticating requests to Anthropic.
   ///   - configuration: The URLSession configuration to use for network requests. Defaults to `.default`.
   case anthropic(apiKey: String, configuration: URLSessionConfiguration = .default)
}

Usage

Azure:

let azureConfiguration: LLMConfiguration = .openAI(.azure(configuration: .init(resourceName: "YOUR_RESOURCE_NAME", openAIAPIKey: .apiKey("YOUR_API_KEY"), apiVersion: "THE_API_VERSION")))

AIProxy

let aiProxyConfiguration: LLMConfiguration = .openAI(.aiProxy(aiproxyPartialKey: "hardcode_partial_key_here", aiproxyDeviceCheckBypass: "hardcode_device_check_bypass_here"))