liveBook · Manning

Conversational ai

As explained in Build Python Web Apps with Streamlit

A chatbot is a software application that conducts conversational interactions with users through natural-language input and output.

Conversational AI powers chatbots that exchange natural-language messages with users. A simple chatbot sends a prompt to an LLM; a business chatbot can also use private company data and tools. section 1.3.6 section 10.1.3

Customer service chatbot

A customer service chatbot can retrieve company information, help customers track or cancel orders, and escalate problems to a human agent. section 10.0

Listing 1.3 A working AI chatbot in less than 30 lines of code
import os
import streamlit as st
from openai import OpenAI

os.environ["OPENAI_API_KEY"] = "sk-..." # Replace with your own API key
openai = OpenAI()

human_message = lambda m: {"role": "user", "content": m}
ai_message = lambda m: {"role": "assistant", "content": m}

def talk_to_ai(question, history):
    return openai.chat.completions.create(
        model="gpt-5-mini",
        messages=history + [human_message(question)],
    ).choices[0].message.content

st.session_state.history = st.session_state.get("history", [])
history = st.session_state.history

for message in history:
    st.chat_message(message["role"]).markdown(message["content"])

prompt= st.chat_input("Chat with me!")
if prompt:
    st.chat_message("human").markdown(prompt)
    response = talk_to_ai(prompt, history)
    history.extend([human_message(prompt), ai_message(response)])
    st.chat_message("ai").markdown(response)

See a compact Streamlit and OpenAI chatbot example with chat messages and conversation history. section 1.3.6

How Build Python Web Apps with Streamlit covers it

How deep it goes
Demonstrates a short chatbot implementation and outlines retrieval and tool workflows, leaving their backend details for later.
Examples
Uses a short Streamlit chatbot and a customer-service bot for order tracking, cancellations, and human escalation.
What it assumes
Configure an OpenAI API key and install the OpenAI Python module before running the chatbot demonstration.
What you can do after
Build from scratch a Streamlit chat interface, then extend it to answer company-specific questions and perform customer-service actions.
How it connects
Links LLMs and Streamlit chat interfaces with retrieval-augmented generation, vector databases, and tool use.

Also explained in

Compare how 20 books explain conversational ai →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Python Web Apps with Streamlit. The section links point to the parts of the book it draws on.