VereskLearn

Module 1 · Talking to a model

Lesson 1.1

One model call

A model call sends a list of messages in and gets one piece of text back.

Lesson 3 of 622 min read

The problem

Why it matters

Without it

A program sends one bare question. The model has no instructions, no earlier turns, and no source text to use.

With it

The program sends a list: instructions, earlier turns, and the new question. The reply follows from that whole list.

How it works

  • The request is a list of messages

    A request to a model is a list of messages. Each message has a role, which says who wrote it, and content, which holds the text. There are three roles: system, user, and assistant. This lesson sends two messages, a system rule and a user question.

    RoleContent
    systemAnswer only from the FAQ.
    userHow long does a refund take?
    The two messages sent in the first request.
    type Role = "system" | "user" | "assistant";type Message = { role: Role; content: string }; const messages: Message[] = [  { role: "system", content: "Answer only from the FAQ." },  { role: "user", content: "How long does a refund take?" },];console.log("Messages ->", messages.length);console.log("First role ->", messages[0].role);

    Output

    Messages -> 2
    First role -> system
  • The model reads the whole list

    The model reads the full list on every call and returns one text reply. It keeps no record of earlier calls. The reply depends only on the messages in that request, so both the rule and the question shape the answer.

    1. System rule
    2. User question
    3. Model
    4. Reply text
    The two messages go in together, and one reply text comes out.
    // A stand-in for the model. It reads only the last message.function fakeModel(messages: { content: string }[]): string {  const text = messages[messages.length - 1].content;  if (text.includes("refund")) {    return "Refunds take 5 to 7 business days.";  }  return "I do not know.";}const q = "How long does a refund take?";console.log("Reply ->", fakeModel([{ content: q }]));

    Output

    Reply -> Refunds take 5 to 7 business days.
  • The reply is plain text

    The reply is one string of text, with no role attached. The program shows it to the user or passes it on. For this question, the reply is "Refunds take 5 to 7 business days." The model can be wrong, so the reply still needs a check.

  • Memory needs the earlier messages again

    Each request stands alone. A follow-up such as "Does it cover gift cards?" makes no sense without the first question. To continue a chat, the program stores the reply as an assistant message and sends the whole list again.

    First request

    • 2 messages: system and user

    Second request

    • 3 messages: system, user, and assistant
    • The stored reply is sent again
    The list grows by one message after each reply.
    type Message = { role: string; content: string };const messages: Message[] = [  { role: "system", content: "Answer only from the FAQ." },  { role: "user", content: "How long does a refund take?" },];messages.push({  role: "assistant",  content: "Refunds take 5 to 7 business days.",});console.log("Last role ->", messages[messages.length - 1].role);

    Output

    Last role -> assistant

Full code

Read the program

See the full code

Common mistakes

What goes wrong

  • Expecting the model to remember earlier calls. Send the earlier turns again in every request.
  • Putting the instructions in the user message. Keep them in the system message, so they stay separate from the question.
  • Treating the reply as checked. The model can be wrong, so test its answers.

Use it when and skip it when

Is it the right tool?

Use it when

  • You want one answer to a question, based on text you send with it.
  • You are building a chat that must remember earlier turns.

Skip it when

  • A fixed answer is enough. A lookup table is simpler, cheaper, and always gives the same result.
  • You need the exact same text every time. Model replies can vary, as lesson 1.3 shows.

Words to know

Terms in this lesson

Message
One item in the list sent to a model, with a role and some content.
Role
The label on a message: system, user, or assistant.
System message
Instructions that set how the model should answer.
Request
One call that sends messages to a model and waits for a reply.
Full code