Skip to content

Commit

Permalink
Return number instead of bigint, if it's safe to do so
Browse files Browse the repository at this point in the history
  • Loading branch information
platypii committed Dec 28, 2023
1 parent 650766f commit 5fda7cc
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/hyllama.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export function ggufMetadata(arrayBuffer: ArrayBuffer): Record<string, any> {

const metadata: Record<string, any> = {}
metadata['version'] = version
metadata['tensorCount'] = tensorCount
metadata['tensorCount'] = castNumber(tensorCount)

// initial offset after header
let offset = 24
Expand All @@ -90,3 +90,11 @@ export function ggufMetadata(arrayBuffer: ArrayBuffer): Record<string, any> {

return metadata
}

/**
* Cast a bigint to a number, if it is safe to do so
*/
function castNumber(value: bigint): number | bigint {
if (value > Number.MAX_SAFE_INTEGER) return value
return Number(value)
}

0 comments on commit 5fda7cc

Please sign in to comment.