Repository navigation
Replies: 4 comments 1 reply
|
The Python SDK does not know the context window. Token limits live in model docs, not in the API. Anything you "get from Python" is a table you maintain (or a library that maintains one). LiteLLM, Practical options: from openai import OpenAI
client = OpenAI()
model = client.models.retrieve("gpt-4") # no context length here
There is no supported |
|
Worth adding to the answer above: the object still will not tell you. What changed is the size of the numbers. Per the model pages, both Two limits that bite in practice. Both models reject I put the two models, the pricing rules and a small script that prices a request before you send it here: https://maxpertise.net/blog/gpt-6-2-astra-and-sol Affiliation: I work at Maxpertise, the site hosting that guide. |
|
The OpenAI Python SDK currently does not expose a model’s context-window size through A practical solution is to maintain a configuration mapping using the limits published in the official model documentation: # Historical example for the original GPT-4 model.
# This is application configuration, not metadata fetched from the API.
MODEL_CONTEXT_WINDOWS = {
"gpt-4": 8192,
}
def get_context_window(model: str) -> int:
if model not in MODEL_CONTEXT_WINDOWS:
raise ValueError(
f"No configured context window for {model!r}. "
"Check its official model documentation."
)
return MODEL_CONTEXT_WINDOWS[model]
print(get_context_window("gpt-4")) # 8192For your original example, GPT-4’s documented context window is 8,192 tokens, rather than exactly 8,000. GPT-4 is now listed as shut down, so this example only illustrates the lookup approach. Also, distinguish the context window from the maximum output tokens: they are separate constraints. Use the documentation for the exact model/version you plan to use, and update your configuration when changing models. References:
|
Uh oh!
There was an error while loading. Please reload this page.
Is it possible to see through openai library or other way how many maximum tokens can be in a model, for example gpt-4? I need to find out the maximum number of tokens in a model using python code.
For example, gpt-4 has a maximum of 8000 tokens, how can I get this number from the python code?
All reactions