I have been following instructions to build a simple SwiftUI GPT-3 client using the OpenAISwift client library. The app works as expected on iOS but when I try to run a macos version I am getting these errors:
2023-01-02 15:07:14.845094-0500 GPT2[35955:1083936] [] networkd_settings_read_from_file Sandbox is preventing this process from reading networkd settings file at "/Library/Preferences/com.apple.networkd.plist", please add an exception. 2023-01-02 15:07:14.845261-0500 GPT2[35955:1083936] [] networkd_settings_read_from_file Sandbox is preventing this process from reading networkd settings file at "/Library/Preferences/com.apple.networkd.plist", please add an exception. 2023-01-02 15:07:15.078105-0500 GPT2[35955:1086396] [] nw_resolver_can_use_dns_xpc_block_invoke Sandbox does not allow access to com.apple.dnssd.service
I found another macos OpenAIKit project on gitub stating that the following need to be added to info.plist for macos:
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
<key>com.apple.security.network.server</key>
<true/>
</dict>
</plist>
but I did not see these choices available in the XCode 14 project properties info section. I would have tried pasting the dict object in to a text version of the info.plist but I could not see a way to edit the info.plist as a text.
Here is the simple code I am using:
import SwiftUI
import OpenAISwift
final class ViewModel: ObservableObject {
init() {}
private var client: OpenAISwift?
func setup() {
client = OpenAISwift(authToken: "MYKEYHERE")
}
func send(text: String,
completion: @escaping (String) -> Void) {
client?.sendCompletion(with: text,
maxTokens: 500,
completionHandler: {result in
switch result {
case .success(let model):
let output = model.choices.first?.text ?? ""
completion(output)
case .failure:
break
}
})
}
}
struct ContentView: View {
@ObservedObject var viewModel = ViewModel()
@State var text = ""
@State var models = [String]()
var body: some View {
VStack(alignment: .leading) {
ForEach(models, id: \.self) { string in
Text(string)
}
Spacer()
HStack {
TextField("Type here ...", text: $text)
Button("Send") {
send()
}
}
}
.onAppear{
viewModel.setup()
}.padding()
}
func send() {
guard !text.trimmingCharacters(in: .whitespaces).isEmpty else {
return
}
models.append("Me: \(text)")
viewModel.send(text: text) { response in
DispatchQueue.main.async {
self.models.append("GPT: " + response)
self.text = ""
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
How can I get this multiplatform app running on macos Ventura 13.1? Thanks for any help.
2条答案
按热度按时间s4n0splo1#
我在项目编辑器中的签名和功能下找到了一个用于启用沙箱的部分。我选择了传入和传出网络连接,并修复了这个问题。GPT现在正在与macos SwiftUI应用程序对话。我应该声明,我不确定我可能会启用什么漏洞。我希望听到任何人关于这两个设置检查可能存在的安全问题。
rbpvctlc2#
我相信您已经找到了如何做到这一点的答案(添加沙盒功能),但您需要一些更多的相关信息才能认为答案是完整的。
简而言之,这些设置会降低应用程序的安全性,但总体上是可以接受的。iOS上不存在这些设置,因为它们总是启用的。因此,它们不会导致一些严重的漏洞。
第一个设置允许应用程序将其访问权限扩展到用户通过打开文件对话框选择的所有文件(对于这一点,我甚至不确定这是如何扩展安全性的,尽管从技术上讲确实如此)。
第二个设置允许应用程序访问互联网。默认情况下,Mac应用程序根本无法访问互联网。这对于为某些类型的应用程序(如企业应用程序或文件管理器)提供额外的安全/隐私是有意义的,但一些普遍接受的事情(如收集分析和崩溃报告)需要此权限。
第三个设置允许应用程序作为一种互联网服务器。这肯定是一个潜在的安全问题,但由于应用程序仍然是沙箱在其访问计算机,只要沙箱是工作的预期,这并不代表一些大门入侵者也。