For anyone having an issue with "authToken" and Xcode asking to replace it with "config", this was not updated in the docs yet in v1.4 of OpenAISwift. Here is the fix. Change your: OpenAISwift(authToken: Constants.key) to: OpenAISwift(config: OpenAISwift.Config.makeDefaultOpenAI(apiKey: Constants.key)) Hope that helps!
@@zs9458 getResponse function would look like this: "client?.sendCompletion(with: input, model: .codex(.davinci), maxTokens: 50, completionHandler...."
October 2023 -- I was able to fix the issue by just adding $5 to my OpenID account (and wait 5 minutes). Setup function should look like this private var client: OpenAISwift? public func setup() { let config: OpenAISwift.Config = .makeDefaultOpenAI(apiKey: “YOUR-ID-KEY") client = OpenAISwift(config: config) // Initialize OpenAI }
definitely a more advanced tutorial, would love if you provided a little bit more explanation behind why you use certain things as if a beginner was encountering it ... gotta go thru the rest of ur videos I suppose
Is your OpenAI API key secure if built into an App Store app like you’ve done in this video - or are there other steps you’d need to take to protect it before uploading your app?
After looking into this (in May 2023), it seems this API doesn't work as the video suggests. The OpenAI API requires that a user goes through a backend, to handle the API keys. "OpenAI’s usage policies do not allow developers to embed their API keys directly in a client-side application." It would be great if you could do an update to this video. Otherwise, anyone who comes across this video now or in the future should understand that they will get a "nil" response back from the sendCompletion function.
You’re right I’m getting a nil response. I also tried saving the apiKey in a node in firebase but I still get nil. Is there something I might be missing?
@@JayAA212 Yes, I figured it out. You can't really use the framework in this video. I can make a video to walk you through it ? You basically have to write your own RESTful API, which lives in Firebase Functions, and then, from iOS, you sent an HTTP Post request to your function API, which sends that post body to the OpenAI API. I've found zero resources online to explain this, so I should probably make a video, because it would help a lot of people.
@@OnionKnight541 Ohhh that makes total sense! Yes please do make a video and mention it here if you ever did, I know it will help many people. I’ll try to get it working using your approach meanwhile. Thanks!
I was able to fix the issue by just adding $5 to my OpenID account (and wait 3-5 minutes just in case). Setup function should look like this private var client: OpenAISwift? public func setup() { let config: OpenAISwift.Config = .makeDefaultOpenAI(apiKey: “YOUR-ID-KEY") client = OpenAISwift(config: config) // Initialize OpenAI }
hi, I think OpenAI change there model for now is : public struct OpenAI: Codable { public let object: String public let model: String public let choices: [Choice] } But i have a .decode error when call api
Hello? I have a question because there is a problem. If I add .codex, I won't see the answer to the GPT. It looks like the answer in the video before I add it. May I know the solution?
I got stuck with a strange error :Type 'ViewController' does not conform to protocol 'UITableViewDataSource' and can't find hot to fix it :/ Seems like i did everything identical to the code on the video
Yes, click on the error and it will ask you if you want to enter the "Stub" functions needed. You need to add two tablewiew functions. Review Tableview tutorials to learn about that.
i've been getting "nil" response too. i did start an OpenAI paid account, and the model worked one time (barely), but now doesn't work at all. I've tried different parameters. have you figured anything out? i'm pretty sure this API is broken.
What is this technique called (where you initialize and customize an object before assigning it)? private let field: UITextField = { let textField = UITextField() // Customize text field. return textField }()
I built a chatbot in Python that reads a JSON file and answers basic questions about my fictitious business. It it possible do implement this bot in swift? Or is there a better way to just do it in swift
@@iOSAcademy yea I understand how to create one that just uses an if else statement. The one with Python used a training file to “teach” the bot it’s words/phrases from a json file then the bot file runs both of those. I’m not sure how Xcode implements this
You should make a video now where you see how much ChatGPT can make this app for you.. I'm sure it won't be totally correct but it would be interesting to see how much you could get from it.
@iOS Academy he means the variability/consistancy in the AI response -- They refer to it as "Temperature" @Duncan it's controllable in the openAI API playground/backend
@@iOSAcademy nice. Good work by the way. Not putting any damper on your incredible channel! Keep promoting iOS development, the people need it. I'm starting to use ChatGPT as an assistant and have found it's getting about 60% of the questions right. Anything with complex questions just breaks it. I want to do a video about this. For instance, the bot suggested I do struct MyInt: UInt8 {} when asked to create my own integer type that is like a UInt8, whereas we all know this fails. I had to figure it out myself using struct MyInt: ExpressibleByInteger {} etc...
Interested in iOS? Follow linkedin.com/in/afrazsiddiqui
For anyone having an issue with "authToken" and Xcode asking to replace it with "config", this was not updated in the docs yet in v1.4 of OpenAISwift.
Here is the fix. Change your:
OpenAISwift(authToken: Constants.key)
to:
OpenAISwift(config: OpenAISwift.Config.makeDefaultOpenAI(apiKey: Constants.key))
Hope that helps!
thank you, your comment was very helpful, I could not solve this error.
World needs more people like you!
thank you!!! you saved me
The short answers were because maxTokens = 16 default. If you change it, the answers will be more.
I realized afterwards
How and where would I adjust this????? 😅
@@zs9458 getResponse function would look like this: "client?.sendCompletion(with: input, model: .codex(.davinci), maxTokens: 50, completionHandler...."
Yup I was thinking the same thing!
having issues running it says APICaller no member of client and cannot not use non optional value of string
October 2023
--
I was able to fix the issue by just adding $5 to my OpenID account (and wait 5 minutes). Setup function should look like this
private var client: OpenAISwift?
public func setup() {
let config: OpenAISwift.Config = .makeDefaultOpenAI(apiKey: “YOUR-ID-KEY")
client = OpenAISwift(config: config) // Initialize OpenAI
}
definitely a more advanced tutorial, would love if you provided a little bit more explanation behind why you use certain things as if a beginner was encountering it ... gotta go thru the rest of ur videos I suppose
thanks for noting this
Is your OpenAI API key secure if built into an App Store app like you’ve done in this video - or are there other steps you’d need to take to protect it before uploading your app?
After looking into this (in May 2023), it seems this API doesn't work as the video suggests. The OpenAI API requires that a user goes through a backend, to handle the API keys. "OpenAI’s usage policies do not allow developers to embed their API keys directly in a client-side application."
It would be great if you could do an update to this video. Otherwise, anyone who comes across this video now or in the future should understand that they will get a "nil" response back from the sendCompletion function.
You’re right I’m getting a nil response. I also tried saving the apiKey in a node in firebase but I still get nil. Is there something I might be missing?
@@JayAA212 Yes, I figured it out. You can't really use the framework in this video. I can make a video to walk you through it ? You basically have to write your own RESTful API, which lives in Firebase Functions, and then, from iOS, you sent an HTTP Post request to your function API, which sends that post body to the OpenAI API. I've found zero resources online to explain this, so I should probably make a video, because it would help a lot of people.
@@OnionKnight541 Ohhh that makes total sense! Yes please do make a video and mention it here if you ever did, I know it will help many people. I’ll try to get it working using your approach meanwhile. Thanks!
Was trying this video and getting nil response like many people.
I was able to fix the issue by just adding $5 to my OpenID account (and wait 3-5 minutes just in case). Setup function should look like this
private var client: OpenAISwift?
public func setup() {
let config: OpenAISwift.Config = .makeDefaultOpenAI(apiKey: “YOUR-ID-KEY")
client = OpenAISwift(config: config) // Initialize OpenAI
}
Hi, do you have a video about how to integrate gpt-4o API?
My print result Always shows nil. In apicaller.😔
Awesome tutorial. Thank you
You are welcome!
Solution: let config = OpenAISwift(config: .makeDefaultOpenAI(apiKey: Constants.key))
hi, I think OpenAI change there model for now is :
public struct OpenAI: Codable {
public let object: String
public let model: String
public let choices: [Choice]
}
But i have a .decode error when call api
did you fix it? im having the same problem.
Hello? I have a question because there is a problem. If I add .codex, I won't see the answer to the GPT. It looks like the answer in the video before I add it. May I know the solution?
I got stuck with a strange error :Type 'ViewController' does not conform to protocol 'UITableViewDataSource' and can't find hot to fix it :/
Seems like i did everything identical to the code on the video
If you click the error, theres a little fix button. Your most likely missing required funcitons
Yes, click on the error and it will ask you if you want to enter the "Stub" functions needed. You need to add two tablewiew functions. Review Tableview tutorials to learn about that.
I'm getting the same error, did you figure out the solution?
@@MillerTring Unfortunately I didn't find how to fix it. I didn't understand where and what was wrong
Great video. I wrote the code identical to yours, but the model is returning "nil." Is this because I don't have any credits in my OpenAI account?
Most likely
i've been getting "nil" response too. i did start an OpenAI paid account, and the model worked one time (barely), but now doesn't work at all. I've tried different parameters. have you figured anything out? i'm pretty sure this API is broken.
Great video Sir!
still can't believe the AI thinks android is better than iOS just because of more RAM !
gotta bring him to iOS Academy
😂😂yep
it is not responding, I think it could not set up a request with the api, how can I fix it, it gives failed output when it works.
Amazing!!
Thanks
When i try to add package there is problem: "OpenAISwift could not be resolved". Does anyone know how to fix this problem?
Hm, did you past the url correctly?
I'm also getting this error :(
i am unable to connect API key in my xcode please help me
I can't see the text output from the model on my app, not sure where I went wrong
nice
Thanks
Is there a way to feed a collection of data for the AI to learn from?
Yes. Theres a refining api
It only returns nil for me
What is this technique called (where you initialize and customize an object before assigning it)?
private let field: UITextField = {
let textField = UITextField()
// Customize text field.
return textField
}()
Anonymous closures
@@iOSAcademy thanks!
sir authtoken kese add kiya hua plz reply
2:30 why you write frozen instead of inside enum parameters as static?
because frozen like Elsa
@@jasonjackson55 real mature, thank you for adding value to the world
@@christiansimbarashe do you know work joke?
@@jasonjackson55 Yeah tbh mate I was just upset about some shit at the time, just happened to take it out on a random comment. Don't mind me
@@christiansimbarashe everything is okey bro
Hello, I get the error: "The operation couldn't be completed." Should I wait for the key to be active or is it about something else ?
Probably something else. Check your usage quota
@@iOSAcademy How can I check it ? I am just a begginer sory for it 😅
did you figure this out? having same issue
How to achieve stream in open ai?
Can you use this in an application on the appstore? Has anyone done this yet?
wasn't this api depreciated Dec. 3rd?
It was not
Do it with xcode 16 and swiftui
Theee is no xcode 16 lol
@@iOSAcademy iOS 16*
is there a way to only run this on your local device
Youd need to download the model and write apis - but yes
I built a chatbot in Python that reads a JSON file and answers basic questions about my fictitious business. It it possible do implement this bot in swift? Or is there a better way to just do it in swift
You can do that in swift
@@iOSAcademy yea I understand how to create one that just uses an if else statement. The one with Python used a training file to “teach” the bot it’s words/phrases from a json file then the bot file runs both of those. I’m not sure how Xcode implements this
You should make a video now where you see how much ChatGPT can make this app for you.. I'm sure it won't be totally correct but it would be interesting to see how much you could get from it.
Nice idea
@@iOSAcademy I tried this, check my shorts.
Works ok, but won’t be building apps for you anytime soon. 👍🏻
no chatgpt can't make AI apps cause I've been using it for many things but it won't create anything related to ai
how do you control temperature?
I dont understand your question
@iOS Academy he means the variability/consistancy in the AI response -- They refer to it as "Temperature"
@Duncan it's controllable in the openAI API playground/backend
interesting
Thanks
Did you handle the truncated answer problem? All answers seem to be truncated at some meaningless point!
Yes, there is a maxToken optional (default value) parameter in the function call
@@iOSAcademy oo thanks
My only question is why is Elon Musk in the thumbnail 😂
Bc….he’s elon
why in UIKIt still?
Still industry standard. I have a SwiftUI version here th-cam.com/video/bUDCW2NeO8Y/w-d-xo.html
can you plz share api key here,i am getting response as error
How can I adapt this for a MacOS app instead of iOS?
Exact same code. Just change the view or use SwiftUI
ChatGPT API is free?
Would be amusing if someone built a Twitter replacement using OpenAI's tools.
lol agreed
After 2 questions, ask it "what was my first question"
Give me postman curl here
Coming soon
This would be much easier to build with SwiftUI…
I plan to do a follow up video
@@iOSAcademy nice. Good work by the way. Not putting any damper on your incredible channel! Keep promoting iOS development, the people need it.
I'm starting to use ChatGPT as an assistant and have found it's getting about 60% of the questions right. Anything with complex questions just breaks it. I want to do a video about this. For instance, the bot suggested I do struct MyInt: UInt8 {} when asked to create my own integer type that is like a UInt8, whereas we all know this fails.
I had to figure it out myself using struct MyInt: ExpressibleByInteger {} etc...
2023, UIKit, closures......
All still used in top apps from fb. Google, & tiktok
@@iOSAcademy and also microsoft
I think this video might need an update.
Coming soon
LOL! Android? Really?
lol yep
I am getting nil response
Printing description of model:
▿ OpenAI
- object : nil
- model : nil
- choices : nil
- usage : nil
- data : nil
- results : nil
@iOSAcademy @
This library has been deprecated.
@@alokpandey2303what can we do now?
nice
Thanks
nice
Thanks