generateAlternatives method
Implementation
@override
Future<List<String>> generateAlternatives(
String prompt, {
String? sessionId,
int count = 3,
}) async {
if (prompt.trim().isEmpty) {
throw AppleFoundationException(
'Prompt cannot be empty',
code: 'INVALID_PROMPT',
);
}
if (count <= 0 || count > 10) {
throw AppleFoundationException(
'count must be between 1 and 10',
code: 'INVALID_COUNT',
);
}
try {
final List<dynamic>? result =
await _invokeMethodWithTimeout<List<dynamic>>(
'generateAlternatives',
{
'prompt': prompt,
if (sessionId != null) 'sessionId': sessionId,
'count': count,
},
);
if (result == null) {
throw AppleFoundationException(
'Received null response from native layer',
code: 'NULL_RESPONSE',
);
}
return result.cast<String>();
} catch (e) {
_logError('generateAlternatives', e);
throw AppleFoundationException(
'Failed to generate alternatives: ${e.toString()}',
code: 'GENERATE_ALTERNATIVES_FAILED',
details: {'prompt': prompt, 'sessionId': sessionId, 'count': count},
);
}
}