Part 1 - Learning to build an OpenAI powered assistant for a client

Part 1 - Learning to build an OpenAI powered assistant for a client

I love learning. I hate the idea of stagnating or not getting to play with the latest technology. It fires me up. Of course, in my role as CEO at MiniCorp , I often don’t have a lot of time to dedicate to it, but this weekend I did!

The Challenge

I decided to set myself a challenge. We built a booking flow for a client of ours, Sisu Clinic . Sisu Clinic is a leading aesthetic clinic and they are powered by Phorest Salon Software . In order to book an appointment you need

  • The clinic you’d like to book with
  • The treatment you’d like
  • The date & time of your appointment
  • The provider you’d like to administer the treatment

I want to build an AI assistant that would talk a prospective client through this process but in a fluid way. In the screenshot below, you’ll notice the flow is sequential. You need to select your clinic… then your treatment… then your slot etc.

I want to know, can I get an AI assistant to be fluid about this conversation and answer questions like

  • “Where in Ireland do you offer Jaw-Sculpting?”
  • “Is Botox the same price across all clinics in Ireland?”
  • “Is Brian Cotter working in any clinics in Ireland next week?”

The current Sisu Booking Flow

The Setup

I’m a Ruby on Rails - The Rails Foundation expert for at least 20 years so I’m super fast at it. With an impending deadline, I created a brand new Rails 7 project and set to accomplish my first task

Can I use the turbo frames feature in Rails 7 to display chat like messages?

Turbo frames in Rails 7

That was very achievable and I was off to the races in a few minutes. Next, it was time to set up a nice structure. I set up a model for a Chat and a Message and started with some styling of what this chat window might look like.

I wanted it to feel like there was a person on the other end so I wanted a photo or avatar that conveyed that.

Nicely styled Chat UI

I found the barebones CSS and JS on a Codepen that I should really reference here but I’ve completely lost the link. Sorry! Either way, I heavily edited the CSS to make it more polished. I now had a little dialog and the feeling of chatting with someone on the other end.

Gathering the Data

We have been using the Phorest Salon Software API for some time so it didn’t take long to implement an API service that would sync the branch, categories and service data for Sisu Clinic in Ireland.

Storing this data locally would hopefully speed up the communication with OpenAI and meant we could potentially look at integrating this assistant with any company that uses Phorest.

Adding OpenAI

Here comes the fun! I had never really worked with OpenAI or any LLM before so I’m very much cutting my teeth here.

I set my first goal of simply integrating the Ruby OpenAI gem and having a conversation like you would with OpenAI. Nothing fancy. You can find the OpenAI gem here.

Within the gem, they give some really strong documentation to get up and running and start streaming.

client.chat(
    parameters: {
        model: "gpt-3.5-turbo", # Required.
        messages: [{ role: "user", content: "Describe a character called Anna!"}], # Required.
        temperature: 0.7,
        stream: proc do |chunk, _bytesize|
            print chunk.dig("choices", 0, "delta", "content")
        end
    })
# => "Anna is a young woman in her mid-twenties, with wavy chestnut hair that falls to her shoulders..."
        

Fantastic! I also found this really impressive GitHub Gist that literally walked me through the streaming process. I’d highly recommend a read. A large hat tip to Alex Rudall for this.

Alex's implementation of streaming

Learning the OpenAI structure

Now that I had my UI and integrated OpenAI, it was time to learn the more complicated structures of how OpenAI works. It’s broken down to the following;

  • Assistant The OpenAI assistant API essentially allows you to determine how OpenAI will interact with your application or users.
  • Thread A thread is like a chat. It is a thread of messages to and from OpenAI and contains the messages and any other related information
  • Run Once you had a message to a thread, you then “run” your assistant. The assistant should have the full context of the previous messages.
  • Functions Finally, a function is where you can specify to OpenAI when to request additional information from the application through a function.

All very nice! After learning this, I decided that I should create a new OpenAI thread when a new chat has been created by the user. The thread will be created with my assistant and the context of my assistant has been set to;

OpenAI Assistant

You can spot things like:

  • Once we know the location, we can then run the function get_clinics which will return a list of available clinics and their associated unique_clinic_id.
  • We can get a list of available services at a clinic by providing the unique_clinic_id to the get_services_for_clinic function.

This gives you an idea of how these functions are being called. I have stored all of the clinics and the services the clinics provide locally. I think allow the assistant to call for this information when it needs to. This gives me;

Sequential requests. Asking for a clinic and then services.

Woah! Powerful. Lets keep going! I need the “three dots” to show that the AI is thinking at some point.

It’s still sequential, that’s not good enough

I’m still asking for a clinic and then what services are available. I decided to see if I could then daisy chain requests and could GPT-4 figure it out!

Non-sequential function calling

Next Up

  • It seems slow. When firing both get_clinic and get_clinic_services, it’s too slow. How can I speed this up?
  • Can I book an appointment or see a list of available slots?
  • Add the three dots to show that the AI is thinking

Aidan Kehoe

Build Your Future

10 个月

Hatz AI Brian Kenny Jimmy Hatzell should be able to get this rolling for you

要查看或添加评论,请登录

Brian Kenny的更多文章

  • Transactional Marketing

    Transactional Marketing

    I think we can get lost behind our screens. Sometimes even behind our work.

    4 条评论
  • We've generated €1m for our clients

    We've generated €1m for our clients

    When I started on this journey one Saturday morning I never thought we would get to this place. Today, we have passed a…

    10 条评论
  • Laila has generated €786,744 in 5 months

    Laila has generated €786,744 in 5 months

    Since launching 5 months ago, we've generated over three quarters of a million euros in revenue for our customers. ??…

    3 条评论
  • Who Cares? Rethinking My Relationship with Social Media

    Who Cares? Rethinking My Relationship with Social Media

    I loved Instagram but I’ve stopped posting lately. During my most active time, I would post 10-15 stories on Instagram…

    2 条评论
  • Laila’s Incredible Journey: 280,000 Euros in Bookings in Just 7 Weeks!

    Laila’s Incredible Journey: 280,000 Euros in Bookings in Just 7 Weeks!

    Wow! This has been an adventure. It seems like only yesterday I wrote about how we had just landed our first customer…

    9 条评论
  • The Broken World of Brand Empowered Customer Service

    The Broken World of Brand Empowered Customer Service

    The Magical €10,000 with Revolut I had an issue with my Revolut account recently. A €10,000 transfer had gotten ‘stuck’…

    5 条评论
  • Part 3 - Did I just get my first customer for my AI app!?

    Part 3 - Did I just get my first customer for my AI app!?

    Over the past two weekends and a few late evenings, I’ve been building an AI assistant called Laila. I’ve documented…

    4 条评论
  • Part 2 - An OpenAI Booking Assistant... that can hack itself?

    Part 2 - An OpenAI Booking Assistant... that can hack itself?

    Last weekend, I set myself a challenge of building an AI assistant that would help a prospective client manage their…

    8 条评论
  • Are you a creator or an entrepreneur?

    Are you a creator or an entrepreneur?

    After building over 100 digital businesses, I have seen some succeed and most fail. Why do they fail? In my experience,…

    1 条评论
  • Will people use your idea/app?

    Will people use your idea/app?

    Well hello there wonderful human, When you come up with a fresh idea do you ever think, "would people actually use this…

    1 条评论

社区洞察

其他会员也浏览了