# ollama: Resolve context window size via API \(\#39941\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/3d5ddcccf08ea4d421b11474cf1190fc6bb1b4a1)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 3d5ddcccf08ea4d421b11474cf1190fc6bb1b4a1

Requested commit: 3d5ddcccf08ea4d421b11474cf1190fc6bb1b4a1

Commit: 3d5ddcccf08ea4d421b11474cf1190fc6bb1b4a1

Tree: 4670fc867a341ac36f38decd3abb0d5589752f54

Author: Bennet Bo Fenner

Committer: GitHub

## Message

````
ollama: Resolve context window size via API (#39941)

Previously we were guessing the context window size here:
https://github.com/zed-industries/zed/blob/8c3f09e31e3588a2494042dfe77bb3dccab1f7ba/crates/ollama/src/ollama.rs#L22

This is inaccurate and must be updated manually. This PR ensures that we
extract the context window size from the request in the same way that
the Ollama CLI does when running `ollama show <model-name>` (Relevant
code is
[here](https://github.com/ollama/ollama/blob/3d32249c749c6f77c1dc8a7cb55ae74fc2f4c08b/cmd/cmd.go#L860))

The format looks like this:

```json
{
  "model_info": {
    "general.architecture": "llama",
    "llama.context_length": 132000
  }
}
```

Once this PR is merged we could technically remove the old code
https://github.com/zed-industries/zed/blob/8c3f09e31e3588a2494042dfe77bb3dccab1f7ba/crates/ollama/src/ollama.rs#L22
I decided to keep it for now, as it is unclear if the necessary fields
are available via the API on older Ollama versions.

Release Notes:

- Fixed an issue where Ollama models would use the wrong context window
size
````

## Parents

- [4dae3a15cc4f9bdd5189c23e71385d8a0ff07665](https://git.cafe/gitcafe/zed/commit/4dae3a15cc4f9bdd5189c23e71385d8a0ff07665?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/3d5ddcccf08ea4d421b11474cf1190fc6bb1b4a1?format=markdown)
