embed method
- String text
Generates embeddings for the given text.
Returns a list of doubles representing the vector embedding. Throws UnsupportedError if the provider doesn't support embeddings.
Implementation
@override
Future<List<double>> embed(String text) async {
final body = {
'model': 'text-embedding-3-small',
'input': text,
};
final response = await _post('/embeddings', body);
final json = jsonDecode(response.body) as Map<String, dynamic>;
if (response.statusCode != 200) {
throw _parseError(response.statusCode, json);
}
final data = (json['data'] as List).first as Map<String, dynamic>;
return (data['embedding'] as List).cast<double>();
}