Skip to content

Make videos on the computer you already own. FreeVideo runs MiniMax H3 in as little as 8 GB of VRAM and 16 GB of RAM, and adapts its acceleration path to your hardware.

Drama: a long shot waits for this computer's capability table and is judged by its limit, also...

Bowen Xue3cb2a1a76928
diff --git a/freevideo_engine/agent/drama.py b/freevideo_engine/agent/drama.py
index e174368..904e3c0 100644
--- a/freevideo_engine/agent/drama.py
+++ b/freevideo_engine/agent/drama.py
@@ -283,6 +283,17 @@ def _carded(play, shot):
return False
+def needs_machine_limit(play):
+ """Whether check() would refuse this film at the 15 s default but might accept it at this machine's own limit."""
+ for shot in play['shots']:
+ seconds = shot.get('seconds', play.get('seconds'))
+ if (isinstance(seconds, (int, float)) and not isinstance(seconds, bool) and seconds > BLOCK_SECONDS
+ and (shot.get('first') is not None
+ or not shot.get('continue') and (shot.get('references') or _carded(play, shot)))):
+ return True
+ return False
+
+
SHOWN_TEXT = re.compile(r'["“「][^"”」]+["”」]')
diff --git a/freevideo_engine/agent/errors.py b/freevideo_engine/agent/errors.py
index 1df7d39..c9ef8ac 100644
--- a/freevideo_engine/agent/errors.py
+++ b/freevideo_engine/agent/errors.py
@@ -82,6 +82,7 @@ ERRORS = {
# Preserve that runtime contract while the pure production code keeps its 409.
PRODUCTION_STATUS = {'not_ready': 409}
ERRORS.update({
+ 'capabilities_computing': (503, True, 'This computer is still working out what it can generate.', 'Wait retry_after_seconds, then retry the request.'),
'unknown_shot': (404, False, 'The shot does not exist.', 'Use a shot id from the production view.'),
'unknown_take': (404, False, 'The take does not exist.', 'Use a take number from this shot in the production view.'),
'take_not_ready': (409, False, 'The take is stale or has not succeeded.', 'Choose a succeeded, non-stale take, or reshoot this shot.'),
@@ -290,6 +291,7 @@ def safe_details(value):
FAILURE_REASONS_ZH = {
**LORA_MESSAGE_ZH,
'lan_unavailable': '局域网设置需要启动器安装记录',
+ 'capabilities_computing': '正在计算这台电脑的生成能力,稍后再试',
'out_of_memory': '生成时显存或内存不足',
'insufficient_memory': '可用显存或内存不够生成这段内容',
'no_memory': '可用显存或内存不够生成这张图片',
@@ -341,6 +343,7 @@ FAILURE_REASONS_ZH = {
FAILURE_REASONS_EN = {
**LORA_MESSAGE_EN,
'lan_unavailable': 'Phone access requires FreeVideo installed with the launcher',
+ 'capabilities_computing': 'Working out what this computer can generate; try again shortly',
'out_of_memory': 'Graphics or system memory ran out during generation',
'insufficient_memory': 'There is not enough free graphics or system memory for this generation',
'no_memory': 'There is not enough free graphics or system memory for this picture',
@@ -480,6 +483,8 @@ def build(code, *, details=None, request=None, validation=False, message=None, n
result = capture_other_usage(result)
if action_required:
result['next'] = next_action if validation and next_action else action
+ if code == 'capabilities_computing':
+ result['retry_after_seconds'] = retry_after_seconds or 1
if code == 'busy':
result['retry_after_seconds'] = retry_after_seconds or 1
result['details'].append(dict(owner=owner if owner in ('agent', 'ui') else 'ui'))
diff --git a/freevideo_engine/agent/guide.py b/freevideo_engine/agent/guide.py
index 2eba558..61514ba 100644
--- a/freevideo_engine/agent/guide.py
+++ b/freevideo_engine/agent/guide.py
@@ -122,7 +122,8 @@ GUIDE = {
],
'agent_jobs': [
'GET /capabilities reads the studio cache with the same size/task/material query parameters. '
- 'status=computing includes retry_after_seconds; unknown plan estimates have seconds=null.',
+ 'status=computing includes retry_after_seconds; unknown plan estimates have seconds=null. '
+ 'A request answered with capabilities_computing waits retry_after_seconds and repeats unchanged.',
'GET /jobs/{id}?wait=25 waits at most 25 seconds and returns poll_after_ms. Like POST /jobs, the answer '
'has the job under job (its fields are also at the top level). Poll the same ID until job.status is '
'succeeded, failed, cancelled or interrupted; disconnecting a wait or SSE does not cancel generation.',
diff --git a/freevideo_engine/agent/production.py b/freevideo_engine/agent/production.py
index 2a46e12..f58c7cf 100644
--- a/freevideo_engine/agent/production.py
+++ b/freevideo_engine/agent/production.py
@@ -403,9 +403,9 @@ def _commit(state, draft, now):
state.update(draft)
-def new(identity, request, *, now):
+def new(identity, request, *, now, single_seconds=drama.BLOCK_SECONDS):
"""Create a JSON receipt. Shot indices start at 1; generations start at 0."""
- request = plan(request)['request']
+ request = plan(request, single_seconds=single_seconds)['request']
if not isinstance(identity, str) or not spec.SLUG.fullmatch(identity):
_invalid([dict(path='/id', message='Production id must be a unique short name')])
state = dict(version=1, id=identity, title=request['screenplay'].get('title'), revision=1,
@@ -583,7 +583,7 @@ def choose(state, shot, take, *, by, reason=None, cascade=True, now):
_commit(state, draft, now)
-def reshoot(state, shot, *, by, note=None, changes=None, takes=1, reason=None, now):
+def reshoot(state, shot, *, by, note=None, changes=None, takes=1, reason=None, now, single_seconds=drama.BLOCK_SECONDS):
"""Reserve a fresh generation; keep all previous non-stale takes selectable."""
_editable(state, by)
draft = deepcopy(state)
@@ -604,7 +604,7 @@ def reshoot(state, shot, *, by, note=None, changes=None, takes=1, reason=None, n
source.update(deepcopy(changes or {}))
# Recheck the complete effective screenplay, transactionally.
plan(dict(screenplay=draft['screenplay'], takes_per_shot=draft['takes_per_shot'], director=draft['director']),
- fields=False)
+ fields=False, single_seconds=single_seconds)
_schedule(draft, row, takes, by, note)
draft['cancelled'], draft['current_join'] = False, None
_decision(draft, now, by, 'reshoot', shot, reason=reason)
diff --git a/freevideo_engine/agent/productions.py b/freevideo_engine/agent/productions.py
index b050a06..ba3c4bb 100644
--- a/freevideo_engine/agent/productions.py
+++ b/freevideo_engine/agent/productions.py
@@ -33,6 +33,7 @@ MAX_GENERATION = 4 # Generations are zero-based: original 0, reshoots 1 through
MAX_CHILDREN = 60 # Includes assembly, rejected submissions and resumed attempts.
MAX_WAITERS = 32 # Long GET waits served at once; more callers receive the current state.
MAX_WAIT = 25
+READY_SECONDS = 20. # A long shot that needs the first table after a start waits this long more, then is asked to retry.
REQUEST_ID = re.compile(r'r-[0-9a-f]{32}')
_NAME = re.compile(r'[A-Za-z0-9_-]{1,64}')
_POINTER = re.compile(r'(?:/(?:[A-Za-z0-9_-]{1,64}|\?))*|/')
@@ -378,15 +379,36 @@ class Productions:
probe = spec.normalize(probe, port=self.jobs.port)
# Pictures and cards make the shot a reference generation, which has its own limit.
table = capability_table(self.jobs.port, probe, wait=WAIT_SECONDS, task='ref2va')
- limit = single_frame_limit(probe, table=table)
- return chain_plan.single_seconds(limit)
+ waiting = table.get('status') == 'computing' and drama.needs_machine_limit(play)
+ if waiting:
+ table = capability_table(self.jobs.port, probe, wait=READY_SECONDS, task='ref2va')
+ waiting = table.get('status') == 'computing'
+ if not waiting:
+ return chain_plan.single_seconds(single_frame_limit(probe, table=table))
except Exception: # A film that does not normalize is reported by its own checks.
return chain_plan.BLOCK_SECONDS
+ # A limit not worked out yet is not a low limit: the same request can succeed in a moment.
+ raise JobError('capabilities_computing', 'Capabilities are being worked out',
+ retry_after_seconds=table.get('retry_after_seconds'))
+
+ def _reshoot_seconds(self, identity, shot, changes):
+ """The limit for a shot that changes; a reshoot with no changes keeps what was accepted. Call without the lock."""
+ if not changes or not isinstance(changes, dict):
+ return math.inf
+ with self.changed:
+ state = deepcopy(self._record(identity)['state'])
+ try:
+ state['screenplay']['shots'][production._shot(state, shot)['index'] - 1].update(changes)
+ except production.ProductionError: # production.reshoot reports it.
+ return math.inf
+ return self._single_seconds(dict(screenplay=state['screenplay']))
def plan(self, request, *, local=True):
+ single_seconds = self._single_seconds(request)
result = _domain(production.plan, {k: v for k, v in request.items() if k != 'ref'},
- single_seconds=self._single_seconds(request))
- state = _domain(production.new, 'dplanpreview', result['request'], now=iso(self.jobs.clock()))
+ single_seconds=single_seconds)
+ state = _domain(production.new, 'dplanpreview', result['request'], now=iso(self.jobs.clock()),
+ single_seconds=single_seconds)
play = result['request']['screenplay']
with self.changed:
cards = self._cards(play)
@@ -611,12 +633,13 @@ class Productions:
if ref and alias and ref != alias:
raise JobError('idempotency_conflict', 'Conflicting keys')
ref = ref or alias
+ single_seconds = self._single_seconds(request) # May wait, so not under the lock.
with self.changed:
digest, replay = self._receipt('start', dict(request=request, by=by), ref, client)
if replay is not None:
return replay
identity = 'd' + uuid.uuid4().hex[:12]
- state = _domain(production.new, identity, request, now=iso(self.jobs.clock()))
+ state = _domain(production.new, identity, request, now=iso(self.jobs.clock()), single_seconds=single_seconds)
# new() only takes director, not the initiating actor. Attribution
# belongs to this boundary, including the future in-process UI.
for decision in state['decisions']:
@@ -765,7 +788,7 @@ class Productions:
paused=view['paused'], stalled=view['stalled'], session=record.get('session'), error_zh=view['error_zh'], error_en=view['error_en']))
return result
- def _mutate(self, action, identity, *, by, ref=None, client=None, **values):
+ def _mutate(self, action, identity, *, by, ref=None, client=None, limit=None, **values):
with self.changed:
record = self._record(identity)
if action in ('choose', 'reshoot', 'finish'):
@@ -777,7 +800,7 @@ class Productions:
return replay
draft = deepcopy(record)
state = draft['state']
- _domain(getattr(production, action), state, by=by, now=iso(self.jobs.clock()), **values)
+ _domain(getattr(production, action), state, by=by, now=iso(self.jobs.clock()), **values, **(limit or {}))
# The next advance is part of this operation: if it cannot run, nothing changes.
self._preflight(record, draft)
self._prepare_estimates(draft)
@@ -805,7 +828,8 @@ class Productions:
return self._mutate('choose', identity, shot=shot, take=take, by=by, ref=ref, **kwargs)
def reshoot(self, identity, shot, *, by='agent', ref=None, **kwargs):
- return self._mutate('reshoot', identity, shot=shot, by=by, ref=ref, **kwargs)
+ seconds = self._reshoot_seconds(identity, shot, kwargs.get('changes'))
+ return self._mutate('reshoot', identity, shot=shot, by=by, ref=ref, limit=dict(single_seconds=seconds), **kwargs)
def finish(self, identity, *, by='agent', ref=None, **kwargs):
return self._mutate('finish', identity, by=by, ref=ref, **kwargs)