Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
josancamon19 committed Jun 2, 2024
2 parents d7ad59b + 99604f2 commit 6437f21
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
5 changes: 3 additions & 2 deletions apps/AppWithWearable/lib/backend/api_requests/api_calls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:friend_private/env/env.dart';
import 'package:friend_private/flutter_flow/flutter_flow_util.dart';
import 'package:http/http.dart' as http;
import 'package:path/path.dart';
import '../../utils/string_utils.dart';

Future<http.Response?> makeApiCall({
required String url,
Expand Down Expand Up @@ -140,7 +141,7 @@ Future<Structured> generateTitleAndSummaryForMemory(String transcript, List<Memo
Here is the transcript ```${transcript.trim()}```.
${_getPrevMemoriesStr(previousMemories)}
The output should be formatted as a JSON instance that conforms to the JSON schema below.
The output should be formatted as a JSON instance that conforms to the JSON schema below. You must always generate valid language and respond according to the format values to the keys in json.
As an example, for the schema {"properties": {"foo": {"title": "Foo", "description": "a list of strings", "type": "array", "items": {"type": "string"}}}, "required": ["foo"]}
the object {"foo": ["bar", "baz"]} is a well-formatted instance of the schema. The object {"properties": {"foo": ["bar", "baz"]}} is not well-formatted.
Expand All @@ -153,7 +154,7 @@ Future<Structured> generateTitleAndSummaryForMemory(String transcript, List<Memo
.replaceAll(' ', '')
.trim();
// debugPrint(prompt);
var structured = (await executeGptPrompt(prompt)).replaceAll('```', '').replaceAll('json', '').trim();
var structured = extractJson(await executeGptPrompt(prompt));
return Structured.fromJson(jsonDecode(structured));
}

Expand Down
34 changes: 34 additions & 0 deletions apps/AppWithWearable/lib/utils/string_utils.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// string_utils.dart

String extractJson(String input) {
int braceCount = 0;
int startIndex = -1;
int endIndex = -1;

for (int i = 0; i < input.length; i++) {
switch (input[i]) {
case '{':
braceCount++;
startIndex = (startIndex == -1) ? i : startIndex;
break;
case '}':
braceCount--;
if (braceCount == 0 && startIndex != -1) {
endIndex = i;
break;
}
break;
default:
continue;
}

if (endIndex != -1) {
break;
}
}

if (startIndex != -1 && endIndex != -1) {
return input.substring(startIndex, endIndex + 1);
}
return '';
}

0 comments on commit 6437f21

Please sign in to comment.