[PR #3530] Add n_probs input option and CompletionProbabilities output option #73483

Open
opened 2026-05-05 05:20:40 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/3530
Author: @rnbwdsh
Created: 4/7/2024
Status: 🔄 Open

Base: mainHead: main


📝 Commits (7)

  • 7e0ec98 Add n_probs input option and CompletionProbabilities output option
  • 23c1d59 whitespace change
  • b783746 Merge remote-tracking branch 'origin/main'
  • defec9c Merge remote-tracking branch 'origin/main'
  • a39ad71 Create separate types for CompletionProbability / CompletionProbs -> more DRY code
  • d7468c8 Comment fix
  • 4dc444b Update api/types.go

📊 Changes

4 files changed (+46 additions, -19 deletions)

View changed files

📝 api/types.go (+19 -0)
📝 docs/api.md (+1 -0)
📝 llm/server.go (+24 -19)
📝 server/routes.go (+2 -0)

📄 Description

As requested in #1259 and #2415 and previously implemented in https://github.com/ollama/ollama/pull/1640 (sadly outdated now)

Example request:

curl --request POST \
  --url http://localhost:11434/api/chat \
  --header 'Content-Type: application/json' \
  --header 'User-Agent: insomnium/0.2.3-a' \
  --data '{
  "model": "llama2",
	"messages": [{"role": "user", "content": "Name a fruit. One word.\n"}],
	"options": {
		"n_probs": 3,
		"num_predict": 5
	}
}'

Response (via insonium)

{
	"model": "llama2",
	"created_at": "2024-04-07T23:47:58.488248035Z",
	"message": {
		"role": "assistant",
		"content": "App"
	},
	"done": false
}{
	"model": "llama2",
	"created_at": "2024-04-07T23:47:58.488267614Z",
	"message": {
		"role": "assistant",
		"content": "le"
	},
	"done": false,
	"completion_probabilities": [
		{
			"content": "App",
			"probs": [
				{
					"prob": 1,
					"tok_str": "App"
				},
				{
					"prob": 0.029869306832551956,
					"tok_str": "Ok"
				},
				{
					"prob": 0.006112611852586269,
					"tok_str": " Apple"
				}
			]
		}
	]
}{
	"model": "llama2",
	"created_at": "2024-04-07T23:47:58.503083924Z",
	"message": {
		"role": "assistant",
		"content": ""
	},
	"done": true,
	"completion_probabilities": [
		{
			"content": "App",
			"probs": [
				{
					"prob": 1,
					"tok_str": "App"
				},
				{
					"prob": 0.029869306832551956,
					"tok_str": "Ok"
				},
				{
					"prob": 0.006112611852586269,
					"tok_str": " Apple"
				}
			]
		},
		{
			"content": "le",
			"probs": [
				{
					"prob": 1,
					"tok_str": "le"
				},
				{
					"prob": 0.00002961125210276805,
					"tok_str": "les"
				},
				{
					"prob": 1.3445553292967816e-7,
					"tok_str": "ple"
				}
			]
		},
		{
			"content": "",
			"probs": [
				{
					"prob": 1,
					"tok_str": ""
				},
				{
					"prob": 0.000035882123484043404,
					"tok_str": "."
				},
				{
					"prob": 0.00002135499926225748,
					"tok_str": "!"
				}
			]
		}
	],
	"total_duration": 190160459,
	"load_duration": 568983,
	"prompt_eval_duration": 22957000,
	"eval_count": 3,
	"eval_duration": 38242000
}

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ollama/ollama/pull/3530 **Author:** [@rnbwdsh](https://github.com/rnbwdsh) **Created:** 4/7/2024 **Status:** 🔄 Open **Base:** `main` ← **Head:** `main` --- ### 📝 Commits (7) - [`7e0ec98`](https://github.com/ollama/ollama/commit/7e0ec98d110ecbb413666c8cabcd97cdedd4a3c8) Add n_probs input option and CompletionProbabilities output option - [`23c1d59`](https://github.com/ollama/ollama/commit/23c1d59d622f997b8b32fec3084954e1e0a72765) whitespace change - [`b783746`](https://github.com/ollama/ollama/commit/b783746ee69d5076ce17a789593c25ef362d0e0f) Merge remote-tracking branch 'origin/main' - [`defec9c`](https://github.com/ollama/ollama/commit/defec9ccfadcc9340b9118a646b0a1accd4085a5) Merge remote-tracking branch 'origin/main' - [`a39ad71`](https://github.com/ollama/ollama/commit/a39ad71270b2ea395fbc673ca627d64d38cc4d8f) Create separate types for CompletionProbability / CompletionProbs -> more DRY code - [`d7468c8`](https://github.com/ollama/ollama/commit/d7468c8b12b0d1417d7ceed7032d2fcae7c6393e) Comment fix - [`4dc444b`](https://github.com/ollama/ollama/commit/4dc444bc55beba7fe32db3d6467ddd4d2f5299fe) Update api/types.go ### 📊 Changes **4 files changed** (+46 additions, -19 deletions) <details> <summary>View changed files</summary> 📝 `api/types.go` (+19 -0) 📝 `docs/api.md` (+1 -0) 📝 `llm/server.go` (+24 -19) 📝 `server/routes.go` (+2 -0) </details> ### 📄 Description As requested in #1259 and #2415 and previously implemented in https://github.com/ollama/ollama/pull/1640 (sadly outdated now) Example request: ``` curl --request POST \ --url http://localhost:11434/api/chat \ --header 'Content-Type: application/json' \ --header 'User-Agent: insomnium/0.2.3-a' \ --data '{ "model": "llama2", "messages": [{"role": "user", "content": "Name a fruit. One word.\n"}], "options": { "n_probs": 3, "num_predict": 5 } }' ``` Response (via insonium) ``` { "model": "llama2", "created_at": "2024-04-07T23:47:58.488248035Z", "message": { "role": "assistant", "content": "App" }, "done": false }{ "model": "llama2", "created_at": "2024-04-07T23:47:58.488267614Z", "message": { "role": "assistant", "content": "le" }, "done": false, "completion_probabilities": [ { "content": "App", "probs": [ { "prob": 1, "tok_str": "App" }, { "prob": 0.029869306832551956, "tok_str": "Ok" }, { "prob": 0.006112611852586269, "tok_str": " Apple" } ] } ] }{ "model": "llama2", "created_at": "2024-04-07T23:47:58.503083924Z", "message": { "role": "assistant", "content": "" }, "done": true, "completion_probabilities": [ { "content": "App", "probs": [ { "prob": 1, "tok_str": "App" }, { "prob": 0.029869306832551956, "tok_str": "Ok" }, { "prob": 0.006112611852586269, "tok_str": " Apple" } ] }, { "content": "le", "probs": [ { "prob": 1, "tok_str": "le" }, { "prob": 0.00002961125210276805, "tok_str": "les" }, { "prob": 1.3445553292967816e-7, "tok_str": "ple" } ] }, { "content": "", "probs": [ { "prob": 1, "tok_str": "" }, { "prob": 0.000035882123484043404, "tok_str": "." }, { "prob": 0.00002135499926225748, "tok_str": "!" } ] } ], "total_duration": 190160459, "load_duration": 568983, "prompt_eval_duration": 22957000, "eval_count": 3, "eval_duration": 38242000 } ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-05-05 05:20:41 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#73483