sessionGetResponse method
Answers the pending turn.
Implementation
@override
Future<AiResponse> sessionGetResponse(
String sessionId, {
GenerationConfig? config,
}) async {
final s = _session(sessionId);
final input = s.takeTurn();
final watch = Stopwatch()..start();
try {
final model = await _ensureModel(s, config);
final promise = model.callMethod<JSPromise<JSString>>(
'prompt'.toJS,
input.toJS,
_promptOptions(s, config) as JSObject,
);
final text = (await promise.toDart).toDart;
return AiResponse(
text: text,
tokenCount: estimateTokens(text),
generationTimeMs: watch.elapsedMilliseconds,
);
} catch (e) {
throw _translate(e);
} finally {
s.abort = null;
}
}