Skip to content

Commit

Permalink
[ Add ] full support for AI instruction option
Browse files Browse the repository at this point in the history
  • Loading branch information
anasfik committed Dec 1, 2023
1 parent afd763d commit 0df4ed4
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
3 changes: 3 additions & 0 deletions lib/src/commands/start_command/start_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class StartCommand extends Command<int> {
langs: asConfig.langs,
languageLocalizationMaxDelay: asConfig.languageLocalizationMaxDelay,
operationId: jsonPartitionRes.operationId,
instruction: asConfig.instruction,
);

logger
Expand Down Expand Up @@ -269,6 +270,7 @@ class StartCommand extends Command<int> {
required Iterable<String> langs,
required String operationId,
required int? languageLocalizationMaxDelay,
required String? instruction,
}) async {
final completer = Completer<LangSyncServerResultSSE>();

Expand All @@ -277,6 +279,7 @@ class StartCommand extends Command<int> {
langs: langs,
operationId: operationId,
languageLocalizationMaxDelay: languageLocalizationMaxDelay,
instruction: instruction,
);

LangSyncServerResultSSE? resultSSE;
Expand Down
18 changes: 11 additions & 7 deletions lib/src/etc/controllers/yaml.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:io';

import 'package:langsync/src/etc/controllers/config_file.dart';
import 'package:langsync/src/etc/extensions.dart';
import 'package:yaml/yaml.dart' as yaml;

class YamlController extends ConfigFile {
Expand Down Expand Up @@ -30,14 +31,17 @@ class YamlController extends ConfigFile {
config,
callback: (entry) async {
if (entry.value is String) {
await super.writeToConfigFile(
"\n ${entry.key}: '${entry.value}' \n",
);
} else if (entry.value is List) {
await super.writeToConfigFile(
'\n ${entry.key}: ${entry.value} \n',
);
if ((entry.value as String).isPathToFileOrFolder()) {
await super.writeToConfigFile(
"\n ${entry.key}: '${entry.value}' \n",
);
return;
}
}

await super.writeToConfigFile(
'\n ${entry.key}: ${entry.value} \n',
);
},
);
}
Expand Down
8 changes: 8 additions & 0 deletions lib/src/etc/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,12 @@ extension StringExt on String {
String tr() {
return this;
}

String ensureStringSymbol() {
return replaceAll("'", '"');
}

bool isPathToFileOrFolder() {
return File(this).existsSync() || Directory(this).existsSync();
}
}
1 change: 1 addition & 0 deletions lib/src/etc/models/config.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:equatable/equatable.dart';
import 'package:langsync/src/etc/extensions.dart';
import 'package:yaml/yaml.dart';

class LangSyncConfig extends Equatable {
Expand Down
6 changes: 5 additions & 1 deletion lib/src/etc/networking/client.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:convert';
import 'dart:io';
import 'package:langsync/src/etc/models/api_key_res.dart';
import 'package:langsync/src/etc/models/config.dart';
import 'package:langsync/src/etc/models/lang_output.dart';
import 'package:langsync/src/etc/models/operation.dart';
import 'package:langsync/src/etc/models/result_locale.dart';
Expand All @@ -21,8 +22,9 @@ class NetClient extends NetClientBoilerPlate {
required Iterable<String> langs,
required String apiKey,
required String operationId,
required int? languageLocalizationMaxDelay,
bool includeOutput = false,
required int? languageLocalizationMaxDelay,
required String? instruction,
}) {
return sseStreamReq<List<LangSyncServerSSE>>(
'/process-translation',
Expand All @@ -33,6 +35,8 @@ class NetClient extends NetClientBoilerPlate {
'langs': langs.toList(),
'includeOutput': includeOutput,
'languageLocalizationMaxDelay': languageLocalizationMaxDelay,
if (instruction != null && instruction.isNotEmpty)
'instruction': instruction,
},
(res) {
final split = res.split('\n\n').where((element) => element.isNotEmpty);
Expand Down

0 comments on commit 0df4ed4

Please sign in to comment.