Zayden / 쩨이든Add LiteLLM provider (#1542)87b11955 months agoHistory
32 lines · 1.1 KB · Swift
RawDownload
import Foundation public enum LiteLLMSettingsReader {    public static let apiKeyEnvironmentKey = "LITELLM_API_KEY"    public static let baseURLEnvironmentKey = "LITELLM_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    }}