How I Use OpenAI Assistants API To Control My Streamlit App

Sdílet
Vložit
  • čas přidán 31. 05. 2024
  • Seen the OpenAI Dev Day Wanderlust Assistants API demo and wondering how to implement a similar web app in full Python? It's all thanks to the new Assistants API feature and its integrated Function Calling.
    In this video, I prototype a Streamlit version of the app. Through this quick overview, you'll learn to:
    - leverage Streamlit's Session State for a clean reactive app using an MVC-like pattern
    - configure an OpenAI Assistant API 's Function calling feature to have OpenAI talk with your app by mapping user intent to predefined functions
    - layout a chatbot and Plotly map through columns and configured by Streamlit secrets
    At the end of this video, you will be able to interactively experiment with the new Assistants API through a Streamlit app and have natural language control the flow of your app.
    00:00 Intro
    00:45 Python App Skeleton
    01:55 Configure GPT to generate code?
    03:24 Everything in Session State
    05:23 Session State is Everything
    06:31 GPT-4 Controls Everything
    08:28 The Last Stretch
    10:21 Easy Peasy
    📧 Want a free, slower paced live coding of this tutorial? Sign up to my email list to be alerted first, and keep up to date with the latest news, tutorials and resources about Streamlit & friends ➡ andfanilo-newsletter.streamli...
    💰 Buy me a coffee to stay awake while editing www.buymeacoffee.com/andfanilo
    🗣️ Find my socials on andfanilo.com
    🔗 Links
    - Source Code: github.com/andfanilo/social-m...
    - How Language Model Hallucinations Can Snowball: arxiv.org/abs/2305.13534
    - Someone did ask about open-sourcing the demo: community.openai.com/t/openai...
    👉 My tools (Affiliate links to support me!)
    - 📷 Main Camera - amzn.to/3QvTosB
    - 📷 Main Lens - amzn.to/3svYCwq
    - 🎙️ Microphone - amzn.to/47l5ewA
    - 🎵 Music & Sound Effects - www.epidemicsound.com/referra...
    - 📕 Streamlit Official Book - amzn.to/3QuRPwl
    ______
    🪶 I tried my hand at motion graphics & design in this video, and I'm quite happy with the result, plus it was a lot of fun! I hope you liked the small animations too, let me know in the comments I want to keep improving this
    ⚠️ Disclaimer: I receive no compensation by any brand quoted in this video. Views are my own and do not represent my employer's.
    Links included in this description might be affiliate links. If you purchase a product or service with the links that I provide I may receive a small commission. Thank you for supporting my channel so I can continue providing you with free content!
    #streamlit #python #datascience #dataapps

