游戏与仿真

live-jev

@vinilana10JavaScript更新于 2026-09-18可当场跑

基于TypeSafe的Jev决策模型,在浏览器中实现的二维自动驾驶汽车模拟。

英文原文

2D autonomous car simulation in the browser, driven by TypeSafe's Jev decision model

vinilana/live-jev

它在哪儿调用了 Jev

import { TypeSafeClient, APIError } from "@typesafe-ai/sdk";

server.js:8

链接指向我们抓取当天的那个 commit,行号是准的。

它问 Jev 的问题

下面是从这个项目源码里原样取出来的 question 组合。

取自 public/js/brain.js:5

  1. lane_action选项

    You are the driving policy of `ego`, a car on a one-way road with 3 lanes (see `road`).

    • keep_laneStay in the current lane; it is clear enough, or no adjacent lane is safer.
    • change_leftMove one lane to the left: the left lane exists, is clear ahead and no car is closing from behind, and the current lane is blocked or slower.
    • change_rightMove one lane to the right: the right lane exists, is clear ahead and no car is closing from behind, and the current lane is blocked or slower.
  2. speed_action选项

    Decide how `ego` should adjust its speed in the next second. Only `lanes.current` matters for speed; objects in

    • stopBrake to a full stop: a pedestrian is in or entering the path, or a stopped obstacle/vehicle is within `ego.stopping_distance_m` plus a 5 m margin (leave room to steer around it later).
    • slow_downReduce speed: the lead in the current lane is within about twice the stopping distance, or `time_to_collision_s` is under ~4 s.
    • holdKeep the current speed: there is a lead in the current lane but the gap is comfortable (`time_to_collision_s` between ~4 and ~8 s, or matching its speed).
    • speed_upAccelerate: the current lane is clear well beyond twice the stopping distance (or `time_to_collision_s` is null or above ~8 s) and ego is below the speed limit.
  3. hazard打分

    Rate the overall collision hazard for `ego` right now, given everything in the state.

    • 0No hazard: the road ahead is clear for a long distance.
    • 1Low: obstacles or vehicles exist but they are far away or in other lanes.
    • 2Moderate: something in the current lane is within about twice the stopping distance, or a pedestrian is close to the road.
    • 3Severe: a collision is likely within a few seconds unless ego brakes or swerves now.
  4. pedestrian_yield是/否

    A pedestrian is on the road, or is walking toward the road and will reach ego's lane, within roughly `ego.stopping_distance_m`

用你自己的内容跑一遍

代码
import { experimental_evaluate as evaluate } from 'ai';

const { answers } = await evaluate({
  model: 'typesafe-ai/jev',
  state,
  questions: {
    lane_action: { type: 'choice', instructions: 'You are the driving policy of `ego`, a car on a one-way road with 3 lanes (see `road`).',
      criteria: { keep_lane: 'Stay in the current lane; it is clear enough, or no adjacent lane is safer.', change_left: 'Move one lane to the left: the left lane exists, is clear ahead and no car is closing from behind, and the current lane is blocked or slower.', change_right: 'Move one lane to the right: the right lane exists, is clear ahead and no car is closing from behind, and the current lane is blocked or slower.' } },
    speed_action: { type: 'choice', instructions: 'Decide how `ego` should adjust its speed in the next second. Only `lanes.current` matters for speed; objects in',
      criteria: { stop: 'Brake to a full stop: a pedestrian is in or entering the path, or a stopped obstacle/vehicle is within `ego.stopping_distance_m` plus a 5 m margin (leave room to steer around it later).', slow_down: 'Reduce speed: the lead in the current lane is within about twice the stopping distance, or `time_to_collision_s` is under ~4 s.', hold: 'Keep the current speed: there is a lead in the current lane but the gap is comfortable (`time_to_collision_s` between ~4 and ~8 s, or matching its speed).', speed_up: 'Accelerate: the current lane is clear well beyond twice the stopping distance (or `time_to_collision_s` is null or above ~8 s) and ego is below the speed limit.' } },
    hazard: { type: 'score', instructions: 'Rate the overall collision hazard for `ego` right now, given everything in the state.',
      criteria: ['No hazard: the road ahead is clear for a long distance.', 'Low: obstacles or vehicles exist but they are far away or in other lanes.', 'Moderate: something in the current lane is within about twice the stopping distance, or a pedestrian is close to the road.', 'Severe: a collision is likely within a few seconds unless ego brakes or swerves now.'] },
    pedestrian_yield: { type: 'boolean', instructions: 'A pedestrian is on the road, or is walking toward the road and will reach ego\'s lane, within roughly `ego.stopping_distance_m`' },
  },
});

同类的其他项目