avatargk_

Summary

The provided content discusses an attempt to automate scheduling using Large Language Models (LLMs) like ChatGPT, in conjunction with software infrastructure such as LangChain, to address the unique and nuanced requirements of business schedules.

Abstract

The article "ChatGPT and LangChain — an attempt at scheduling automation — Part 1 of 3" explores the potential of integrating Large Language Models (LLMs) with specialized software to automate the complex task of managing business schedules. It emphasizes the importance of this use case in the context of front-office job displacement due to the combinatorial effects of messaging apps, LLMs, and reasoning systems. The author argues that while LLMs alone are insufficient for handling schedules, when chained with 'reasoning systems' like programming code, they can interact with internal data systems to perform scheduling tasks. The article outlines a three-part series where the first part examines the limitations of LLMs in scheduling, the second part will focus on creating a structure to chain LLMs with necessary tools, and the third part will evaluate the end result of this integration. The use of LangChain, a framework for developing language model-powered applications, is introduced as a solution to connect LLMs with data and allow for agentic interactions within a program's execution. The article also hints at the use of natural language within program execution as an emerging trend in software development.

Opinions

  • The author believes that the combination of LLMs, messaging apps, and reasoning systems will significantly disrupt front-office jobs.
  • It is expressed that scheduling is inherently complex due to the unique nature of each business's schedule and requires some level of reasoning.
  • The author suggests that LLMs like ChatGPT are currently incapable of managing schedules effectively without integration into a business's internal systems.
  • The article conveys that LangChain can serve as a bridge between LLMs and the data-aware, agentic functions needed for scheduling automation.
  • There is an opinion that the use of natural language within the execution of a software program is a powerful and novel approach, signaling a shift in programming paradigms.
  • The author indicates that the integration of LLMs with scheduling functions will necessitate verbose and descriptive return values to facilitate natural language interaction.

ChatGPT and LangChain — an attempt at scheduling automation — Part 1 of 3

What can we do with a Large Language Model (LLM) and software infrastructure around it to try and automate a schedule? How far can we go? In this first pass we get into it fairly deeply…

Why is this an important use case?

In The massive disruption nobody is talking about, yet. we argued that the combinatorial effect of messaging apps, LLMs and ‘reasoning systems’ would displace most front-office jobs.

… reasoning functionality will inevitably combined with language processing for common front-office functions such as:

  • calendar scheduling
  • pricing questions
  • managing reservations

A work calendar or ‘schedule’ is used by front-office staff to schedule appointments.

Much of the world’s small businesses are service-based and most service based businesses operate from schedules (what service is being provided — for whom — by whom — when).

A large language model is no good at this and ultimately, because most schedules have unique characteristics, because there’s no one unified, standard type of ‘schedule’ there is some reasoning involved.

So today, countless humans manage a business’ schedule on the phone and [increasingly] in messaging threads with customers. Can we automate scheduling? This is a BIG question, not only for it’s practical uses but because it is a harbinger of the front-office automation disruption we are interested in understanding.

What will we be doing in this 3-part series:

Part 1: what can ChatGPT do with schedules? What do we need?

Part 2: creating a structure to ‘chain’ a LLM with the tools it needs

Part 3: examining the end result — the devil is in the details…

Dall-E https://labs.openai.com/

What can Chat GPT do with schedules?

By itself: not much. In fact it is fairly useless. Again there is no such thing as ‘a schedule’ in a standard, unified sense. Every schedule is somewhat unique, ever changing, and nuanced.

Let’s take a simple 5-day schedule and represent it in json format, the date is the key and the (24hour format) hour and client name are the elements:

{'04/11/23': {'15': 'Shane Clark',
  '9': 'Jeffrey Hampton',
  '11': 'Sean Hernandez',
  '12': 'Julie Lopez',
  '14': 'John Walker',
  '17': 'Dennis Wright',
  '13': 'James Leonard',
  '16': 'Natasha Frazier'},
 '04/12/23': {'12': 'Richard Ramos',
  '11': 'Jacob Garza',
  '9': 'Robin Spence',
  '13': 'Rachel Holmes',
  '14': 'Steven Robinson'},
 '04/13/23': {'12': 'Brandy Hernandez',
  '14': 'Christopher Robinson',
  '17': 'Christy Todd',
  '13': 'Bruce Jones',
  '11': 'Mark Joyce'},
 '04/14/23': {'16': 'Stephen Smith',
  '17': 'Shannon Murillo',
  '13': 'Sarah Munoz',
  '15': 'Nathan Parker'},
 '04/15/23': {'12': 'Brittany Brown', '15': 'Rebecca Graham'}}

This is much simpler than most business schedules. We’re only concerned here with whole hours (not partials) and there’s only one client per hour (no multi-booking), also we haven’t blocked off any hours for these days.

Let’s give this to ChatGPT with instructions and see what it can do…

let’s provide the date and ask if we can schedule time today…

let’s try tomorrow:

