Skip to content

browser/interfaces: add logprobs#260

Merged
BruceMacD merged 3 commits intomainfrom
parth/logprobs
Nov 12, 2025
Merged

browser/interfaces: add logprobs#260
BruceMacD merged 3 commits intomainfrom
parth/logprobs

Conversation

@ParthSareen
Copy link
Member

@ParthSareen ParthSareen commented Nov 12, 2025

Adds JS SDK support for: ollama/ollama#12899

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove the logprobs-generate.ts example since the code is largely the same as chat.

images?: Uint8Array[] | string[]
keep_alive?: string | number // a number (seconds) or a string with a duration unit suffix ("300ms", "1.5h", "2h45m", etc)
think?: boolean | 'high' | 'medium' | 'low'
logprobs?: boolean
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add these fields in the README also

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good callout! will add

Comment on lines +1 to +11
import { Ollama } from 'ollama';

function printLogprobs(entries: Array<{ token: string; logprob: number; top_logprobs?: typeof entries }>, label: string) {
console.log(`\n${label}:`)
for (const entry of entries) {
console.log(` token=${entry.token.padEnd(12)} logprob=${entry.logprob.toFixed(3)}`)
for (const alt of entry.top_logprobs ?? []) {
console.log(` alt -> ${alt.token.padEnd(12)} (${alt.logprob.toFixed(3)})`)
}
}
}
Copy link
Member

@BruceMacD BruceMacD Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { Ollama } from 'ollama';
function printLogprobs(entries: Array<{ token: string; logprob: number; top_logprobs?: typeof entries }>, label: string) {
console.log(`\n${label}:`)
for (const entry of entries) {
console.log(` token=${entry.token.padEnd(12)} logprob=${entry.logprob.toFixed(3)}`)
for (const alt of entry.top_logprobs ?? []) {
console.log(` alt -> ${alt.token.padEnd(12)} (${alt.logprob.toFixed(3)})`)
}
}
}
import { Ollama, type Logprob } from 'ollama';
function printLogprobs(entries: Logprob[], label: string) {
console.log(`\n${label}:`)
for (const entry of entries) {
console.log(` token=${entry.token.padEnd(12)} logprob=${entry.logprob.toFixed(3)}`)
for (const alt of entry.top_logprobs ?? []) {
console.log(` alt -> ${alt.token.padEnd(12)} (${alt.logprob.toFixed(3)})`)
}
}
}

Copy link
Member

@BruceMacD BruceMacD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@BruceMacD BruceMacD merged commit c3b668c into main Nov 12, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants