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

Поділитися
Вставка
  • Опубліковано 3 гру 2024

КОМЕНТАРІ • 123

  • @iOSAcademy
    @iOSAcademy  2 роки тому +5

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

  • @nullptryt
    @nullptryt 8 місяців тому +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 7 місяців тому +2

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

    • @kareemgordon-graham94
      @kareemgordon-graham94 6 місяців тому +1

      World needs more people like you!

    • @박기철-f2x
      @박기철-f2x 4 місяці тому +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

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

    • @GerardfromMS
      @GerardfromMS Рік тому +1

      Yup I was thinking the same thing!

  • @merakshot9277
    @merakshot9277 11 місяців тому +8

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

  • @opensourceideas
    @opensourceideas Рік тому +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

  • @Ward1982
    @Ward1982 Рік тому +2

    Awesome tutorial. Thank you

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

  • @Ronald-v5d
    @Ronald-v5d 3 місяці тому

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

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

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

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

  • @thecatdowntheroad369
    @thecatdowntheroad369 2 роки тому +1

    Amazing!!

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

  • @SwatiChoudhary-gf8ut
    @SwatiChoudhary-gf8ut Рік тому +2

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

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

    • @amgadalamin5805
      @amgadalamin5805 Рік тому

      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

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

    • @amgadalamin5805
      @amgadalamin5805 Рік тому +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
      }

  • @toshisansan
    @toshisansan 2 роки тому +1

    nice

  • @SwimnBird
    @SwimnBird Рік тому +1

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

  • @Jubair-o1s
    @Jubair-o1s Рік тому

    sir authtoken kese add kiya hua plz reply

  • @dwayneburrows1390
    @dwayneburrows1390 Рік тому +2

    Do it with xcode 16 and swiftui

  • @md.tipusultan9629
    @md.tipusultan9629 Рік тому +1

    My print result Always shows nil. In apicaller.😔

  • @홍준영-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?

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

  • @abdorizak
    @abdorizak 2 роки тому +1

    interesting

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

  • @asadmalik8545
    @asadmalik8545 Рік тому

    How to achieve stream in open ai?

  • @jordanw4056
    @jordanw4056 Рік тому +1

    wasn't this api depreciated Dec. 3rd?

  • @BananaPajamaGamer
    @BananaPajamaGamer Рік тому

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

  • @bigmeatyclaws3966
    @bigmeatyclaws3966 Рік тому

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

    • @iOSAcademy
      @iOSAcademy  Рік тому

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

  • @DuncanDay1990
    @DuncanDay1990 Рік тому

    how do you control temperature?

    • @iOSAcademy
      @iOSAcademy  Рік тому

      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

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

  • @khennefer
    @khennefer 2 роки тому

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

  • @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 Рік тому

      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

  • @ufohoh
    @ufohoh 2 місяці тому

    It only returns nil for me

  • @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  Рік тому

      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

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

  • @cellodabest
    @cellodabest Рік тому +1

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

  • @zeynepsevgi4903
    @zeynepsevgi4903 7 місяців тому

    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.

  • @ingongoyama3995
    @ingongoyama3995 Рік тому

    why in UIKIt still?

    • @iOSAcademy
      @iOSAcademy  Рік тому +1

      Still industry standard. I have a SwiftUI version here ua-cam.com/video/bUDCW2NeO8Y/v-deo.html

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

  • @omerkaraca7375
    @omerkaraca7375 Рік тому

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

    • @iOSAcademy
      @iOSAcademy  Рік тому +1

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

    • @omerkaraca7375
      @omerkaraca7375 Рік тому

      @@iOSAcademy oo thanks

  • @micahcrandell2540
    @micahcrandell2540 Рік тому

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

    • @iOSAcademy
      @iOSAcademy  Рік тому

      Exact same code. Just change the view or use SwiftUI

  • @marcy1546
    @marcy1546 Рік тому

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

  • @abdullabardiyev299
    @abdullabardiyev299 5 місяців тому

    ChatGPT API is free?

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

  • @reddisekhar5790
    @reddisekhar5790 Рік тому

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

  • @superertert
    @superertert Рік тому

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

  • @bhushanrocks412
    @bhushanrocks412 2 роки тому

    Give me postman curl here

  • @Jamcoc0s
    @Jamcoc0s Рік тому +1

    2023, UIKit, closures......

    • @iOSAcademy
      @iOSAcademy  Рік тому

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

    • @Jamcoc0s
      @Jamcoc0s Рік тому

      @@iOSAcademy and also microsoft

  • @kal5211
    @kal5211 Рік тому

    I think this video might need an update.

  • @ingongoyama3995
    @ingongoyama3995 Рік тому

    LOL! Android? Really?

  • @alokpandey2303
    @alokpandey2303 6 місяців тому

    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 6 місяців тому

      This library has been deprecated.

    • @bsick6856
      @bsick6856 3 місяці тому

      @@alokpandey2303what can we do now?

  • @victorriurean
    @victorriurean 2 роки тому

    nice

  • @goldfish8196
    @goldfish8196 2 роки тому +1

    nice