|
@@ -1,6 +1,7 @@
|
|
import 'dart:math';
|
|
import 'dart:math';
|
|
|
|
|
|
import "package:logging/logging.dart";
|
|
import "package:logging/logging.dart";
|
|
|
|
+import "package:photos/services/machine_learning/semantic_search/semantic_search_service.dart";
|
|
import "package:shared_preferences/shared_preferences.dart";
|
|
import "package:shared_preferences/shared_preferences.dart";
|
|
|
|
|
|
const _promptsJson = {
|
|
const _promptsJson = {
|
|
@@ -48,7 +49,8 @@ class MagicCacheService {
|
|
List<Map<String, Object>> getRandomPrompts() {
|
|
List<Map<String, Object>> getRandomPrompts() {
|
|
final promptsJson = _promptsJson["prompts"];
|
|
final promptsJson = _promptsJson["prompts"];
|
|
final randomPrompts = <Map<String, Object>>[];
|
|
final randomPrompts = <Map<String, Object>>[];
|
|
- final randomNumbers = _generateRandomNumbers(promptsJson!.length - 1, 4);
|
|
|
|
|
|
+ final randomNumbers =
|
|
|
|
+ _generateUniqueRandomNumbers(promptsJson!.length - 1, 4);
|
|
for (int i = 0; i < randomNumbers.length; i++) {
|
|
for (int i = 0; i < randomNumbers.length; i++) {
|
|
randomPrompts.add(promptsJson[randomNumbers[i]]);
|
|
randomPrompts.add(promptsJson[randomNumbers[i]]);
|
|
}
|
|
}
|
|
@@ -56,10 +58,25 @@ class MagicCacheService {
|
|
return randomPrompts;
|
|
return randomPrompts;
|
|
}
|
|
}
|
|
|
|
|
|
- List<int> _generateRandomNumbers(int max, int count) {
|
|
|
|
|
|
+ Future<List<int>> getMatchingFileIDsForPromptData(
|
|
|
|
+ Map<String, Object> promptData,
|
|
|
|
+ ) {
|
|
|
|
+ return SemanticSearchService.instance.getMatchingFileIDs(
|
|
|
|
+ promptData["prompt"] as String,
|
|
|
|
+ promptData["minimumScore"] as double,
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ ///Generates from 0 to max unique random numbers
|
|
|
|
+ List<int> _generateUniqueRandomNumbers(int max, int count) {
|
|
final numbers = <int>[];
|
|
final numbers = <int>[];
|
|
- for (int i = 1; i <= count; i++) {
|
|
|
|
- numbers.add(Random().nextInt(max + 1));
|
|
|
|
|
|
+ for (int i = 1; i <= count;) {
|
|
|
|
+ final randomNumber = Random().nextInt(max + 1);
|
|
|
|
+ if (numbers.contains(randomNumber)) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ numbers.add(randomNumber);
|
|
|
|
+ i++;
|
|
}
|
|
}
|
|
return numbers;
|
|
return numbers;
|
|
}
|
|
}
|