repo_name string | dataset string | owner string | lang string | func_name string | code string | docstring string | url string | sha string |
|---|---|---|---|---|---|---|---|---|
biomes-game | github_2023 | ill-inc | typescript | CollisionHelper.intersect | static intersect(
boxes: BoxesIndex,
table: SpatialTable,
worldMetadata: ReadonlyWorldMetadata,
aabb: AABB,
fn: CollisionCallback
) {
// Test if the box intersects any of the terrain shards.
CollisionHelper.intersectAABB(boxes, aabb, fn);
// Test if the box intersects any entities.
... | // Does a general AABB intersection test against the terrain and entities. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/game/collision.ts#L98-L111 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | blockToolDps | function blockToolDps(block: Item | undefined, tool: Item | undefined) {
return baseDps(tool) * affinityDpsMultiplier(block, tool);
} | // Returns the DPS that the given tool will deal to the given block. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/game/damage.ts#L65-L67 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | affinityDpsMultiplier | function affinityDpsMultiplier(
block: Item | undefined,
tool: Item | undefined
): number {
const affinity = blockToolAffinity(block, tool);
switch (affinity) {
case "hand":
return 0.714;
case "none":
return 0.833;
case "preferred":
return 1.666;
}
} | // Certain combinations of blocks and tools can be more effective, get the | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/game/damage.ts#L79-L92 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | findBestRefForMerge | function findBestRefForMerge(
inventory: ReadonlyInventory,
itemAndCount: ReadonlyItemAndCount,
{
partialOk,
noHotbar,
noInventory,
}: {
partialOk?: boolean;
noHotbar?: boolean;
noInventory?: boolean;
},
used?: Set<string>
): MergeIndex | undefined {
const combinableAmount = partia... | // Find the best ref for merge, returning the reference as well | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/game/inventory.ts#L264-L334 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | BatteryItemBuilder.addCharge | addCharge(power: number): number {
const chargeAdded = Math.min(this.chargeUntilFull(), power);
this.battery.charge += chargeAdded;
return power - chargeAdded;
} | // Adds charge to a battery and returns any access power that could not be consumed. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/game/robot.ts#L108-L112 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | BatteryItemBuilder.pullCharge | pullCharge(power: number): number {
const chargeRemoved = Math.min(this.charge(), power);
this.battery.charge -= chargeRemoved;
return power - chargeRemoved;
} | // of the charge that was removed. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/game/robot.ts#L116-L120 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | BatteryItemBuilder.build | build(): ItemAndCount {
const { item, count } = this.itemAndCount;
return countOf(
item.id,
{
[attribs.batteryCapacity.id]: this.battery.capacity,
[attribs.batteryCharge.id]: this.battery.charge,
},
count
);
} | // Apply changes and create a new entity. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/game/robot.ts#L123-L133 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | intersectRayEntity | function intersectRayEntity(
from: ReadonlyVec3,
dir: ReadonlyVec3,
entity: ReadonlyEntity
): RayIntersection | undefined {
const entityAabb = getAabbForEntity(entity);
if (!entityAabb) {
return undefined;
}
return intersectRayAabb(from, dir, entityAabb);
} | // If the ray intersects the entity, return the point of intersection, otherwise | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/game/spatial.ts#L137-L148 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | OnDemandBuffered.get | get(): TBuffer {
if (this.#materialized === undefined) {
const blob = this.blob;
const backing = blob
? this.spec.blobToBacking(this.voxeloo, blob)
: undefined;
this.#materialized = {
buffer: this.spec.backingToBuffer(this.voxeloo, backing),
dirty: false,
};
... | // Get the buffer, creating it off the backing object if needed. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/game/terrain/on_demand_buffers.ts#L93-L106 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | OnDemandBuffered.abandon | abandon() {
this.#newBlob = undefined;
if (this.#materialized !== undefined) {
this.#materialized.buffer.abandon();
}
} | // Abandon any buffered changes. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/game/terrain/on_demand_buffers.ts#L127-L132 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | OnDemandBuffered.commit | commit() {
if (this.#newBlob !== undefined) {
this.spec.save(this.voxeloo, this.entity, this.#newBlob);
this.#blob = this.#newBlob;
} else if (
this.#materialized !== undefined &&
this.#materialized.buffer.dirty
) {
this.#materialized.buffer.commit();
this.#materialized.d... | // Commit the buffered changes to the backing object. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/game/terrain/on_demand_buffers.ts#L135-L146 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | OnDemandBuffered.finish | finish() {
// We do not need to handle newBlob here as it is directly
// committed.
this.#newBlob = undefined;
if (this.#materialized === undefined) {
return;
}
try {
if (this.#materialized.dirty) {
this.spec.save(
this.voxeloo,
this.entity,
this... | // Finish, calling the save routine on the backing object if needed. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/game/terrain/on_demand_buffers.ts#L156-L174 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | ReadonlyTerrain.involved | protected get involved() {
return getLazyObjectMaterializedValues(this.buffers);
} | // All involved fields, to simplify the below. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/game/terrain/terrain.ts#L147-L149 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | typedPredicate | function typedPredicate<T extends string, V extends z.ZodTypeAny>(
kind: T,
value: V
) {
return z.object({
kind: z.literal(kind),
value,
invert: z.boolean().optional(),
});
} | // Numerical predicates can be queried with min/max, or a specific value | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/loot_tables/predicates.ts#L12-L21 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | square | function square(t: number) {
return t * t;
} | // Reference: https://gist.github.com/Fonserbc/3d31a25e87fdaa541ddf | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/math/easing.ts#L3-L5 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | sampleGaussianPolar | function sampleGaussianPolar(variance: number) {
// Convert from [0,1) -> (0,1], so we can safely take the logarithm of u1.
const u1 = 1 - Math.random();
const u2 = Math.random();
return {
magnitude: Math.sqrt(-2 * Math.log(u1) * variance),
angle: 2 * Math.PI * u2,
};
} | // Sample from a Gaussian distribution using the Box-Muller transform. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/math/gaussian.ts#L18-L27 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | Timer.elapsedOr | elapsedOr<R>(value: R) {
return this.start !== TimerNeverSet ? this.elapsed : value;
} | // Return the elapsed time, or an alternative value if nonfinite. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/metrics/timer.ts#L11-L13 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | collisionIndex | const collisionIndex = ([v0, v1]: AABB, fn: HitFn) => {
CollisionHelper.intersect(
(id) => env.resources.get("/physics/boxes", id),
env.table,
metadata,
[v0, v1],
(hit: AABB, entity?: ReadonlyEntity) => {
// Avoid self-intersections.
if (!entity || entity.id !== npc.id)... | // Define the intersection testing routine. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/npc/logic.ts#L193-L206 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | SimulatedNpc.lockedInPlace | get lockedInPlace(): boolean {
return Boolean(this.entity.lockedInPlace());
} | // Read-only state access. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/npc/simulated.ts#L59-L61 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | SimulatedNpc.setEmote | setEmote(emote: Emote) {
this.entity.setEmote(emote);
} | // Mutators. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/npc/simulated.ts#L109-L111 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | getPositionAhead | function getPositionAhead({
npc,
distance,
}: {
npc: SimulatedNpc;
distance: number;
}) {
const direction = npc.velocity;
return add(
npc.position,
scale(distance, normalizev([direction[0], 0, direction[2]]))
);
} | // Gets the position of the entity `distance` blocks ahead of where it is heading. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/npc/behavior/fly.ts#L177-L189 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | AStarPathfinder.heuristic | private heuristic(node: Node): number {
return dist(node.position, this.dest.position);
} | // Euclidean distance heuristic. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/npc/behavior/pathfinding.ts#L271-L273 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | SocializingNpc.findNewFriend | findNewFriend(): BiomesId | undefined {
let candidates = this.findNearbyCandidateFriends();
candidates = candidates.filter((npcId) => {
return npcId !== this.state.previousFriend && npcId !== this.state.friend;
});
// Select a random friend out of the pool of candidates.
return sample(candid... | // Finds a new friend out a list of candidate friends. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/npc/behavior/socialize.ts#L182-L191 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | SocializingNpc.findPathToFriend | findPathToFriend(): Path | undefined {
const src = this.npc.position;
const graph = new GraphImpl();
const srcNode = graph.closestNode(src);
const friendPosition = this.friendPosition();
if (!friendPosition) {
return undefined;
}
const destNode = graph.closestNode(friendPosition);
... | // Generate a path to the Npc's friend. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/npc/behavior/socialize.ts#L221-L243 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | SocializingNpc.justMetFriend | justMetFriend(): boolean {
if (
this.state.meetingTime !== undefined ||
this.state.friend === undefined
) {
// Npc just met friend or doesn't have a friend to meet.
return false;
}
const friend = this.env.resources.get("/ecs/entity", this.state.friend);
const friendPosition ... | // Predicate to check if an NPC just met its friend. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/npc/behavior/socialize.ts#L246-L258 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | SocializingNpc.moveTowardsFriend | moveTowardsFriend(): number {
ok(this.state.pathfinding?.path);
const target = findNextTargetOnPath(
this.npc.position,
this.state.pathfinding.path
);
if (target === undefined) {
return 0;
}
this.lookAt(target);
return this.npc.type.walkSpeed;
} | // Moves the NPC towards it's friend. Returns the speed the Npc moves. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/npc/behavior/socialize.ts#L261-L275 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | SocializingNpc.lookAt | lookAt(target: ReadonlyVec3) {
const targetVector = sub(target, this.npc.position);
const angleToFriend = yaw(targetVector);
if (angleToFriend !== this.npc.state.rotateTarget) {
this.npc.mutableState().rotateTarget = angleToFriend;
}
} | // Rotate to face the target. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/npc/behavior/socialize.ts#L278-L285 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | getDepthInWater | function getDepthInWater({
npc,
env,
maxDepthToCheck,
}: {
npc: SimulatedNpc;
env: Environment;
maxDepthToCheck: number;
}): number {
// Create a box column above the entity and see how much of it is filled with water.
const anchor = npc.position;
const columnWidth = 0.25;
const collisionBox: AABB =... | // Determines how deep in water the entity is. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/npc/behavior/swim.ts#L137-L164 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | collisionAlongAxis | function collisionAlongAxis(
index: CollisionIndex,
aabb: AABB,
impulse: Readonly<Vec3>,
axis: 0 | 1 | 2
) {
// Calculate the minimum axial vector required to prevent collision.
let repulsion = 0;
index(aabb, ([v0, v1]) => {
if (impulse[axis] >= 0) {
repulsion = absMax(repulsion, v0[axis] - aabb... | // The below function finds the first point of collision along an axis-aligned | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/physics/constraints.ts#L22-L40 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | intersectX | const intersectX = (x: number) => {
return intersecting(index, shiftAABB(aabb, [x, 0, 0]));
}; | // Helper routines to test for an intersection. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/physics/forces.ts#L49-L51 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | BiomesNodeCollector.setOptionForPath | setOptionForPath<P extends PathMap<P>, K extends Key<P>>(
path: K,
options: BiomesResourceAddOptions<Ret<P, K>>
) {
this.pathToOption.set(path, options);
} | // paths. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/resources/biomes.ts#L173-L178 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | BiomesResourcesBuilder.addWithCache | addWithCache<K extends Key<P>, C>(
path: K,
createCacheFn: (
...args: [TypedResourceDeps<P>, C | undefined, ...Args<P, K>]
) => C,
createFn: (...args: [TypedResourceDeps<P>, C, ...Args<P, K>]) => Ret<P, K>,
options?: BiomesResourceAddOptions<Ret<P, K>>
) {
const cachePath = `/cache${path... | // main resource, but is not publicly accessible. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/resources/biomes.ts#L239-L273 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | doNothing | function doNothing() {} | // Define this globally so that it doesn't unexpectedly retain any context. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/resources/core.ts#L27-L27 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | withResolved | const withResolved = (resolved: Resolve<T>) => {
this.resolved = resolved;
if (isDisposable(this.resolved)) {
this.disposer = this.resolved.dispose.bind(this.resolved);
this.resolved.dispose = doNothing;
}
this.deps = onReady(this);
if (this.count == 0) {
this.dispo... | // Wait until the new value is finished being built. After which, we set | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/resources/core.ts#L48-L58 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | Node.stale | stale() {
return !this.value || this.value.version < this.request;
} | // up-to-date. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/resources/core.ts#L197-L199 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | NodeMap.get | get(path: Arg[], idx = 0): Node<unknown> | undefined {
ok(path.length > idx);
const key = normalizeKey(path[idx]);
const value = this.contents.get(key);
if (value instanceof NodeMap) {
return value.get(path, idx + 1);
} else if (idx === path.length - 1) {
return value;
}
} | // Get a Node by key, or undefined if not present. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/resources/core.ts#L316-L325 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | NodeMap.delete | delete(path: Arg[], idx = 0): boolean {
ok(path.length > idx);
const key = normalizeKey(path[idx]);
const value = this.contents.get(key);
if (value instanceof NodeMap) {
if (value.delete(path, idx + 1)) {
this.size -= 1;
if (value.size === 0) {
this.contents.delete(key);
... | // Delete a node by key, return true if actually deleted. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/resources/core.ts#L328-L349 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | NodeMap.set | set(path: Arg[], value: Node<unknown>, idx = 0): boolean {
ok(path.length > idx);
const key = normalizeKey(path[idx]);
if (idx === path.length - 1) {
const oldSize = this.contents.size;
this.contents.set(key, value);
if (oldSize !== this.contents.size) {
this.size += 1;
ret... | // Set a key to a given value, return true if this key did not previously exist. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/resources/core.ts#L352-L379 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | NodeMap.clear | clear() {
this.contents.clear();
this.size = 0;
} | // Clear all values. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/resources/core.ts#L382-L385 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | distinctArrayMatches | function distinctArrayMatches(values: any[], matchers: Matcher[]) {
return internalDistinctArrayMatches(
values,
matchers,
new DefaultMap(
(matcher) => new DefaultMap((i) => matches(matcher, values[i]))
),
[]
);
} | // Returns true if matcher matches precisely one of the values. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/triggers/matcher.ts#L12-L21 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | Latch.wait | wait(ms = Infinity): Promise<boolean> {
return new Promise<boolean>((resolve) => {
if (this.signalled) {
resolve(true);
return;
}
const done = () => {
resolve(this.signalled);
removeValue(this.resolveFns, done);
if (timeout) {
clearTimeout(timeout)... | // Wait, optionally with a timeout. Returns true if the latch was signalled. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/util/async.ts#L102-L118 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | TaskPriorityQueue.maybeEnableOrDisableScheduling | private maybeEnableOrDisableScheduling() {
if (!this.setIntervalId && this.schedulingNeeded()) {
this.setIntervalId = setInterval(() => {
this.reprioritize();
this.triggerNextTasks(
this.options.maxTaskCount - this.runningTasksCount
);
});
} else if (this.setInterva... | // there is no scheduling work to be done. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/util/async.ts#L395-L408 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | TaskPriorityQueue.schedulingNeeded | private schedulingNeeded(): boolean {
return this.queuedTaskCount > 0;
} | // Are there active tasks to be run? | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/util/async.ts#L411-L413 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | TaskPriorityQueue.reprioritize | private reprioritize() {
const batchCount = Math.min(
this.options.maxReprioritizeBatch,
this.reprioritizeQueue.size
);
for (let i = 0; i < batchCount; ++i) {
const [task] = this.reprioritizeQueue;
this.reprioritizeQueue.delete(task);
const newPriority = task.priorityFn();
... | // priorities have changed since they were queued or previously reprioritized. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/util/async.ts#L417-L439 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | FixedRateTicker.advanceClock | advanceClock(now: number, intervalMs: number, maxTicks?: number) {
const prevTime = this.curTime;
this.curTime = now;
const endTick = this.timeToTicks(this.curTime, intervalMs);
const startTick = this.timeToTicks(prevTime, intervalMs);
let diffTicks = endTick - startTick;
if (diffTicks > 1) {
... | // and returns the number of ticks that have occurred in between. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/util/fixed_rate_ticker.ts#L35-L54 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | now | function now() {
return performance.now();
} | // TODO: Figure out how to make these routines use a simulation time instead of system time. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/util/throttling.ts#L4-L6 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | InternalMessagePortCall.write | async write(response: any) {
if (this.controller.signal.aborted) {
return;
}
return this.port.postMessage([this.reqId, prepare(response)]);
} | // Write a response, can be called many times for streaming responses. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/zrpc/messageport_server.ts#L57-L62 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | InternalMessagePortCall.status | status(status: grpc.status, details?: string) {
if (this.controller.signal.aborted) {
return;
}
this.controller.abort();
try {
this.port.postMessage([this.reqId, status, details ?? ""]);
} catch (error) {
if (grpc.isStatusObject(error) && error.code === grpc.status.CANCELLED) {
... | // Send a status code, this terminates the call. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/zrpc/messageport_server.ts#L65-L84 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | InternalMessagePortCall.run | async run(path: string, handler?: MessagePortCallHandler) {
try {
if (handler === undefined || !isFunction(handler)) {
throw new RpcError(grpc.status.UNIMPLEMENTED);
}
if (this.controller.signal.aborted) {
return;
}
this.inflight = handler(this);
await this.inflig... | // appropriate counters. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/zrpc/messageport_server.ts#L102-L116 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
shikiji | github_2023 | antfu | typescript | dimColor | function dimColor(color: string) {
const hexMatch = color.match(/#([0-9a-f]{3})([0-9a-f]{3})?([0-9a-f]{2})?/)
if (hexMatch) {
if (hexMatch[3]) {
// convert from #rrggbbaa to #rrggbb(aa/2)
const alpha = Math.round(Number.parseInt(hexMatch[3], 16) / 2)
.toString(16)
.padStart(2, '0')
... | /**
* Adds 50% alpha to a hex color string or the "-dim" postfix to a CSS variable
*/ | https://github.com/antfu/shikiji/blob/fc923646e2a450e8d929598ea99d9fed96cbb657/packages/shikiji-core/src/code-to-tokens-ansi.ts#L64-L91 | fc923646e2a450e8d929598ea99d9fed96cbb657 |
shikiji | github_2023 | antfu | typescript | StackElementMetadata.getLanguageId | public static getLanguageId(metadata: number): number {
return (metadata & MetadataConsts.LANGUAGEID_MASK) >>> MetadataConsts.LANGUAGEID_OFFSET
} | // } | https://github.com/antfu/shikiji/blob/fc923646e2a450e8d929598ea99d9fed96cbb657/packages/shikiji-core/src/stack-element-metadata.ts#L79-L81 | fc923646e2a450e8d929598ea99d9fed96cbb657 |
shikiji | github_2023 | antfu | typescript | locateTextTokens | const locateTextTokens = (
line: number,
character: number,
length: number,
) => {
const start = character
const end = character + length
// When the length is 0 (completion), we find the token that contains it
if (length === 0) {
... | // Find tokens are in range of a node, it can may multiple tokens. | https://github.com/antfu/shikiji/blob/fc923646e2a450e8d929598ea99d9fed96cbb657/packages/shikiji-twoslash/src/core.ts#L133-L151 | fc923646e2a450e8d929598ea99d9fed96cbb657 |
node-llama-cpp | github_2023 | withcatai | typescript | Llama.cpuMathCores | public get cpuMathCores() {
return this._mathCores;
} | /** The number of CPU cores that are useful for math */ | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/bindings/Llama.ts#L191-L193 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | Llama.maxThreads | public get maxThreads() {
return this._threadsSplitter.maxThreads;
} | /**
* The maximum number of threads that can be used by the Llama instance.
*
* If set to `0`, the Llama instance will have no limit on the number of threads.
*
* See the `maxThreads` option of `getLlama` for more information.
*/ | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/bindings/Llama.ts#L202-L204 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | Llama.vramPaddingSize | public get vramPaddingSize() {
return this._vramPadding.size;
} | /**
* VRAM padding used for memory size calculations, as these calculations are not always accurate.
* This is set by default to ensure stability, but can be configured when you call `getLlama`.
*
* See `vramPadding` on `getLlama` for more information.
*/ | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/bindings/Llama.ts#L259-L261 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | Llama.getVramState | public async getVramState() {
this._ensureNotDisposed();
const {total, used, unifiedSize} = this._bindings.getGpuVramInfo();
return {
total,
used,
free: Math.max(0, total - used),
unifiedSize
};
} | /**
* The total amount of VRAM that is currently being used.
*
* `unifiedSize` represents the amount of VRAM that is shared between the CPU and GPU.
* On SoC devices, this is usually the same as `total`.
*/ | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/bindings/Llama.ts#L269-L280 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | Llama.getSwapState | public async getSwapState(): Promise<{
/**
* The maximum size of the swap memory that the system can allocate.
* If the swap size is dynamic (like on macOS), this will be `Infinity`
*/
maxSize: number,
/** The total size allocated by the system for swap memory */
... | /**
* Get the state of the swap memory.
*
* **`maxSize`** - The maximum size of the swap memory that the system can allocate.
* If the swap size is dynamic (like on macOS), this will be `Infinity`.
*
* **`allocated`** - The total size allocated by the system for swap memory.
*
* ... | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/bindings/Llama.ts#L294-L318 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | Llama.createGrammarForJsonSchema | public async createGrammarForJsonSchema<const T extends GbnfJsonSchema>(schema: Readonly<T>) {
return new LlamaJsonSchemaGrammar<T>(this, schema);
} | /**
* @see [Using a JSON Schema Grammar](https://node-llama-cpp.withcat.ai/guide/grammar#json-schema) tutorial
* @see [Reducing Hallucinations When Using JSON Schema Grammar](https://node-llama-cpp.withcat.ai/guide/grammar#reducing-json-schema-hallucinations) tutorial
*/ | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/bindings/Llama.ts#L348-L350 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | Llama.getGrammarFor | public async getGrammarFor(type: Parameters<typeof LlamaGrammar.getFor>[1]) {
return await LlamaGrammar.getFor(this, type);
} | /* eslint-enable @stylistic/max-len */ | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/bindings/Llama.ts#L353-L355 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | Llama.createGrammar | public async createGrammar(options: LlamaGrammarOptions) {
return new LlamaGrammar(this, options);
} | /**
* @see [Using Grammar](https://node-llama-cpp.withcat.ai/guide/grammar) tutorial
*/ | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/bindings/Llama.ts#L360-L362 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | Llama._init | public async _init() {
await this._bindings.init();
} | /** @internal */ | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/bindings/Llama.ts#L365-L367 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | Llama._log | public _log(level: LlamaLogLevel, message: string) {
this._onAddonLog(LlamaLogLevelToAddonLogLevel.get(level) ?? defaultLogLevel, message + "\n");
} | /**
* Log messages related to the Llama instance
* @internal
*/ | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/bindings/Llama.ts#L373-L375 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | Llama._onAddonLog | private _onAddonLog(level: number, message: string) {
const llamaLogLevel = addonLogLevelToLlamaLogLevel.get(level) ?? LlamaLogLevel.fatal;
if (this._pendingLog != null && this._pendingLogLevel != null && this._pendingLogLevel != llamaLogLevel) {
this._callLogger(this._pendingLogLevel, this... | /** @internal */ | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/bindings/Llama.ts#L378-L407 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | Llama._dispatchPendingLogMicrotask | private _dispatchPendingLogMicrotask() {
this._logDispatchQueuedMicrotasks--;
if (this._logDispatchQueuedMicrotasks !== 0)
return;
if (this._pendingLog != null && this._pendingLogLevel != null) {
this._callLogger(this._pendingLogLevel, this._pendingLog);
this... | /** @internal */ | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/bindings/Llama.ts#L410-L419 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | Llama._callLogger | private _callLogger(level: LlamaLogLevel, message: string) {
// llama.cpp uses dots to indicate progress, so we don't want to print them as different lines,
// and instead, append to the same log line
if (logMessageIsOnlyDots(message) && this._logger === Llama.defaultConsoleLogger) {
... | /** @internal */ | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/bindings/Llama.ts#L422-L449 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | Llama._onExit | private _onExit() {
if (this._pendingLog != null && this._pendingLogLevel != null) {
this._callLogger(this._pendingLogLevel, this._pendingLog);
this._pendingLog = null;
}
} | /** @internal */ | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/bindings/Llama.ts#L452-L457 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | Llama._ensureNotDisposed | private _ensureNotDisposed() {
if (this._disposed)
throw new DisposedError();
} | /** @internal */ | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/bindings/Llama.ts#L460-L463 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | Llama._create | public static async _create({
bindings, bindingPath, buildType, buildMetadata, logLevel, logger, vramPadding, ramPadding, maxThreads, skipLlamaInit = false,
debug
}: {
bindings: BindingModule,
bindingPath: string,
buildType: "localBuild" | "prebuilt",
buildMetadata: B... | /** @internal */ | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/bindings/Llama.ts#L466-L562 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | NoBinaryFoundError.constructor | public constructor(message: string = "NoBinaryFoundError") {
super(message);
} | /** @internal */ | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/bindings/utils/NoBinaryFoundError.ts#L3-L5 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | AlpacaChatWrapper._getOptionConfigurationsToTestIfCanSupersedeJinjaTemplate | public static override _getOptionConfigurationsToTestIfCanSupersedeJinjaTemplate() {
return [
{},
{allowSpecialTokensInTitles: true}
] satisfies ChatWrapperJinjaMatchConfiguration<typeof this>;
} | /** @internal */ | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/chatWrappers/AlpacaChatWrapper.ts#L38-L43 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | FalconChatWrapper._getOptionConfigurationsToTestIfCanSupersedeJinjaTemplate | public static override _getOptionConfigurationsToTestIfCanSupersedeJinjaTemplate() {
return [
{},
{allowSpecialTokensInTitles: true}
] satisfies ChatWrapperJinjaMatchConfiguration<typeof this>;
} | /** @internal */ | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/chatWrappers/FalconChatWrapper.ts#L157-L162 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | FunctionaryChatWrapper._generateContextStateV3 | private _generateContextStateV3({
chatHistory, availableFunctions, documentFunctionParams
}: ChatWrapperGenerateContextStateOptions): ChatWrapperGeneratedContextState {
const hasFunctions = Object.keys(availableFunctions ?? {}).length > 0;
const historyWithFunctions = this.addAvailableFunct... | /** @internal */ | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/chatWrappers/FunctionaryChatWrapper.ts#L134-L296 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | FunctionaryChatWrapper._generateContextStateV2Llama3 | private _generateContextStateV2Llama3({
chatHistory, availableFunctions, documentFunctionParams
}: ChatWrapperGenerateContextStateOptions): ChatWrapperGeneratedContextState {
const historyWithFunctions = this.addAvailableFunctionsSystemMessageToHistory(chatHistory, availableFunctions, {
... | /** @internal */ | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/chatWrappers/FunctionaryChatWrapper.ts#L299-L424 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | FunctionaryChatWrapper._generateContextStateV2 | private _generateContextStateV2({
chatHistory, availableFunctions, documentFunctionParams
}: ChatWrapperGenerateContextStateOptions): ChatWrapperGeneratedContextState {
const hasFunctions = Object.keys(availableFunctions ?? {}).length > 0;
const historyWithFunctions = this.addAvailableFunct... | /** @internal */ | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/chatWrappers/FunctionaryChatWrapper.ts#L427-L646 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | FunctionaryChatWrapper._getOptionConfigurationsToTestIfCanSupersedeJinjaTemplate | public static override _getOptionConfigurationsToTestIfCanSupersedeJinjaTemplate() {
return [
{variation: "v3"},
{variation: "v2.llama3"},
{variation: "v2"}
] satisfies ChatWrapperJinjaMatchConfiguration<typeof this>;
} | /** @internal */ | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/chatWrappers/FunctionaryChatWrapper.ts#L722-L728 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | GeneralChatWrapper._getOptionConfigurationsToTestIfCanSupersedeJinjaTemplate | public static override _getOptionConfigurationsToTestIfCanSupersedeJinjaTemplate() {
return [
{},
{allowSpecialTokensInTitles: true}
] satisfies ChatWrapperJinjaMatchConfiguration<typeof this>;
} | /** @internal */ | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/chatWrappers/GeneralChatWrapper.ts#L176-L181 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | Llama2ChatWrapper._getOptionConfigurationsToTestIfCanSupersedeJinjaTemplate | public static override _getOptionConfigurationsToTestIfCanSupersedeJinjaTemplate() {
return [
{addSpaceBeforeEos: false},
{addSpaceBeforeEos: true}
] satisfies ChatWrapperJinjaMatchConfiguration<typeof this>;
} | /** @internal */ | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/chatWrappers/Llama2ChatWrapper.ts#L118-L123 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | Llama3_1ChatWrapper.constructor | public constructor(options: {
/**
* Set to `null` to disable
*
* Defaults to December 2023
*/
cuttingKnowledgeDate?: Date | (() => Date) | number | string | null,
/**
* Set to `null` to disable
*
* Defaults to current date
... | /**
* @param options
*/ | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/chatWrappers/Llama3_1ChatWrapper.ts#L40-L83 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | Llama3_1ChatWrapper._checkModelCompatibility | public static override _checkModelCompatibility(options: ChatWrapperCheckModelCompatibilityParams): boolean {
if (options.tokenizer != null) {
const tokens = options.tokenizer("<|eom_id|>", true, "trimLeadingSpace");
return tokens.length === 1 && options.tokenizer.isSpecialToken(tokens[0... | /** @internal */ | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/chatWrappers/Llama3_1ChatWrapper.ts#L333-L340 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | Llama3_1ChatWrapper._getOptionConfigurationsToTestIfCanSupersedeJinjaTemplate | public static override _getOptionConfigurationsToTestIfCanSupersedeJinjaTemplate() {
return [
{},
[{todayDate: null}, {}],
[{cuttingKnowledgeDate: null}, {}],
[{noToolInstructions: true}, {}],
[{todayDate: null, cuttingKnowledgeDate: null}, {}],
... | /** @internal */ | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/chatWrappers/Llama3_1ChatWrapper.ts#L343-L374 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | Llama3_2LightweightChatWrapper.constructor | public constructor(options: {
/**
* Set to `null` to disable
*
* Defaults to December 2023
*/
cuttingKnowledgeDate?: Date | (() => Date) | number | string | null,
/**
* Set to `null` to disable
*
* Defaults to current date
... | /**
* @param options
*/ | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/chatWrappers/Llama3_2LightweightChatWrapper.ts#L39-L82 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | Llama3_2LightweightChatWrapper._checkModelCompatibility | public static override _checkModelCompatibility(options: ChatWrapperCheckModelCompatibilityParams): boolean {
if (options.tokenizer != null) {
const tokens = options.tokenizer("<|eom_id|>", true, "trimLeadingSpace");
return tokens.length === 1 && options.tokenizer.isSpecialToken(tokens[0... | /** @internal */ | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/chatWrappers/Llama3_2LightweightChatWrapper.ts#L305-L312 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | Llama3_2LightweightChatWrapper._getOptionConfigurationsToTestIfCanSupersedeJinjaTemplate | public static override _getOptionConfigurationsToTestIfCanSupersedeJinjaTemplate() {
return [
{},
[{todayDate: null}, {}],
[{cuttingKnowledgeDate: null}, {}],
[{noToolInstructions: true}, {}],
[{todayDate: null, cuttingKnowledgeDate: null}, {}],
... | /** @internal */ | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/chatWrappers/Llama3_2LightweightChatWrapper.ts#L315-L346 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | MistralChatWrapper._generateAvailableToolsText | private _generateAvailableToolsText({
availableFunctions,
documentFunctionParams = true
}: {
availableFunctions?: ChatModelFunctions,
documentFunctionParams?: boolean
}) {
const availableFunctionNames = Object.keys(availableFunctions ?? {});
if (availableFunction... | /** @internal */ | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/chatWrappers/MistralChatWrapper.ts#L152-L182 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | MistralChatWrapper._splitSystemMessageFromChatHistory | private _splitSystemMessageFromChatHistory(history: readonly ChatHistoryItem[]) {
const systemMessages: LlamaText[] = [];
const newHistory = history.slice();
while (newHistory.length > 0 && newHistory[0]!.type === "system")
systemMessages.push(LlamaText.fromJSON((newHistory.shift()!... | /** @internal */ | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/chatWrappers/MistralChatWrapper.ts#L185-L196 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | MistralChatWrapper._splitLastInteractionFromChatHistory | private _splitLastInteractionFromChatHistory(history: readonly ChatHistoryItem[]) {
const lastInteraction: ChatHistoryItem[] = [];
const newHistory = history.slice();
while (newHistory.length > 0) {
const item = newHistory.pop()!;
lastInteraction.unshift(item);
... | /** @internal */ | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/chatWrappers/MistralChatWrapper.ts#L199-L215 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | MistralChatWrapper._getOptionConfigurationsToTestIfCanSupersedeJinjaTemplate | public static override _getOptionConfigurationsToTestIfCanSupersedeJinjaTemplate() {
return [
{addSpaceBeforeEos: false},
{addSpaceBeforeEos: true}
] satisfies ChatWrapperJinjaMatchConfiguration<typeof this>;
} | /** @internal */ | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/chatWrappers/MistralChatWrapper.ts#L218-L223 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | JinjaTemplateChatWrapper.constructor | public constructor({
template,
modelRoleName = "assistant",
userRoleName = "user",
systemRoleName = "system",
convertUnsupportedSystemMessagesToUserMessages = defaultConvertUnsupportedSystemMessagesToUserMessagesFormat,
functionCallMessageTemplate,
joinAdjacentMes... | /**
* @param options
*/ | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/chatWrappers/generic/JinjaTemplateChatWrapper.ts#L119-L160 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | JinjaTemplateChatWrapper._generateContextText | private _generateContextText(history: readonly ChatHistoryItem[], {
convertSystemMessagesToUserMessagesFormat
}: {
convertSystemMessagesToUserMessagesFormat?: string
}): {
contextText: LlamaText,
stopGenerationTriggers: LlamaText[],
ignoreStartText?: LlamaText[],
... | /** @internal */ | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/chatWrappers/generic/JinjaTemplateChatWrapper.ts#L193-L456 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | JinjaTemplateChatWrapper._runSanityTest | private _runSanityTest() {
try {
let supportsSystemMessages = true;
for (const chatHistory of chatHistoriesForSanityTest) {
const {transformedSystemMessagesToUserMessages} = this.generateContextState({chatHistory});
if (transformedSystemMessagesToUserMes... | /**
* Validate that this Jinja template can be rendered
* @internal
*/ | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/chatWrappers/generic/JinjaTemplateChatWrapper.ts#L462-L477 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | ChatModelFunctionsDocumentationGenerator.getTypeScriptFunctionSignatures | public getTypeScriptFunctionSignatures({documentParams = true}: {documentParams?: boolean} = {}) {
const chatModelFunctions = this.chatModelFunctions;
if (!this.hasAnyFunctions || chatModelFunctions == null)
return "";
const functionNames = Object.keys(chatModelFunctions);
... | /**
* Example:
* ```ts
* // Retrieve the current date
* function getDate();
*
* // Retrieve the current time
* function getTime(params: {hours: "24" | "12", seconds: boolean});
* ```
* @param options
* @param [options.documentParams] - Whether to document the parameters... | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.ts#L30-L58 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | ChatModelFunctionsDocumentationGenerator.getTypeScriptFunctionTypes | public getTypeScriptFunctionTypes({documentParams = true, reservedFunctionNames = []}: {
documentParams?: boolean, reservedFunctionNames?: string[]
} = {}) {
const chatModelFunctions = this.chatModelFunctions;
if (!this.hasAnyFunctions || chatModelFunctions == null)
return "";
... | /**
* Example:
* ```ts
* // Retrieve the current date
* type getDate = () => any;
*
* // Retrieve the current time
* type getTime = (_: {hours: "24" | "12", seconds: boolean}) => any;
* ```
* @param options
* @param [options.documentParams] - Whether to document the par... | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.ts#L73-L105 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | ChatModelFunctionsDocumentationGenerator.getLlama3_1FunctionSignatures | public getLlama3_1FunctionSignatures({documentParams = true}: {documentParams?: boolean} = {}) {
const chatModelFunctions = this.chatModelFunctions;
if (!this.hasAnyFunctions || chatModelFunctions == null)
return "";
const functionNames = Object.keys(chatModelFunctions);
r... | /**
* Example:
* ```
* Use the function 'getDate' to: Retrieve the current date
* {"name": "getDate", "description": "Retrieve the current date"}
*
* Use the function 'getTime' to: Retrieve the current time
* {"name": "getTime", "description": "Retrieve the current time", "parameters"... | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.ts#L120-L148 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | ChatModelFunctionsDocumentationGenerator.getLlama3_2LightweightFunctionSignatures | public getLlama3_2LightweightFunctionSignatures({documentParams = true}: {documentParams?: boolean} = {}) {
const chatModelFunctions = this.chatModelFunctions;
if (!this.hasAnyFunctions || chatModelFunctions == null)
return "";
const functionNames = Object.keys(chatModelFunctions);... | /**
* Example:
* ```
* {"name": "getDate", "description": "Retrieve the current date"}
*
* {"name": "getTime", "description": "Retrieve the current time", "parameters": {"type": "object", "properties": {"hours": {"enum": ["24", "12"]}, "seconds": {"type": "boolean"}}}}
* ```
* @param ... | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.ts#L162-L185 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | isClassReference | function isClassReference<T>(value: any, classReference: T): value is T {
return value === classReference;
} | // this is needed because TypeScript guards don't work automatically with class references | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/chatWrappers/utils/resolveChatWrapper.ts#L392-L394 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | removeAdditionalTensorInfoFields | function removeAdditionalTensorInfoFields(tensorInfo?: GgufTensorInfo[]) {
if (tensorInfo == null)
return;
for (const tensor of tensorInfo) {
delete (tensor as {fileOffset?: GgufTensorInfo["fileOffset"]}).fileOffset;
delete (tensor as {filePart?: GgufTensorInfo["filePart"]}).filePart;
... | // these fields are added by the parser for ease of use and are not found in the gguf file itself | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/cli/commands/inspect/commands/InspectGgufCommand.ts#L231-L239 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | ConsoleInteraction._onData | private _onData(data: Buffer) {
if (!this._isActive)
return;
const key = data.toString();
const callbacks = this._keyCallbacks.get(key) ?? [];
if (callbacks.length === 0 && key === ConsoleInteractionKey.ctrlC) {
process.stdout.write("\n");
this.stop(... | /** @internal */ | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/cli/utils/ConsoleInteraction.ts#L78-L98 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | ConsoleInteractionOnKeyHandle._create | public static _create(dispose: () => void) {
return new ConsoleInteractionOnKeyHandle(dispose);
} | /** @internal */ | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/cli/utils/ConsoleInteraction.ts#L149-L151 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | LlamaCompletion.generateCompletion | public async generateCompletion(input: Token[] | string | LlamaText, options: LlamaCompletionGenerationOptions = {}) {
const {response} = await this.generateCompletionWithMeta(input, options);
return response;
} | /**
* Generate a completion for an input.
*/ | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaCompletion.ts#L234-L238 | 63a106627e1a8664ac335526c987522c94e87ce2 |
node-llama-cpp | github_2023 | withcatai | typescript | LlamaCompletion.generateCompletionWithMeta | public async generateCompletionWithMeta(
input: Token[] | string | LlamaText,
{
onTextChunk,
onToken,
signal,
maxTokens,
temperature,
minP,
topK,
topP,
seed,
trimWhitespaceSuffix = fal... | /**
* Same as `generateCompletion`, but returns additional metadata about the generation.
* See `generateCompletion` for more information.
*/ | https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaCompletion.ts#L244-L364 | 63a106627e1a8664ac335526c987522c94e87ce2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.