增加chatGPT key是否有效校验
authorliangzhenying <867174124@qq.com>
Mon, 17 Feb 2025 08:31:25 +0000 (16:31 +0800)
committerliangzhenying <867174124@qq.com>
Mon, 17 Feb 2025 08:31:25 +0000 (16:31 +0800)
IOTBluetooth/IOTBluetooth/IOTBluetooth.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate
IOTBluetooth/IOTBluetooth/IOTBluetooth/IBAiManager.swift

index b85db71..28a9979 100644 (file)
Binary files a/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate and b/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate differ
index bf7fbd5..24cbe6d 100644 (file)
@@ -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()