From 4e5aaf8371a05444f3304caf0ac4cde612abb3ab Mon Sep 17 00:00:00 2001 From: MrCsabaToth Date: Sat, 19 Oct 2024 21:25:50 -0700 Subject: [PATCH] Fixing embedding function return call handling #48 --- lib/ai/service/embedding_list.dart | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/ai/service/embedding_list.dart b/lib/ai/service/embedding_list.dart index c1c8609..a8d8ef3 100644 --- a/lib/ai/service/embedding_list.dart +++ b/lib/ai/service/embedding_list.dart @@ -6,33 +6,36 @@ class Embeddings { Embeddings.fromJson(Map embeddingMap) { textEmbeddings.clear(); if (embeddingMap.containsKey('text') && embeddingMap['text'] != null) { - final embeddingsList = embeddingMap['text']! as List; + final embeddingsList = embeddingMap['text']! as List; for (final embeddings in embeddingsList.nonNulls) { - final embedding = (embeddings as List).nonNulls; + final embedding = + (embeddings as List).nonNulls.toList(growable: false); if (embedding.isNotEmpty) { - textEmbeddings - .add(dimensionalityReduction(embedding as List)); + textEmbeddings.add(dimensionalityReduction(embedding.cast())); } } } imageEmbeddings.clear(); if (embeddingMap.containsKey('image') && embeddingMap['image'] != null) { - final embedding = (embeddingMap['image']! as List).nonNulls; + final embedding = (embeddingMap['image']! as List) + .nonNulls + .toList(growable: false); if (embedding.isNotEmpty) { imageEmbeddings - .addAll(dimensionalityReduction(embedding as List)); + .addAll(dimensionalityReduction(embedding.cast())); } } videoEmbeddings.clear(); if (embeddingMap.containsKey('video') && embeddingMap['video'] != null) { - final embeddingsList = embeddingMap['video']! as List; + final embeddingsList = embeddingMap['video']! as List; for (final embeddings in embeddingsList.nonNulls) { - final embedding = (embeddings as List).nonNulls; + final embedding = + (embeddings as List).nonNulls.toList(growable: false); if (embedding.isNotEmpty) { videoEmbeddings - .add(dimensionalityReduction(embedding as List)); + .add(dimensionalityReduction(embedding.cast())); } } }