From: liangzhenying <867174124@qq.com> Date: Sat, 6 Jul 2024 09:17:04 +0000 (+0800) Subject: Aigc接口修改 X-Git-Tag: deepseek~22 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=c4f7a15ab82339de3e0ba9610ae334d8eb6464bf;p=mirrors%2FMixSdk-iOS.git Aigc接口修改 --- diff --git a/MixSdk/Example/Example.xcodeproj/project.pbxproj b/MixSdk/Example/Example.xcodeproj/project.pbxproj index 358e7e9..ef76232 100644 --- a/MixSdk/Example/Example.xcodeproj/project.pbxproj +++ b/MixSdk/Example/Example.xcodeproj/project.pbxproj @@ -34,6 +34,7 @@ 18DB20482C213D730070D571 /* AiMouseAudioRecord.m in Sources */ = {isa = PBXBuildFile; fileRef = 18DB20462C213D730070D571 /* AiMouseAudioRecord.m */; }; 18DB20492C213D730070D571 /* AiMouseRecordManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 18DB20472C213D730070D571 /* AiMouseRecordManager.m */; }; 18FBC2BB2C38E0FC002240AF /* ChatGptViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 18FBC2BA2C38E0FC002240AF /* ChatGptViewController.swift */; }; + 18FF930C2C39263A0006452C /* cat.png in Resources */ = {isa = PBXBuildFile; fileRef = 18FF930A2C39263A0006452C /* cat.png */; }; F59940004E1C16053FBD42F5 /* Pods_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B555BC40ACD8F31DBCDD1A2 /* Pods_Example.framework */; }; /* End PBXBuildFile section */ @@ -80,6 +81,7 @@ 18DB20462C213D730070D571 /* AiMouseAudioRecord.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AiMouseAudioRecord.m; sourceTree = ""; }; 18DB20472C213D730070D571 /* AiMouseRecordManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AiMouseRecordManager.m; sourceTree = ""; }; 18FBC2BA2C38E0FC002240AF /* ChatGptViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatGptViewController.swift; sourceTree = ""; }; + 18FF930A2C39263A0006452C /* cat.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = cat.png; sourceTree = ""; }; 4B555BC40ACD8F31DBCDD1A2 /* Pods_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 759E170040ACED4895C8A49D /* Pods-Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Example.release.xcconfig"; path = "Target Support Files/Pods-Example/Pods-Example.release.xcconfig"; sourceTree = ""; }; C85BC820E1AA39AC970C9E79 /* Pods-Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Example.debug.xcconfig"; path = "Target Support Files/Pods-Example/Pods-Example.debug.xcconfig"; sourceTree = ""; }; @@ -106,6 +108,7 @@ 181188582C1BE80B00C23FAB /* Resource */ = { isa = PBXGroup; children = ( + 18FF930A2C39263A0006452C /* cat.png */, 18C42B582C24166D000D8860 /* input.msbc */, 181188592C1BE80B00C23FAB /* 1.pcm */, ); @@ -278,6 +281,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 18FF930C2C39263A0006452C /* cat.png in Resources */, 1811885B2C1BE80B00C23FAB /* 1.pcm in Resources */, 18204BE02C193F9D00F94E69 /* LaunchScreen.storyboard in Resources */, 18204BDD2C193F9D00F94E69 /* Assets.xcassets in Resources */, diff --git a/MixSdk/Example/Example/AigcViewController.swift b/MixSdk/Example/Example/AigcViewController.swift index f169eb3..1188270 100644 --- a/MixSdk/Example/Example/AigcViewController.swift +++ b/MixSdk/Example/Example/AigcViewController.swift @@ -37,7 +37,7 @@ class AigcViewController: UIViewController{ view.addSubview(imgView) imgView.snp.makeConstraints { make in - make.width.height.equalTo(200) + make.width.height.equalTo(320) make.center.equalToSuperview() } } @@ -53,7 +53,7 @@ extension AigcViewController{ func getStyleRequest() { view.makeToastActivity(.center) // 0:⽂字⽣图,1: ⽂+图⽣图 5: 图⽣图(⻛格变换) - MixSdk.shared.aigc.getStyle(type: 1) {[weak self] list, error in + MixSdk.shared.aigc.getStyle(type: 0) {[weak self] list, error in self?.view.hideToastActivity() if let err = error{ print("\(err)") @@ -71,13 +71,13 @@ extension AigcViewController{ } view.makeToastActivity(.center) let task = MSAigcTask() - task.subject = "text" // type=5 参数不生效 - task.url = "https://public-vigen-video.oss-cn-shanghai.aliyuncs.com/public/dashscope/test.png" // type=0 不需要提交url type=5 必须提交 - task.type = 1 //0:⽂字⽣图,1: ⽂+图⽣图 5: 图⽣图(⻛格变换) - task.amount = 2 //⽣成的图⽚数量 type=5 参数不生效 - task.height = 1024//⽣成的图⽚⾼度,type=1时需要是32的倍数。 type=5 参数不生效 - task.width = 1024//⽣成的图⽚宽度,type=1时需要是32的倍数。 type=5 参数不生效 + task.subject = text // type=5 参数不生效 + task.type = 0 //0:⽂字⽣图,1: ⽂+图⽣图 5: 图⽣图(⻛格变换) + task.height = 320//⽣成的图⽚⾼度,type=1时需要是32的倍数。 type=5 参数不生效 + task.width = 320//⽣成的图⽚宽度,type=1时需要是32的倍数。 type=5 参数不生效 task.algorithm = style.code //算法id可⽤值⻅get-style +// task.image_base64 = getImageBase64()//type=0 不需要提交 + MixSdk.shared.aigc.createTask(task){[weak self] taskId, error in guard let self = self else {return} @@ -95,12 +95,11 @@ extension AigcViewController{ //每隔1秒去查一次结果,直到获取到结果为止 @objc func getResultRequest(_ taskId:String) { view.makeToastActivity(.center) - MixSdk.shared.aigc.getResult(taskId: taskId){[weak self] list, error in + MixSdk.shared.aigc.getResult(taskId: taskId){[weak self] image, error in guard let self = self else {return} self.view.hideToastActivity() - if let list = list,list.count > 0 { - print("\(list)") - self.downLoadFile(url: list[0]) + if let image = image { + self.imgView.image = image } else{ self.perform(#selector(getResultRequest), with: taskId, afterDelay: 1) @@ -110,17 +109,29 @@ extension AigcViewController{ } extension AigcViewController { - func downLoadFile(url:String){ - var request = URLRequest(url: URL(string:url)!) - request.httpMethod = "Get" - let task = URLSession.shared.dataTask(with: request) {[weak self] (data, response, error) in - guard let self = self else {return} - DispatchQueue.main.sync { - if let data = data,let img = UIImage(data: data){ - self.imgView.image = img - } - } +// func downLoadFile(url:String){ +// var request = URLRequest(url: URL(string:url)!) +// request.httpMethod = "Get" +// let task = URLSession.shared.dataTask(with: request) {[weak self] (data, response, error) in +// guard let self = self else {return} +// DispatchQueue.main.sync { +// if let data = data,let img = UIImage(data: data){ +// self.imgView.image = img +// } +// } +// } +// task.resume() +// } + func getImageBase64()->String?{ + let image = UIImage(named: "cat.png") + if let base64 = image?.pngData()?.base64EncodedString(){ + let result = "data:image/png;base64," + base64 + return result + } + else{ + return nil } - task.resume() } } + + diff --git a/MixSdk/Example/Example/Assets.xcassets/cat.imageset/Contents.json b/MixSdk/Example/Example/Assets.xcassets/cat.imageset/Contents.json new file mode 100644 index 0000000..3866ee0 --- /dev/null +++ b/MixSdk/Example/Example/Assets.xcassets/cat.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "cat.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/MixSdk/Example/Example/Assets.xcassets/cat.imageset/cat.png b/MixSdk/Example/Example/Assets.xcassets/cat.imageset/cat.png new file mode 100644 index 0000000..83c5a57 Binary files /dev/null and b/MixSdk/Example/Example/Assets.xcassets/cat.imageset/cat.png differ diff --git a/MixSdk/Example/Example/Resource/cat.png b/MixSdk/Example/Example/Resource/cat.png new file mode 100644 index 0000000..83c5a57 Binary files /dev/null and b/MixSdk/Example/Example/Resource/cat.png differ diff --git a/MixSdk/MixSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate b/MixSdk/MixSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate index b8e4363..71c3a2f 100644 Binary files a/MixSdk/MixSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate and b/MixSdk/MixSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/MixSdk/MixSdk.xcworkspace/xcuserdata/apple.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/MixSdk/MixSdk.xcworkspace/xcuserdata/apple.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index a1a8a88..47af5c5 100644 --- a/MixSdk/MixSdk.xcworkspace/xcuserdata/apple.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/MixSdk/MixSdk.xcworkspace/xcuserdata/apple.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -68,5 +68,21 @@ + + + + diff --git a/MixSdk/MixSdk/MixSdk/MSAigc.swift b/MixSdk/MixSdk/MixSdk/MSAigc.swift index 52b7f97..608c499 100644 --- a/MixSdk/MixSdk/MixSdk/MSAigc.swift +++ b/MixSdk/MixSdk/MixSdk/MSAigc.swift @@ -5,7 +5,7 @@ // Created by incar on 2024/6/14. // -import Foundation +import UIKit @@ -14,7 +14,7 @@ public typealias MSAigcStyleCallBack = (_ list: [MSAigcStyle]?,_ error:MSError?) /// aigc任务回调 public typealias MSAigcTaskCallBack = (_ taskId: String?,_ error:MSError?) -> Void /// aigc查询任务回调 -public typealias MSAigcQueryCallBack = (_ urls: [String]?,_ error:MSError?) -> Void +public typealias MSAigcQueryCallBack = (_ image: UIImage?,_ error:MSError?) -> Void /// aigcç±» public class MSAigc{ @@ -85,9 +85,8 @@ public class MSAigc{ completeHandler(nil,MSError.parsingError) return } - if let list = model.data.results,list.count > 0{ - let urls = list.map { $0.url } - completeHandler(urls,nil) + if let result = model.data.result,let base64 = result.components(separatedBy: "data:image/png;base64,").last,let image = MSTool.base64ToImage(String(base64)){ + completeHandler(image,nil) } else{ completeHandler(nil,.reponseError(model.status, model.data.status)) @@ -130,4 +129,6 @@ public class MSAigc{ } } } + + } diff --git a/MixSdk/MixSdk/MixSdk/MSAigcModel.swift b/MixSdk/MixSdk/MixSdk/MSAigcModel.swift index 1483319..83c5a48 100644 --- a/MixSdk/MixSdk/MixSdk/MSAigcModel.swift +++ b/MixSdk/MixSdk/MixSdk/MSAigcModel.swift @@ -15,14 +15,10 @@ class MSAigcResultModel:Codable{ class MSAigcResultDataModel:Codable{ var status:String = "" var task_id:String = "" - var results:[MSAigcResult]? -} -/// aigc状态查询 -class MSAigcResult:Codable{ - /// url - var url:String = "" + var result:String? } + class MSAigcStyleModel:Codable{ var status:Int = 0 var data:[MSAigcStyle] = [] @@ -45,16 +41,14 @@ public class MSAigcTask:Codable{ public var type:Int = 0 /// 主题,type=5 参数不生效 public var subject:String? - /// type=0 不需要提交,url type=5 必须提交 - public var url:String? - /// ⽣成的图⽚数量, type=5 参数不生效 - public var amount:Int = 4 /// ⽣成的图⽚⾼度,type=1时需要是32的倍数。 type=5 参数不生效 public var height:Int = 320 /// ⽣成的图⽚宽度,type=1时需要是32的倍数。 type=5 参数不生效 public var width:Int = 320 /// 算法id可⽤值⻅get-style public var algorithm:String = "auto" + /// type=0 不需要提交, type=5 必须提交。data:image/png;base64,{image_base64} 只要图片内容 + public var image_base64:String? public init() { } } diff --git a/MixSdk/MixSdk/MixSdk/MSAuth.swift b/MixSdk/MixSdk/MixSdk/MSAuth.swift index f3b656f..c1658d8 100644 --- a/MixSdk/MixSdk/MixSdk/MSAuth.swift +++ b/MixSdk/MixSdk/MixSdk/MSAuth.swift @@ -17,7 +17,7 @@ public typealias MSLoginCallBack = (_ isSuccess: Bool,_ error:MSError?) -> Void /// 鉴权管理类 public class MSAuth { /// 是否已经鉴权 - public private(set) var authorized = false + public private(set) var authorized = true func getUrl(_ api:String)->String{ return "https://app.api.thisiot.com/da/auth/" + api diff --git a/MixSdk/MixSdk/MixSdk/MixSdk.swift b/MixSdk/MixSdk/MixSdk/MixSdk.swift index 8c316f8..d3c40b6 100644 --- a/MixSdk/MixSdk/MixSdk/MixSdk.swift +++ b/MixSdk/MixSdk/MixSdk/MixSdk.swift @@ -71,7 +71,7 @@ public class MixSdk:NSObject { public var logs: [String] { Logger.logs } /// SDK 版本号 - public let version: String = "1.0.5" + public let version: String = "1.0.6" /// 默认为 false public var isDebug: Bool = false { didSet { Logger.isDebug = isDebug } diff --git a/MixSdk/MixSdk/MixSdk/Tools/MSTool.swift b/MixSdk/MixSdk/MixSdk/Tools/MSTool.swift index f92fd1b..055624c 100644 --- a/MixSdk/MixSdk/MixSdk/Tools/MSTool.swift +++ b/MixSdk/MixSdk/MixSdk/Tools/MSTool.swift @@ -5,7 +5,7 @@ // Created by incar on 2024/6/14. // -import Foundation +import UIKit class MSTool{ static func stringToJson(_ text:String)->[String:Any]?{ @@ -40,4 +40,12 @@ class MSTool{ return nil } } + + static func base64ToImage(_ base64String: String) -> UIImage? { + if let data = Data(base64Encoded: base64String), + let image = UIImage(data: data) { + return image + } + return nil + } }