setupViews()
setupChatCallBack()
//设置默认平台
- self.title = "chat-豆包"
+ self.title = MSPlatform.doubao.title
MixSdk.shared.setPlatform(.doubao)
}
chat.callBack = {[weak self] model in
guard let self = self else {return}
- print("\(model.type) : \(model.content ?? "")")
if model.type == "start" {
textView.text += Date().format(.full) + "[receive] "
@objc func changePlatform(){
let vc = UIAlertController(title: nil, message: "请选择", preferredStyle: .actionSheet)
- let action0 = UIAlertAction(title: "豆包", style: .default) { action in
- self.title = "chat-豆包"
+ vc.addAction( UIAlertAction(title: MSPlatform.doubao.title, style: .default) { action in
+ self.title = MSPlatform.doubao.title
MixSdk.shared.setPlatform(.doubao)
- }
- vc.addAction(action0)
- let action1 = UIAlertAction(title: "文心一言", style: .default) { action in
+ })
+ vc.addAction(UIAlertAction(title:MSPlatform.yiyan.title, style: .default) { action in
MixSdk.shared.setPlatform(.yiyan)
- self.title = "chat-文心一言"
- }
- vc.addAction(action1)
- let action2 = UIAlertAction(title: "KiMi", style: .default) { action in
+ self.title = MSPlatform.yiyan.title
+ })
+ vc.addAction(UIAlertAction(title: MSPlatform.kimi.title, style: .default) { action in
MixSdk.shared.setPlatform(.kimi)
- self.title = "chat-kimi"
- }
- vc.addAction(action2)
- let action3 = UIAlertAction(title: "ChatGPT", style: .default) { action in
+ self.title = MSPlatform.kimi.title
+ })
+ vc.addAction(UIAlertAction(title: MSPlatform.xunfei.title, style: .default) { action in
+ MixSdk.shared.setPlatform(.xunfei)
+ self.title = MSPlatform.xunfei.title
+ })
+ vc.addAction(UIAlertAction(title: MSPlatform.aliyun.title, style: .default) { action in
+ MixSdk.shared.setPlatform(.aliyun)
+ self.title = MSPlatform.aliyun.title
+ })
+ vc.addAction(UIAlertAction(title: MSPlatform.chatGPT.title, style: .default) { action in
MixSdk.shared.setPlatform(.chatGPT, key: gptKey)
MixSdk.shared.chatGpt.changeModel(model: gptModel)
- self.title = "chatGPT"
- }
- vc.addAction(action3)
+ self.title = MSPlatform.chatGPT.title
+ })
- let action4 = UIAlertAction(title: "取消", style: .cancel) { action in
- }
- vc.addAction(action4)
+ vc.addAction(UIAlertAction(title: "取消", style: .cancel) { action in
+ })
self.present(vc, animated: true)
}
extension ViewController{
@objc func registerAction() {
view.makeToastActivity(.center)
- let deviceId = "281106AFB0F7"
- let productId = "pafOCKLiUbeVHbdZlddH"
- let productKey = "HHosiYUNdG42t1cTgKOzIUPOvAVMI2QT"
MixSdk.shared.auth.register(productId: productId, productKey: productKey, deviceId: deviceId){[weak self] password,error in
self?.view.hideToastActivity()
if let password = password{
self?.view.makeToast("register success!")
print(password)
//deviceId和password APP要确保这个一一对应。
+ UserDefaults.standard.setValue(password, forKey: deviceId)
}
else{
print(error!)
}
}
@objc func loginAction() {
+ if let password = UserDefaults.standard.string(forKey: deviceId){
+ startLogin(password: password)
+ }
+ else{
+ self.view.makeToast("请先注册")
+ }
+ }
+ func startLogin(password:String){
view.makeToastActivity(.center)
- let deviceId = "281106AFB0F7"
- let productKey = "HHosiYUNdG42t1cTgKOzIUPOvAVMI2QT"
- let password = "aWGKrBWaijsKD5eEsVVU5rjWPI1sVy"//注册获得的密码
-
MixSdk.shared.auth.login(productKey:productKey,deviceId: deviceId, password: password){[weak self] token,error in
self?.view.hideToastActivity()
if let err = error{