liveBook · Manning

Dialogue

As explained in Data Analysis with LLMs

A message history is an ordered collection of conversational messages representing an interaction with a chat model.

A dialogue is a back-and-forth exchange between a user and a chat model. Its message history includes the latest message and any prior messages supplied as context. The model uses that history to generate a reply, so a follow-up can refer to an earlier request without repeating it. section 3.4 section 2.2

In Python, represent the history as a list of message dictionaries. Each message needs:

  • A `role`: `user` for an input or `assistant` for a model reply. An optional `system` message can give general instructions, such as translating data-set questions into SQL queries. section 3.4
  • A `content` value containing the message. Pass the list as `messages` when requesting a chat completion. section 3.4

Ask for a story

A first request can contain just `{'role': 'user', 'content': 'Tell me a story!'}`. In the ChatGPT interface, a later request can ask for a change to the answer without restating the original prompt. Starting a New Chat instead clears the prior dialogue steps from that conversation. section 3.4 section 2.2

Message histories also serve as fine-tuning examples. For movie-review classification, pair a user message containing a review with an assistant message containing the desired label, such as `neg`. A collection of these successful interactions can be written as JSON-lines training data. section 9.8

{'messages':[
    {'role':'user', 'content':'I am willing to tolerate almost anything 
     ...'},
    {'role':'assistant', 'content':'neg'}
]}

This short history shows both sides of one desired interaction: a review as user input and its label as the assistant output. section 9.8

How Data Analysis with LLMs covers it

How deep it goes
Defines message lists, dictionaries, roles, and content, then shows a completion call and labeled training histories without examining model internals.
Examples
Uses a story request, ChatGPT follow-ups, and a movie review paired with the desired `neg` label.
What it assumes
Introduces message lists, dictionaries, roles, and content before the Python call; begins web dialogue after OpenAI account login.
What you can do after
Apply it via the OpenAI Python library to submit message histories, or build labeled histories for fine-tuning.
How it connects
Connects dialogue to chat completion, prompt context, system instructions, and fine-tuning.

Also explained in

Compare how 10 books explain dialogue →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data Analysis with LLMs. The section links point to the parts of the book it draws on.