Loading...
history.push({ role: 'user', content: input });
const body = { model: MODEL, messages: history, maxTokens: 4096 };history.push({ role: 'user', content: input });
const MAX_OUTPUT = 4096;
while ((await countTokens(history)) + MAX_OUTPUT > CONTEXT_WINDOW) {
history.shift(); // drop the oldest message
}
const body = { model: MODEL, system: SYSTEM_PROMPT, messages: history, maxTokens: MAX_OUTPUT };Old messages are dropped until input plus reserved output fits the window, and instructions live in the system prompt.
Yes. Input and generated output share the context window, so a long prompt leaves less room for the answer.
The API usually rejects the request with a length error, or some apps silently drop the oldest messages.
Not always. Huge prompts cost more, run slower and the model may miss details in the middle, so retrieval is often still better.