From: liangzhenying <867174124@qq.com> Date: Mon, 17 Feb 2025 08:31:25 +0000 (+0800) Subject: 增加chatGPT key是否有效校验 X-Git-Url: http://git.snicker.com.cn/sitemap.xml?a=commitdiff_plain;h=0ae94d02579ca983fd5342ad473253ec6d523ef2;p=mirrors%2FIOTBluetooth-iOS.git 增加chatGPT key是否有效校验 --- diff --git a/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate b/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate index b85db71..28a9979 100644 Binary files a/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate and b/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBAiManager.swift b/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBAiManager.swift index bf7fbd5..24cbe6d 100644 --- a/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBAiManager.swift +++ b/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBAiManager.swift @@ -21,6 +21,9 @@ public class IBAiManager{ /// chatGpt model gpt3.5-turbo、gpt-4-turbo、gpt-4o 默认是 gpt-4-turbo public var gptModel:String = "gpt-4-turbo" + public var platform:MSPlatform{ + return MixSdk.shared.aiPlatform + } /// 使用大模型 public var useMode:((_ result:MSPlatform) -> Void)? /// 使用大模型 @@ -62,29 +65,29 @@ public class IBAiManager{ } else{ if platform == .chatGPT { - checkChatptValid() + checkChatptValid(key ?? "") {[weak self] isValid, error in + guard let self = self else {return} + if let valid = isValid{ + sendAiState(isValid: valid, gptKey: key) + } + else { + sendAiState(isValid: false, gptKey: key) + } + } } else{ sendAiState(isValid: true, gptKey: nil) } } } - - func checkChatptValid(){ + + public func checkChatptValid(_ key:String ,completeHandler: @escaping MSChatGptCheckKeyCallBack){ guard let key = chatGptKey else{ Logger.log("请先设置chatGPT key") - sendAiState(isValid: false, gptKey: "") + completeHandler(false,nil) return } - MixSdk.shared.chatGpt.isValidKey(key) {[weak self] isValid, error in - guard let self = self else {return} - if let valid = isValid{ - sendAiState(isValid: valid, gptKey: key) - } - else { - sendAiState(isValid: false, gptKey: key) - } - } + MixSdk.shared.chatGpt.isValidKey(key, completeHandler: completeHandler) } func sendAiState(isValid:Bool,gptKey:String?){ let model = IBAiValid()