NCA-GENL - Software Development - Section 2.5

Write application code for generative tasks and chatbot applications.

Write application code that calls a generative model API, constructs prompts, and handles streaming or batch responses for tasks such as text generation, summarisation, and chatbot dialogue. Understand how to manage conversation history, control generation parameters like temperature and top-p, and integrate safety filters into an end-to-end application.

Practice question for this objective

Free sampleSoftware Developmentmedium

A developer is building a chatbot that must remember the last five exchanges. When constructing the messages array for each new API call, which approach correctly implements a sliding-window conversation history?

  • AAppend every new user and assistant turn to the messages list indefinitely, relying on the model to ignore older turns automatically.
  • BKeep the system message at index 0, then retain only the most recent ten messages (five user and five assistant turns), dropping the oldest pair first when the limit is reached. Correct
  • CStore only the last user message and the last assistant reply, discarding all earlier turns, so the model always receives exactly two messages plus the system prompt.
  • DPlace all historical turns before the system message in the messages array, then append the current user message at the end to give the model full context.
Understand how to manage conversation history in a chatbot by maintaining a bounded, correctly ordered messages array for LLM API calls. LLM inference APIs expect a structured messages array where the system message occupies position 0, followed by alternating user and assistant turns. A sliding-window strategy retains a fixed number of recent turns and removes the oldest pair when the limit is exceeded, keeping the payload within the model's context window while preserving coherent multi-turn context.

Why A is wrong: Tempting because it is the simplest implementation and some models do tolerate long contexts, but context windows have fixed token limits; indefinite growth will eventually cause the API to reject the request or silently truncate early turns, breaking conversation continuity.

Why B is correct: The system message provides persistent instructions and must stay in position 0; retaining the last ten role-alternating messages gives exactly five exchanges while bounding token consumption. Dropping the oldest pair first preserves chronological coherence and prevents context overflow.

Why C is wrong: Tempting because it guarantees a small payload and zero overflow risk, but limiting history to one exchange means the model cannot resolve references to earlier turns, producing incoherent multi-turn dialogue despite the chatbot appearing to respond.

Why D is wrong: Tempting because ordering history before the current question feels intuitive, but most inference APIs require the system message to be the first element; placing it after history violates the expected schema and will typically return a validation error.

See more NCA-GENL practice questions, answers explained.

More in this domain

Back to all Software Development objectives, or the NCA-GENL cert hub.

Examworthy is not affiliated with or endorsed by NVIDIA. Original, blueprint-aligned practice material only.