AI: 게임 시작 때 모델 미리 올리기, 2시간 유지
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -207,6 +207,8 @@ export class BotBrain {
|
|||||||
|
|
||||||
onGameStart(): void {
|
onGameStart(): void {
|
||||||
this.happened = [];
|
this.happened = [];
|
||||||
|
// A game with computers and people: make sure the model is loaded before anyone talks.
|
||||||
|
if (this.llm?.available() && this.room.humans().length && this.room.bots().length) void this.llm.warm();
|
||||||
if (!this.enabled() || this.room.gameId() === 'mafia' || this.random() > 0.7) return;
|
if (!this.enabled() || this.room.gameId() === 'mafia' || this.random() > 0.7) return;
|
||||||
const bots = this.room.bots();
|
const bots = this.room.bots();
|
||||||
const bot = bots[Math.floor(this.random() * bots.length)];
|
const bot = bots[Math.floor(this.random() * bots.length)];
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ export class Llm {
|
|||||||
model: this.cfg.model,
|
model: this.cfg.model,
|
||||||
messages,
|
messages,
|
||||||
stream: false,
|
stream: false,
|
||||||
keep_alive: this.cfg.keepAlive ?? '30m',
|
keep_alive: this.cfg.keepAlive ?? '2h',
|
||||||
...(opts.format ? { format: opts.format } : {}),
|
...(opts.format ? { format: opts.format } : {}),
|
||||||
options: { temperature: opts.temperature ?? 0.9, num_predict: opts.maxTokens ?? 80 },
|
options: { temperature: opts.temperature ?? 0.9, num_predict: opts.maxTokens ?? 80 },
|
||||||
}),
|
}),
|
||||||
@@ -115,8 +115,15 @@ export class Llm {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Loads the model into GPU memory ahead of the first real request (the first load takes ~20 s). */
|
private lastWarm = -Infinity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the model into GPU memory ahead of the first real request (a cold load takes ~20 s; Ollama unloads it after
|
||||||
|
* `keepAlive` without use). Cheap when it is already loaded; at most once a minute.
|
||||||
|
*/
|
||||||
async warm(): Promise<boolean> {
|
async warm(): Promise<boolean> {
|
||||||
|
if (this.now() - this.lastWarm < 60_000) return true;
|
||||||
|
this.lastWarm = this.now();
|
||||||
const r = await this.chat([{ role: 'user', content: '안녕' }], { maxTokens: 1, timeoutMs: 60_000 });
|
const r = await this.chat([{ role: 'user', content: '안녕' }], { maxTokens: 1, timeoutMs: 60_000 });
|
||||||
return r !== null;
|
return r !== null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user