暫無描述

OpenAIConfiguration.swift 961B

1234567891011121314151617181920
  1. import Foundation
  2. enum OpenAIConfiguration {
  3. /// Emergency fallback key when plist/environment injection is unavailable.
  4. private static let fallbackAPIKey = "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"
  5. /// Read key from environment first, then Info.plist, then fallback.
  6. static var apiKey: String {
  7. let fromEnvironment = ProcessInfo.processInfo.environment["OPENAI_API_KEY"] ?? ""
  8. let fromPlist = Bundle.main.object(forInfoDictionaryKey: "OPENAI_API_KEY") as? String ?? ""
  9. let resolved = !fromEnvironment.isEmpty ? fromEnvironment : (!fromPlist.isEmpty ? fromPlist : fallbackAPIKey)
  10. return resolved.trimmingCharacters(in: .whitespacesAndNewlines)
  11. }
  12. /// Whether `apiKey` is currently populated with a real value.
  13. static var hasAPIKey: Bool {
  14. !apiKey.isEmpty
  15. }
  16. }