Zum Inhalt springen
PeakPrivacyDocs
AnwendenVerwaltenEinführenSicherheit & DatenschutzEntwickler

Conversations and system prompts

Hold multi-turn conversations, write system prompts that work and keep the history short, with a chatbot loop in Python and JavaScript.

Als Markdown anzeigen

A chat completion takes a list of messages and returns the next one. To continue a conversation, you send the whole history with each request. A system prompt steers the answers, and a short history keeps long conversations fast and affordable.

The examples use gpt-swiss Schweiz, which answered in one to three seconds in our tests. Any model from Models works the same way. All examples were run against the live API on 11.11.2026.

Message roles

RoleWritten byUse it for
systemYou, the developerStanding instructions: who the model is, tone, format, limits. Send it first.
userYour userThe question, or the text the model should work on.
assistantThe modelEarlier answers. You send them back so that the model knows what it already said.
toolYour codeThe result of a function call, see tools in Request body.

Write instructions as system, not developer. In our tests, developer worked on some models and returned 500 on others, for example mistral-small-swiss.

Multi-turn conversations

The API is stateless: it doesn't remember earlier requests. Every request must carry the whole conversation so far, oldest message first. To continue, append the model's answer as an assistant message, append the next user message, and send the full list again.

The second turn of the conversation, with the first answer in the history:

curl https://api.peakprivacy.ch/v1/ai/chat/completions \
  -H "Authorization: Bearer $PEAKPRIVACY_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -d '{
    "model": "gpt-swiss",
    "messages": [
      {"role": "system", "content": "You are the internal assistant of Alpenblick Treuhand AG. Write short, friendly English."},
      {"role": "user", "content": "Draft a one-sentence reminder for Luca: the Q3 report for Seeblick GmbH is due on 15 October."},
      {"role": "assistant", "content": "Hi Luca, just a friendly reminder that the Q3 report for Seeblick GmbH is due on 15 October."},
      {"role": "user", "content": "Make it more formal and add that Nadia can help."}
    ]
  }'

Output of the Python and JavaScript versions:

1: Hi Luca, just a friendly reminder that the Q3 report for Seeblick GmbH is due on 15 October.
2: Please be reminded that the Q3 report for Seeblick GmbH is due on 15 October, and should you require assistance, Nadia is available to help.

The second answer still names Seeblick GmbH and the date because both are in the history. Without the first two messages, the model wouldn't know which reminder you mean.

Because your code holds the history, you decide what the model sees. You can store it in your own database, shorten or edit it before the next request, or send it to a different model.

Send back only role and content of an answer. Reasoning models also return reasoning_content (Reasoning), but the next turn doesn't need it.

System prompts that work

A good system prompt settles five things:

  • Role and audience. Who the model is and for whom it works.
  • Task and limits. What it should do and what it should leave alone.
  • Format. Length, language, tone, lists or prose.
  • Uncertainty. What to do when it doesn't know: say so, ask back, or point to a person.
  • Facts. The model knows nothing about your organisation. Give it the names, rules and deadlines it needs.

The help desk below uses this prompt:

You are the internal help desk of Alpenblick Treuhand AG, a fiduciary firm in Zurich.
Answer in at most three sentences.
If a question needs company-specific facts you don't have, say so and suggest asking Mira in Office Management.
  • Be concrete. "At most three sentences" works better than "be brief".
  • Separate rules from material. Rules go in the system prompt, the text to work on goes in a user message.
  • Test with real questions, including the ones the model should decline or hand over.
  • Assume users can read it. Users can often get a model to repeat its system prompt, so keep secrets out.
  • Keep personal data out. "anonymize": true doesn't process system messages, see Anonymisation.

Temperature

temperature sets how much answers vary, from 0 to 2. The default is 0.7.

ValueGood for
0 to 0.3Help desk answers, extraction, classification
0.7Everyday writing
1 and aboveBrainstorming, several variants of a text

Even at 0, two runs of the same request can give different answers. Some models ignore temperature or use a fixed value, see Request body.

Keep the history short

Every request sends the whole history again, so every turn costs more input tokens than the one before. In the help desk session below, usage.prompt_tokens grew from 121 to 223 in three short turns. Long histories also slow down answers, and a history longer than the model's context window fails with 400 or, depending on the model, 500, see The model rejects the request.

  • Keep the last messages. Send the system prompt plus the most recent messages. The chatbot below keeps 20.
  • Summarise older turns. Ask the model for a short summary of the conversation so far and send it instead of the older messages.
  • Start over when the topic changes.
  • Send long documents once. Include a document only in the turn that needs it, not in every later request.

A chatbot in the terminal

A complete help desk bot: it reads questions from the terminal, keeps the history, trims it and prints the prompt size after each answer. Type exit or an empty line to quit.

import os

from openai import OpenAI

client = OpenAI(
    base_url="https://api.peakprivacy.ch/v1/ai",
    api_key=os.environ["PEAKPRIVACY_API_KEY"],
)

MODEL = "gpt-swiss"
SYSTEM_PROMPT = (
    "You are the internal help desk of Alpenblick Treuhand AG, a fiduciary firm in Zurich. "
    "Answer in at most three sentences. "
    "If a question needs company-specific facts you don't have, say so and suggest asking Mira in Office Management."
)
MAX_MESSAGES = 20  # recent messages to keep, besides the system prompt


def trim(history):
    """Keep the system prompt and the most recent messages, starting with a user message."""
    recent = history[1:][-MAX_MESSAGES:]
    while recent and recent[0]["role"] != "user":
        recent.pop(0)
    return history[:1] + recent


messages = [{"role": "system", "content": SYSTEM_PROMPT}]

while True:
    question = input("You: ").strip()
    if question in ("", "exit"):
        break

    messages.append({"role": "user", "content": question})
    messages = trim(messages)

    completion = client.chat.completions.create(model=MODEL, messages=messages, temperature=0.3)
    answer = completion.choices[0].message.content
    messages.append({"role": "assistant", "content": answer})

    print(f"Bot: {answer}")
    print(f"     ({completion.usage.prompt_tokens} prompt tokens)\n")

A session:

You: Draft a two-line out-of-office note for Nadia. She is back on 20 October.
Bot: I’m currently out of the office and will return on 20 October. For urgent matters, please contact Mira in Office Management.
     (121 prompt tokens)

You: Now the same in German.
Bot: Ich bin derzeit nicht im Büro und bin ab dem 20. Oktober wieder erreichbar.
Für dringende Angelegenheiten wenden Sie sich bitte an Mira in der Office Management.
     (165 prompt tokens)

You: Who do I ask about parking at our office?
Bot: I don’t have the specific contact for parking inquiries on hand—please ask Mira in Office Management, who can point you to the right person.
     (223 prompt tokens)

You: exit

"Now the same in German" works only because the earlier note is in the history. The third answer follows the system prompt's rule for unknown company facts.

For a bot that shows the answer while it is written, see Streaming.

Good to know

  • One history per conversation. Requests are independent, so conversations only mix if your code mixes them. Key each history by user and session.
  • Your application holds the history. Store, protect and delete it like any other user data.
  • German answers use ss. Chat completion answers have ß replaced by ss.
  • Failed requests. If a request fails, your list ends with an unanswered question. After a 429, a 500 or a network error, send the same list again with backoff, see Retries. If the model rejected the request, for example because the history is too long, shorten the history before you send it again.

See also

Auf dieser Seite