33 lines
1.1 KiB
Swift
33 lines
1.1 KiB
Swift
import Foundation
|
|
|
|
public enum LLMProxySettingsReader {
|
|
public static let apiKeyEnvironmentKey = "LLM_PROXY_API_KEY"
|
|
public static let baseURLEnvironmentKey = "LLM_PROXY_BASE_URL"
|
|
|
|
public static func apiKey(
|
|
environment: [String: String] = ProcessInfo.processInfo.environment) -> String?
|
|
{
|
|
self.cleaned(environment[self.apiKeyEnvironmentKey])
|
|
}
|
|
|
|
public static func baseURL(
|
|
environment: [String: String] = ProcessInfo.processInfo.environment) -> URL?
|
|
{
|
|
guard let raw = self.cleaned(environment[self.baseURLEnvironmentKey]) else { return nil }
|
|
return URL(string: raw)
|
|
}
|
|
|
|
static func cleaned(_ raw: String?) -> String? {
|
|
guard var value = raw?.trimmingCharacters(in: .whitespacesAndNewlines), !value.isEmpty else {
|
|
return nil
|
|
}
|
|
if (value.hasPrefix("\"") && value.hasSuffix("\"")) ||
|
|
(value.hasPrefix("'") && value.hasSuffix("'"))
|
|
{
|
|
value = String(value.dropFirst().dropLast())
|
|
}
|
|
value = value.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
return value.isEmpty ? nil : value
|
|
}
|
|
}
|