AIConfiguration.swift 643 B

123456789101112131415161718
  1. import Foundation
  2. enum AIConfiguration {
  3. /// OpenAI API key used by Post Generator, Title Optimizer, and Comment Writer.
  4. /// Priority: `OPENAI_API_KEY` environment variable (dev builds), then bundled encrypted key.
  5. static var apiKey: String? {
  6. if let envKey = ProcessInfo.processInfo.environment["OPENAI_API_KEY"],
  7. !envKey.trimmingCharacters(in: .whitespaces).isEmpty {
  8. return envKey.trimmingCharacters(in: .whitespaces)
  9. }
  10. return EncryptedOpenAIKey.openAIAPIKey()
  11. }
  12. static func usesLiveAI(hasPremiumAccess: Bool) -> Bool {
  13. hasPremiumAccess && apiKey != nil
  14. }
  15. }