Build An AI ChatBot with OpenAI (Swift, Xcode 14, 2023)

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 ธ.ค. 2024

ความคิดเห็น • 123

  • @iOSAcademy
    @iOSAcademy  2 ปีที่แล้ว +5

    Interested in iOS? Follow linkedin.com/in/afrazsiddiqui

  • @nullptryt
    @nullptryt 9 หลายเดือนก่อน +26

    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!

    • @zeynepsevgi4903
      @zeynepsevgi4903 8 หลายเดือนก่อน +2

      thank you, your comment was very helpful, I could not solve this error.

    • @kareemgordon-graham94
      @kareemgordon-graham94 7 หลายเดือนก่อน +1

      World needs more people like you!

    • @박기철-f2x
      @박기철-f2x 5 หลายเดือนก่อน +1

      thank you!!! you saved me

  • @Andrew-v2g
    @Andrew-v2g 2 ปีที่แล้ว +17

    The short answers were because maxTokens = 16 default. If you change it, the answers will be more.

    • @iOSAcademy
      @iOSAcademy  2 ปีที่แล้ว +5

      I realized afterwards

    • @zs9458
      @zs9458 2 ปีที่แล้ว

      How and where would I adjust this????? 😅

    • @DuncanDay1990
      @DuncanDay1990 2 ปีที่แล้ว +2

      @@zs9458 getResponse function would look like this: "client?.sendCompletion(with: input, model: .codex(.davinci), maxTokens: 50, completionHandler...."

    • @GerardfromMS
      @GerardfromMS 2 ปีที่แล้ว +1

      Yup I was thinking the same thing!

  • @SwatiChoudhary-gf8ut
    @SwatiChoudhary-gf8ut ปีที่แล้ว +2

    having issues running it says APICaller no member of client and cannot not use non optional value of string

  • @AnthonyMarchenko
    @AnthonyMarchenko ปีที่แล้ว +2

    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
    }

  • @opensourceideas
    @opensourceideas 2 ปีที่แล้ว +9

    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

  • @Tenly2009
    @Tenly2009 ปีที่แล้ว +3

    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?

  • @OnionKnight541
    @OnionKnight541 ปีที่แล้ว +14

    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.

    • @JayAA212
      @JayAA212 ปีที่แล้ว

      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?

    • @OnionKnight541
      @OnionKnight541 ปีที่แล้ว +5

      @@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.

    • @JayAA212
      @JayAA212 ปีที่แล้ว +1

      @@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!

    • @salehmasum9419
      @salehmasum9419 ปีที่แล้ว +1

      Was trying this video and getting nil response like many people.

    • @AnthonyMarchenko
      @AnthonyMarchenko ปีที่แล้ว +1

      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
      }

  • @Ronald-v5d
    @Ronald-v5d 3 หลายเดือนก่อน

    Hi, do you have a video about how to integrate gpt-4o API?

  • @md.tipusultan9629
    @md.tipusultan9629 ปีที่แล้ว +1

    My print result Always shows nil. In apicaller.😔

  • @Ward1982
    @Ward1982 2 ปีที่แล้ว +2

    Awesome tutorial. Thank you

    • @iOSAcademy
      @iOSAcademy  2 ปีที่แล้ว

      You are welcome!

  • @merakshot9277
    @merakshot9277 ปีที่แล้ว +8

    Solution: let config = OpenAISwift(config: .makeDefaultOpenAI(apiKey: Constants.key))

  • @RyanProphet
    @RyanProphet ปีที่แล้ว +4

    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

    • @guillermo-ky4vm
      @guillermo-ky4vm ปีที่แล้ว

      did you fix it? im having the same problem.

  • @홍준영-s1q
    @홍준영-s1q ปีที่แล้ว +1

    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?

  • @ribosome8085
    @ribosome8085 ปีที่แล้ว +1

    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

    • @iOSAcademy
      @iOSAcademy  ปีที่แล้ว

      If you click the error, theres a little fix button. Your most likely missing required funcitons

    • @michaelmeinberg2696
      @michaelmeinberg2696 ปีที่แล้ว +1

      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.

    • @MillerTring
      @MillerTring ปีที่แล้ว +2

      I'm getting the same error, did you figure out the solution?

    • @ribosome8085
      @ribosome8085 ปีที่แล้ว +1

      @@MillerTring Unfortunately I didn't find how to fix it. I didn't understand where and what was wrong

  • @AnthonyQin
    @AnthonyQin ปีที่แล้ว +2

    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?

    • @iOSAcademy
      @iOSAcademy  ปีที่แล้ว

      Most likely

    • @OnionKnight541
      @OnionKnight541 ปีที่แล้ว +1

      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.

  • @cozybazaar
    @cozybazaar 2 ปีที่แล้ว +10

    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

  • @zeynepsevgi4903
    @zeynepsevgi4903 8 หลายเดือนก่อน

    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.

  • @thecatdowntheroad369
    @thecatdowntheroad369 2 ปีที่แล้ว +1

    Amazing!!

  • @adilbektursunov3868
    @adilbektursunov3868 2 ปีที่แล้ว +1

    When i try to add package there is problem: "OpenAISwift could not be resolved". Does anyone know how to fix this problem?

    • @iOSAcademy
      @iOSAcademy  2 ปีที่แล้ว

      Hm, did you past the url correctly?

    • @gina-uj5rl
      @gina-uj5rl ปีที่แล้ว

      I'm also getting this error :(

  • @Jubair-o1s
    @Jubair-o1s ปีที่แล้ว

    i am unable to connect API key in my xcode please help me

  • @khennefer
    @khennefer 2 ปีที่แล้ว

    I can't see the text output from the model on my app, not sure where I went wrong

  • @toshisansan
    @toshisansan 2 ปีที่แล้ว +1

    nice

  • @SwimnBird
    @SwimnBird 2 ปีที่แล้ว +1

    Is there a way to feed a collection of data for the AI to learn from?

    • @iOSAcademy
      @iOSAcademy  2 ปีที่แล้ว

      Yes. Theres a refining api

  • @ufohoh
    @ufohoh 3 หลายเดือนก่อน

    It only returns nil for me

  • @foxster.mp4
    @foxster.mp4 2 ปีที่แล้ว +2

    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
    }()

    • @iOSAcademy
      @iOSAcademy  2 ปีที่แล้ว +2

      Anonymous closures

    • @foxster.mp4
      @foxster.mp4 2 ปีที่แล้ว

      @@iOSAcademy thanks!

  • @Jubair-o1s
    @Jubair-o1s ปีที่แล้ว

    sir authtoken kese add kiya hua plz reply

  • @RyokNaruto
    @RyokNaruto 2 ปีที่แล้ว

    2:30 why you write frozen instead of inside enum parameters as static?

    • @jasonjackson55
      @jasonjackson55 2 ปีที่แล้ว

      because frozen like Elsa

    • @christiansimbarashe
      @christiansimbarashe 2 ปีที่แล้ว +1

      @@jasonjackson55 real mature, thank you for adding value to the world

    • @jasonjackson55
      @jasonjackson55 ปีที่แล้ว

      @@christiansimbarashe do you know work joke?

    • @christiansimbarashe
      @christiansimbarashe ปีที่แล้ว

      @@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

    • @jasonjackson55
      @jasonjackson55 ปีที่แล้ว

      ​@@christiansimbarashe everything is okey bro

  • @tufanocak5332
    @tufanocak5332 2 ปีที่แล้ว

    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 ?

    • @iOSAcademy
      @iOSAcademy  2 ปีที่แล้ว

      Probably something else. Check your usage quota

    • @tufanocak5332
      @tufanocak5332 2 ปีที่แล้ว

      @@iOSAcademy How can I check it ? I am just a begginer sory for it 😅

    • @fh03
      @fh03 ปีที่แล้ว

      did you figure this out? having same issue

  • @asadmalik8545
    @asadmalik8545 ปีที่แล้ว

    How to achieve stream in open ai?

  • @BananaPajamaGamer
    @BananaPajamaGamer ปีที่แล้ว

    Can you use this in an application on the appstore? Has anyone done this yet?

  • @jordanw4056
    @jordanw4056 2 ปีที่แล้ว +1

    wasn't this api depreciated Dec. 3rd?

  • @dwayneburrows1390
    @dwayneburrows1390 ปีที่แล้ว +2

    Do it with xcode 16 and swiftui

  • @bigmeatyclaws3966
    @bigmeatyclaws3966 2 ปีที่แล้ว

    is there a way to only run this on your local device

    • @iOSAcademy
      @iOSAcademy  2 ปีที่แล้ว

      Youd need to download the model and write apis - but yes

  • @danielduggin2898
    @danielduggin2898 2 ปีที่แล้ว

    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
      @iOSAcademy  2 ปีที่แล้ว

      You can do that in swift

    • @danielduggin2898
      @danielduggin2898 2 ปีที่แล้ว

      @@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

  • @JeromePullenJr
    @JeromePullenJr 2 ปีที่แล้ว +8

    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.

    • @iOSAcademy
      @iOSAcademy  2 ปีที่แล้ว +5

      Nice idea

    • @petersuvara
      @petersuvara 2 ปีที่แล้ว +2

      @@iOSAcademy I tried this, check my shorts.
      Works ok, but won’t be building apps for you anytime soon. 👍🏻

    • @Assassin_610
      @Assassin_610 2 ปีที่แล้ว

      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

  • @DuncanDay1990
    @DuncanDay1990 2 ปีที่แล้ว

    how do you control temperature?

    • @iOSAcademy
      @iOSAcademy  2 ปีที่แล้ว

      I dont understand your question

    • @mimisbrunnur
      @mimisbrunnur ปีที่แล้ว +1

      ​ @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

  • @abdorizak
    @abdorizak 2 ปีที่แล้ว +1

    interesting

  • @omerkaraca7375
    @omerkaraca7375 2 ปีที่แล้ว

    Did you handle the truncated answer problem? All answers seem to be truncated at some meaningless point!

    • @iOSAcademy
      @iOSAcademy  2 ปีที่แล้ว +1

      Yes, there is a maxToken optional (default value) parameter in the function call

    • @omerkaraca7375
      @omerkaraca7375 2 ปีที่แล้ว

      @@iOSAcademy oo thanks

  • @cellodabest
    @cellodabest ปีที่แล้ว +1

    My only question is why is Elon Musk in the thumbnail 😂

  • @ingongoyama3995
    @ingongoyama3995 2 ปีที่แล้ว

    why in UIKIt still?

    • @iOSAcademy
      @iOSAcademy  2 ปีที่แล้ว +1

      Still industry standard. I have a SwiftUI version here th-cam.com/video/bUDCW2NeO8Y/w-d-xo.html

  • @reddisekhar5790
    @reddisekhar5790 2 ปีที่แล้ว

    can you plz share api key here,i am getting response as error

  • @micahcrandell2540
    @micahcrandell2540 2 ปีที่แล้ว

    How can I adapt this for a MacOS app instead of iOS?

    • @iOSAcademy
      @iOSAcademy  2 ปีที่แล้ว

      Exact same code. Just change the view or use SwiftUI

  • @abdullabardiyev299
    @abdullabardiyev299 6 หลายเดือนก่อน

    ChatGPT API is free?

  • @marcy1546
    @marcy1546 2 ปีที่แล้ว

    Would be amusing if someone built a Twitter replacement using OpenAI's tools.

  • @superertert
    @superertert ปีที่แล้ว

    After 2 questions, ask it "what was my first question"

  • @bhushanrocks412
    @bhushanrocks412 2 ปีที่แล้ว

    Give me postman curl here

  • @petersuvara
    @petersuvara 2 ปีที่แล้ว +2

    This would be much easier to build with SwiftUI…

    • @iOSAcademy
      @iOSAcademy  2 ปีที่แล้ว +1

      I plan to do a follow up video

    • @petersuvara
      @petersuvara 2 ปีที่แล้ว

      @@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...

  • @Jamcoc0s
    @Jamcoc0s 2 ปีที่แล้ว +1

    2023, UIKit, closures......

    • @iOSAcademy
      @iOSAcademy  2 ปีที่แล้ว

      All still used in top apps from fb. Google, & tiktok

    • @Jamcoc0s
      @Jamcoc0s 2 ปีที่แล้ว

      @@iOSAcademy and also microsoft

  • @kal5211
    @kal5211 ปีที่แล้ว

    I think this video might need an update.

  • @ingongoyama3995
    @ingongoyama3995 2 ปีที่แล้ว

    LOL! Android? Really?

  • @alokpandey2303
    @alokpandey2303 7 หลายเดือนก่อน

    I am getting nil response
    Printing description of model:
    ▿ OpenAI
    - object : nil
    - model : nil
    - choices : nil
    - usage : nil
    - data : nil
    - results : nil
    @iOSAcademy @

    • @alokpandey2303
      @alokpandey2303 7 หลายเดือนก่อน

      This library has been deprecated.

    • @bsick6856
      @bsick6856 3 หลายเดือนก่อน

      @@alokpandey2303what can we do now?

  • @victorriurean
    @victorriurean 2 ปีที่แล้ว

    nice

  • @goldfish8196
    @goldfish8196 2 ปีที่แล้ว +1

    nice