avatargk_

Summary

The web content discusses an attempt to automate scheduling by integrating ChatGPT with LangChain, detailing the technical setup and the significance of this use case for future automation and disruption in front-office jobs.

Abstract

The article "ChatGPT and LangChain — an attempt at scheduling automation — Part 2 of 3" delves into the practical application of Large Language Models (LLMs) like ChatGPT, combined with software infrastructure, to automate scheduling tasks. It emphasizes the importance of this use case as a precursor to the broader impacts of automation on front-office roles, as previously argued in a related article. The piece outlines the creation of a structured 'chain' using LangChain's tools and chains, including the PALChain for resolving word problems related to dates and times. It provides a step-by-step explanation of setting up the necessary code, defining tools with natural language descriptions, and integrating them into a Streamlit web application. The article concludes by setting the stage for Part 3, where the scheduling system's performance will be evaluated, highlighting the expectation of both impressive successes and notable failures.

Opinions

  • The authors believe that the combination of messaging apps, LLMs, and reasoning systems will significantly disrupt front-office jobs.
  • Scheduling is presented as a complex task for machines, involving both language understanding and reasoning.
  • The article suggests that the described scheduling automation is a harbinger of broader advancements and disruptions in the job market.
  • The use of LangChain's PALChain is highlighted as a novel approach to solving 'word problems' related to scheduling.
  • The authors express that while the scheduling automation system has potential, it is expected to have both successful outcomes and areas where it will struggle, indicating an awareness of the current limitations of automation technology.

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

What can we do with an LLM and software infrastructure around it to try and automate a schedule? In this part we get into the thick of it…

created w/Dall-E

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. It’s worth exploring this particular use case as a harbinger of the advancements (and disruption) ahead.

In some ways ‘scheduling’ is both a language and reasoning problem, so basic (in human terms) but so nuanced and complex (for machine).

“can I schedule an appointment for this Wednesday at 2?”

“are there times available tomorrow at 13:00? or 14:00?”

“when can I reserve time later this week?”

What we are covering in this 3-part series:

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

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

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

Creating our Language ‘Chain’

The complete code to our scheduling test rig is here:

We’ll examine it piece by piece:

First, the necessary imports: (install as needed)

from langchain import OpenAI
from langchain.agents import initialize_agent, Tool
from langchain.chains import PALChain
from langchain.chains.conversation.memory import ConversationBufferMemory
from langchain import PromptTemplate, LLMChain

import streamlit as st

You’ll notice here the following: (please read up before proceeding, these are new concepts)

OpenAI (no introduction needed here), we’ll use this as our LLM

Tool: https://python.langchain.com/en/latest/modules/agents/tools.html

PALChain: https://python.langchain.com/en/latest/modules/chains/examples/pal.html

Memory: https://python.langchain.com/en/latest/modules/memory.html

LLMChain: https://python.langchain.com/en/latest/modules/chains/generic/llm_chain.html

We’ll skip over the schedule utility functions, covered in Part 1.

Next we setup our first chain: (I’ve changed the API key, insert your own)

os.environ['OPENAI_API_KEY'] = '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'


llm = OpenAI(temperature=0, verbose=True)
pal_chain = PALChain.from_math_prompt(llm, verbose=True)

This instantiates our llm and creates a PALChain which we can use to resolve ‘word problems’ such as ‘7 days from now’. We’ll refer to this PAL chain in our tools definition…

tools = [
 Tool(
  name = "today's date",
  func = lambda string: todayDate(),
  description="use to get today's date",
  ),
 Tool(
  name = 'available appointments',
  func = lambda string: getAvailTimes(string),
  description="Use to check on available appointment times for a given date. The input to this tool should be a string in this format mm/dd/yy. This is the only way for you to answer questions about available appointments. This tool will reply with available times for the specified date in 24hour time, for example: 15:00 and 3pm are the same.",
  ),
 Tool(
  name = 'schedule appointment',
  func = lambda string: scheduleTime(string),
  description="Use to schedule an appointment for a given date and time. The input to this tool should be a comma separated list of 2 strings: date and time in format: mm/dd/yy, hh:mm, convert date and time to these formats. For example, `12/31/23, 10:00` would be the input if for Dec 31'st 2023 at 10am",
  ),
 Tool(
        name = "PAL",
        func = pal_chain.run,
        description = "useful for when you need to answer questions about math or word problems or date comparisons"
  )
 ]

Here we define the ‘tools’ our chain will be able to use. 4 tools:

  • a simple Python function for today’s date
  • our scheduling utility functions described in Part 1
  • our PAL chain

Notice that each uses a lambda do describe the interface, but more significantly note that each tool offers a natural language description of how it’s to be used. This is similar to a prompt, it must be worded carefully.

Notice that a tool can itself be a chain… chains within chains.

Finally we instantiate our chain:

memory = ConversationBufferMemory(memory_key="chat_history")

if 'agent_memory' not in st.session_state:
 st.session_state['agent_memory'] = ConversationBufferMemory(memory_key='chat_history')

agent_chain = initialize_agent(tools, llm, agent='zero-shot-react-description', memory=st.session_state['agent_memory'], verbose=True)

Memory is defined (read the memory docs with link above) for more details. We instantiate the streamlit (st) session state and we initialize our agent_chain.

For details on session state within streamlit.io see: https://docs.streamlit.io/library/api-reference/session-state

agent_chain = initialize_agent(tools, llm, agent='zero-shot-react-description', memory=st.session_state['agent_memory'], verbose=True)

verbose=True will provide us details of how things are working internally…

Another new concept: ‘Agent’, read mode here: https://python.langchain.com/en/latest/modules/agents.html

And finally out streamlit web app setup:

st.header(":gray[Langchain chatbot with Python function tools for schedule]")
user_input = st.text_input("You: ")

if st.button('Submit'):
 print('user_input:', user_input)

 st.markdown(agent_chain.run(input=user_input))
 #print(st.session_state['agent_memory'])

#comment out the printing of session state but feel free to enable that…

Get all this setup on your system and follow me to part 3…

Dall-E

Next in Part 3:

We will be experimenting with this scheduling rig to see what it does, how it does it, what it fails to do, etc.

There will be times where we will be impressed! and other times where it will fail pathetically.

We have to start somewhere…

Part 3…

AI
ChatGPT
Langchain
Python
OpenAI
Recommended from ReadMedium