Komentáře • 44

  • @MMABeijing
    @MMABeijing Před 4 měsíci +1

    In my opinion you have the best resources on youtube, and your style is unparalleled. What a talent you are Sir

    • @andfanilo
      @andfanilo  Před 3 měsíci

      Wow, thank you, I appreciate the support ☺️

  • @PaulBenthamcom
    @PaulBenthamcom Před 6 měsíci +1

    Your videos are real hidden gems, thanks for the explanations here 👍

    • @andfanilo
      @andfanilo  Před 6 měsíci

      Thank you for the kind words 😌 hope to keep seeing you around!

  • @kenchang3456
    @kenchang3456 Před 6 měsíci

    Fascinating, thanks for the detail. And BTW, you hit the right amount of humor, I was smiling through most of the video 🙂

    • @andfanilo
      @andfanilo  Před 6 měsíci

      Thank you for the support, greatly appreciated :)
      I had loads of fun doing this video, I'm happy I managed to pass a smile and some teachings at the same time!

  • @Hitchon
    @Hitchon Před 6 měsíci +1

    Wow really great job ! I love your editing & teaching style, made the tutorial fun to watch! Keep it up :)

    • @andfanilo
      @andfanilo  Před 6 měsíci

      Oh, thank you very much for the supportive feedback ☺️ I'm taking a small break but I'll be back soon, so I hope to see you on the next one!
      Any subject in particular you wanted to see covered one day :) ?

    • @Hitchon
      @Hitchon Před 6 měsíci

      @@andfanilo I’m somewhat new to streamlit, something on session states would be really helpful

    • @tgauss
      @tgauss Před 5 měsíci

      I second this comment. Your style is fast, fun and informative! Appreciate your great content and sharing your expertise.

  • @silkogelman
    @silkogelman Před 6 měsíci

    👏👏👏🤩 Great tutorial, thank you Fanilo!
    Time for some experimentation 🎉

    • @andfanilo
      @andfanilo  Před 6 měsíci +1

      Ahah, I feel you always have so many AI platform experimentations running XD do you share them somewhere ?

    • @silkogelman
      @silkogelman Před 6 měsíci

      @@andfanilo most of them are proof of concepts and experiments, not sure if that code should see the light of day 😅
      I like exploring AI ideas, but they are less than half of what I experiment with.

  • @matthewcover8748
    @matthewcover8748 Před 6 měsíci

    stoked I stumbled upon your channel, Fanilo 🔥

    • @andfanilo
      @andfanilo  Před 6 měsíci

      Happy to hear that! Thanks for the support and hope to keep seeing you here :)

  • @ibrahimsaidi7239
    @ibrahimsaidi7239 Před 5 měsíci

    Awesome tutorial

    • @andfanilo
      @andfanilo  Před 5 měsíci

      Thanks for watching :) hope to see you in the next one!

  •  Před 6 měsíci +1

    Amazing video as always, loved the animations too! which tool did you use to create them?

    • @andfanilo
      @andfanilo  Před 6 měsíci +2

      Thanks for the support :) I've been learning a lot more After Effects recently, and it was a really fun process! I think I can definitely pass more complex boring information from those when I get the hang of it

  • @mikew2883
    @mikew2883 Před 6 měsíci

    Good stuff! 👍

    • @andfanilo
      @andfanilo  Před 6 měsíci +1

      Thanks for the support, hope to keep seeing you around :)

    • @mikew2883
      @mikew2883 Před 6 měsíci

      Absolutely! Just stumbled across your channel and definitely a subscriber now!
      @@andfanilo

    • @andfanilo
      @andfanilo  Před 6 měsíci +1

      ...you're right I totally forgot about them
      I documented them in the README: github.com/andfanilo/social-media-tutorials/tree/master/20231116-st_assistants (there's also all the code for markers, especially at the plotly part)

  • @samsquamsh78
    @samsquamsh78 Před 6 měsíci +2

    I really like your videos, you always have good topics, creative solutions and add humor to them🙂 for me though (a beginner at python and coding in general), you move a bit too fast. It would be great to see a video where you go from start to finish, as you code live in a speed which is okay for less seasoned developers. but, I understand if that is not your target audience. keep it up!

    • @andfanilo
      @andfanilo  Před 6 měsíci +4

      Hello! Thanks for the support and for sharing your thoughts in a positive way 🙂
      I have thought about the pacing and difficulty of my videos a lot recently, as more and more beginners stumble on my videos as I grow. I hope I can inspire them to keep coding and improving until they're able to understand a more complex use case video of mine in one take, but I also totally understand it can be very frustrating for people who just want to code at a slower pace (actually even intermediate developers would need to pause at 2-3 points of this video and criticize how fast I am in some difficult parts and I would totally agree, I'm still improving my pacing skills ^^ )
      It's not that I don't want to target beginners, it's rather I haven't found a format I'm comfortable with doing for beginners. There are 2 things that make me not do it right now:
      - I feel there is already a lot of "live coding beginner-friendly" CZcams videos out there, for example just typing "Assistants API", and you have 10-15 CZcamsrs who break down code in a notebook slowly, and I don't really want to compete with them
      - Ok the real reason is, I myself never learn by live coding with a video tutorial. I prefer reading books and reimplementing with blog posts instead, and only watch project overview videos rather than live-coding sessions...so I don't record "live-coding" videos because I can't seem to learn and benefit from those.
      Maybe I could write small blog posts with my videos (like what I did for streamlit-components-tutorial.netlify.app/ ) so after watching the video to get a first grasp of what the project is about, you can live-code with the blog post at the pace you want by reading the blog post, would that sound like a good compromise?
      Or maybe I could...do live code sessions of my complex videis like this one but only accessible through a newsletter or for paying members of my CZcams community. For a financial incentive, I could force myself to do it.
      Anyway, that was a very unstructured brainstorming answer, I hope it makes sense 😆

    • @samsquamsh78
      @samsquamsh78 Před 5 měsíci

      @@andfanilo many thanks and much appreciated. I understand the dilemma of pacing and target audience. We have all different ways of learning, and you should probably stick to your beliefs. I will continue watching even though I may not be able to keep the pace up, but i can take inspiration from it😊👍

  • @emilbalis5010
    @emilbalis5010 Před 6 měsíci

    Very good :)))

    • @andfanilo
      @andfanilo  Před 6 měsíci

      Thanks for the support 😃 I hope you’ll keep watching what’s next!

  • @syenza
    @syenza Před 6 měsíci

    Great video, thanks. Do you take on private clients to assist with implementing the above and other projects?

    • @andfanilo
      @andfanilo  Před 6 měsíci +1

      Hello,
      Currently not, as I'm juggling this channel with a fulltime job and being an university lecturer. I'm open to giving advice during 1 hour Zoom calls when I have some time but that's it for now. What are you trying to build?
      Have a nice day!

  • @camino_interior
    @camino_interior Před 5 měsíci

    Thank you very much for your videos. They are very useful for my learning.
    I made an app in streamlit to manage a parking lot, without knowing that streamlit does not have any functionality to send a print with a form_submit_button. My app needs to print a ticket to give to the customer when they leave the car. Do you have any solution for that?

    • @andfanilo
      @andfanilo  Před 5 měsíci +1

      Hello!
      Yeah Streamlit doesn't have any functionality about that, you'll probably need to bring custom Python code & library. Like, are you able to build your own small PDF from data in the Streamlit app with PyPDF2, export as PDF and have a user download it with st.download_button or send that PDF via email? Or send that PDF to a remote Cloud location and a Cloud service that reacts to any new file added there to print it physically? I don't know much about Cloud Printing services though...
      sorry for the very quick brainstorming, those were my immediate unfiltered first thoughts, hope it helps a little

    • @camino_interior
      @camino_interior Před 5 měsíci

      @@andfanilo Thank you very much for your reply. I'm trying with an api that connects to the printer locally. When I have the solution I will share it.

    • @camino_interior
      @camino_interior Před 5 měsíci

      @@andfanilo Would something work?
      import streamlit as st
      import serial
      # Create an instance of the serial.Serial object to communicate with the printer.
      ser = serial.Serial(
      port='/dev/ttyUSB0', # Port to which the printer is connected
      baudrate=9600, # Printer baud rate
      parity=serial.PARITY_NONE, # Printer parity
      stopbits=serial.STOPBITS_ONE, # Printer stop bits
      timeout=1 # Printer wait time (in seconds)
      )
      # Write data to the printer.
      # Obtain the data you want to print from the Streamlit interface
      data = st.text_input('Data to print')
      # Encode the data into a byte string
      data_bytes = data.encode('utf-8')
      # Write the data to the printer
      ser.write(data_bytes)
      # Close the instance of the serial.Serial object when finished using it.
      ser.close()

  • @rockNbrain
    @rockNbrain Před 6 měsíci

    Fanilo is a real rockstar 🎸

    • @andfanilo
      @andfanilo  Před 6 měsíci +1

      🎸 I need to do some live touring at conferences then, like real rockstars ahah, what's the conference/meetup near your location :p ?
      Thanks for the support ^^

    • @rockNbrain
      @rockNbrain Před 6 měsíci

      @@andfanilo Brazil, please come! Lmfao

    • @andfanilo
      @andfanilo  Před 6 měsíci

      Keeping it in mind :)

  • @abdollahchelasi1477
    @abdollahchelasi1477 Před 6 měsíci

    Please teach a streamlit project for hotel reservation

    • @andfanilo
      @andfanilo  Před 6 měsíci

      Hello, what do you mean by "hotel reservation" ?

  • @abdulmanan8432
    @abdulmanan8432 Před 5 měsíci

    to much overacting

    • @andfanilo
      @andfanilo  Před 5 měsíci

      🕺 too bad, I guess my channel won't be for you then
      Have a nice day!