So there is much confusion already. And of course the LLM cannot really make a reservation to local business systems, it’s not integrated with any.

more confusion and scheduling contradictions:

So this isn’t a fair test, really:

  • a LLM has no way of knowing how a business’ schedule functions or how it is unique from any other scheduling
  • a LLM has no integration into a business’ calendar to create reservations

This should come as no surprise.

In short: scheduling requires some reasoning, it requires integration to internal systems.

https://labs.openai.com/

Where do we begin?

We need a way to connect, or ‘chain’, the LLM (eg. ChatGPT) with ‘reasoning systems’. The best and simplest example of a reasoning system is… programming code. How can we chain our LLM with code that is built to understand something like a business’ schedule? that is built to interface with internal data (a scheduling calendar)?

That is where LangChain comes in.

🦜️🔗 LangChain

LangChain is a framework for developing applications powered by language models. We believe that the most powerful and differentiated applications will not only call out to a language model via an api, but will also:

  1. Be data-aware: connect a language model to other sources of data
  2. Be agentic: Allow a language model to interact with its environment

As such, the LangChain framework is designed with the objective in mind to enable those types of applications.

We need some code that can lookup available times in a schedule (eg. our json structure) and we need code to make a reservation at a given date/time.

We need to chain a LLM with these functions and wrap them into an ensemble that a user can use to interact with them through natural language.

Internal to this type of system, the LLM will use the provided functions to do things with data, moreover it will interpret the return values of these functions to figure out what’s needed. This is a way of using natural language within a program’s execution to make things work.

Before the rise of large language models and their APIs programmers didn’t use natural language within an executing program. Now in this new era it’s beginning to feel like an inevitable path forward.

Natural language used within the execution of a software program is an astonishing thing, we’ll look at this more closely shortly.

Dall-E

The boring stuff

We’ll need some basic code to create and manage a simple schedule. For simplicity sake we’ll store our schedule in json format, as per above.

Here’s a notebook to get a simple schedule setup and organized…

The json schedule data is stored in a schedule.json file. Simple. The names are fake, the times are random, as we go further out there are fewer reservations.

Our function to check available times:

# get available times for a date
def getAvailTimes(date, num=10):
    if '/' not in date:
        return 'date parameter must be in format: mm/dd/yy'
    
    if date not in schedule:
        return 'that day is entirely open, all times are available'
    
    hoursAvail = 'hours available on %s are ' % date
    for h in range(hours[0], hours[1]):
        if str(h) not in schedule[date]:
            hoursAvail += str(h) +':00, '
            num -= 1
            if num == 0:
                break
    
    if num > 0:
        hoursAvail = hoursAvail[:-2] +' - all other times are reserved'
    else:
        hoursAvail = hoursAvail[:-2]
        
    return hoursAvail

And our function to reserve a date/time:

# schedule available time
def scheduleTime(dateTime):
    date, time = dateTime.split(',')
    
    if not date or not time:
        return "sorry parameters must be date and time comma separated, for example: `12/31/23, 10:00` would be the input if for Dec 31'st 2023 at 10am"
    if date not in schedule:
        return 'no schedule available yet for this date'

    # get hours
    if ':' in time:
        timeHour = int(time[:time.index(':')])
        print(timeHour)
        
        if timeHour not in schedule[date]:
            if timeHour >= hours[0] and timeHour <= hours[1]:
                schedule[date][timeHour] = fake.name()
                saveSchedule()
                return 'thank you, appointment scheduled for %s under name %s' % (time, schedule[date][timeHour])
            else:
                return '%s is after hours, please select a time during business hours' % time
        else:
            return 'sorry that time (%s) on %s is not available' % (time, date)
    else:
        return '%s is not a valid time, time must be in format hh:mm'

Notice that the return values are all quite verbose and descriptive. This is not normal for an internal function. We need this because we’ll be using these functions as tools within our chain and the LLM will be interacting with these using natural language.

In Part 2:

We will be setting up our Langchain, it will define these schedule functions as ‘tools’ for the LLM to use in answering questions. We will be describing in natural language how the LLM needs to interact with these tools, their expected input parameters, etc.

We’ll explore a built-in tool called ‘PAL’ which provides the LLM with a ‘chain’ to resolve problems by writing Python code. This is a fascinating new development you can read about here: https://reasonwithpal.com/ and a Cornell University research paper you can read here.

Also using LangChain we’ll instantiate our LLM (OpenAI) and provide it our API key.

We’ll use https://streamlit.io to make a simple web app to demonstrate the new interface.

In short: we’ll write a few lines of code (besides the calendar utility functions) that take natural language questions from a user and use a language ‘chain’ to resolve them. The answer may emerge and when it does it’s the product of:

  • calling internal functions (tools) using natural language to understand how they need to be called and how to interpret their responses
  • using a LLM to make sense of language used in talking about schedules
  • accessing and storing business data (a schedule) via existing functions

Part 2…

AI
ChatGPT
Langchain
Python
OpenAI
Recommended from ReadMedium