[GH-ISSUE #4447] NumCtx can't change, just 2048 #64815

Closed
opened 2026-05-03 18:52:56 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @jianwen-wang on GitHub (May 15, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/4447

What is the issue?

When using the LLaMA 3 model with OpenAI’s /v1/chat/completions API, it was discovered that the request message can’t exceed 2k tokens, while the LLaMA 3 8B model inherently supports up to 8K tokens.

Upon examining the code, it was found that in api/types.go at line 475, DefaultOptions contains a fixed default value of 2048 for NumCtx, and there is no available option to modify this default configuration.

OS

macOS

GPU

Apple

CPU

Apple

Ollama version

0.1.37

Originally created by @jianwen-wang on GitHub (May 15, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/4447 ### What is the issue? When using the LLaMA 3 model with OpenAI’s /v1/chat/completions API, it was discovered that the request message can’t exceed 2k tokens, while the LLaMA 3 8B model inherently supports up to 8K tokens. Upon examining the code, it was found that in api/types.go at line 475, DefaultOptions contains a fixed default value of 2048 for NumCtx, and there is no available option to modify this default configuration. ### OS macOS ### GPU Apple ### CPU Apple ### Ollama version 0.1.37
GiteaMirror added the bug label 2026-05-03 18:52:56 -05:00
Author
Owner

@mxyng commented on GitHub (May 15, 2024):

The OpenAI API spec does not provide a mechanism to set context length. However, if you use the Ollama API, the context length can be set a few ways:

  1. Statically for a model through the Modelfile, e.g. PARAMETER num_ctx 8192
  2. Dynamically during runtime with API options, e.g. {"model": "llama3", "options": {"num_ctx": 8192}}
  3. Dynamically during runtime with client library options, e.g. for Python ollama.chat(model="llama3", options={"num_ctx": 8192})
<!-- gh-comment-id:2112784702 --> @mxyng commented on GitHub (May 15, 2024): The OpenAI API [spec](https://platform.openai.com/docs/api-reference/chat/create) does not provide a mechanism to set context length. However, if you use the Ollama API, the context length can be set a few ways: 1. Statically for a model through the Modelfile, e.g. `PARAMETER num_ctx 8192` 2. Dynamically during runtime with API options, e.g. `{"model": "llama3", "options": {"num_ctx": 8192}}` 3. Dynamically during runtime with client library options, e.g. for Python `ollama.chat(model="llama3", options={"num_ctx": 8192})`
Author
Owner

@wszgrcy commented on GitHub (Aug 2, 2024):

The OpenAI API spec does not provide a mechanism to set context length. However, if you use the Ollama API, the context length can be set a few ways:

  1. Statically for a model through the Modelfile, e.g. PARAMETER num_ctx 8192
  2. Dynamically during runtime with API options, e.g. {"model": "llama3", "options": {"num_ctx": 8192}}
  3. Dynamically during runtime with client library options, e.g. for Python ollama.chat(model="llama3", options={"num_ctx": 8192})

I use num_ctx by /v1/chat/completions but not work
Does this parameter only support the '/app/generate' interface?

<!-- gh-comment-id:2264425558 --> @wszgrcy commented on GitHub (Aug 2, 2024): > The OpenAI API [spec](https://platform.openai.com/docs/api-reference/chat/create) does not provide a mechanism to set context length. However, if you use the Ollama API, the context length can be set a few ways: > > 1. Statically for a model through the Modelfile, e.g. `PARAMETER num_ctx 8192` > 2. Dynamically during runtime with API options, e.g. `{"model": "llama3", "options": {"num_ctx": 8192}}` > 3. Dynamically during runtime with client library options, e.g. for Python `ollama.chat(model="llama3", options={"num_ctx": 8192})` I use `num_ctx` by `/v1/chat/completions` but not work Does this parameter only support the '/app/generate' interface?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#64815