Skip to content

Commit

Permalink
Refactored all comments
Browse files Browse the repository at this point in the history
  • Loading branch information
MananGandhi1810 committed May 22, 2024
1 parent ecde0d4 commit d218316
Show file tree
Hide file tree
Showing 22 changed files with 424 additions and 526 deletions.
2 changes: 0 additions & 2 deletions lib/cloudflare_ai.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,3 @@
library cloudflare_ai;

export 'src/cloudflare_ai_base.dart';

// TODO: Export any libraries intended for clients of this package.
38 changes: 16 additions & 22 deletions lib/src/language_translation/language_translation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,20 @@ export 'response.dart';
export 'languages.dart';

class LanguageTranslationModel {
late String accountId;

/// Account ID, available on Cloudflare daskboard
late String apiKey;
late String accountId;

/// API Key, can by generated from the Cloudflare dashboard
late LanguageTranslationModels model;
late String apiKey;

/// The model to use
NetworkService networkService = NetworkService();
late LanguageTranslationModels model;

/// Network service object
late String baseUrl;
NetworkService networkService = NetworkService();

/// Base URL for the API
late String baseUrl;

LanguageTranslationModel({
required this.accountId,
Expand All @@ -30,49 +29,44 @@ class LanguageTranslationModel {
}) {
baseUrl = "https://api.cloudflare.com/client/v4/accounts/$accountId/ai/run";
if (accountId.trim() == "") {
throw Exception("Account ID cannot be empty");

/// Throw an exception if account ID is empty
throw Exception("Account ID cannot be empty");
}
if (apiKey.trim() == "") {
throw Exception("API Key cannot be empty");

/// Throw an exception if API key is empty
throw Exception("API Key cannot be empty");
}
}

/// Asynchronous function which returns summarized text through the TextSummarizationResponse object
Future<LanguageTranslationResponse> translate(
String text,

/// Text to translate
Languages from,
String text,

/// Language to translate from
Languages to,
Languages from,

/// Language to translate to
Languages to,
) async {
/// Post request to the API
Map<String, dynamic> res =
await networkService.post("$baseUrl/${model.value}", apiKey, {
"source_lang": from.value,

/// Source language
"target_lang": to.value,
"source_lang": from.value,

/// Target language
"text": text,
"target_lang": to.value,

/// Text to translate
"text": text,
});

/// Post request to the API
/// Create a response object from the JSON data
LanguageTranslationResponse response =
LanguageTranslationResponse.fromJson(res['data']);

/// Create a response object from the JSON data
return response;

/// Return the response object
return response;
}
}
Loading

0 comments on commit d218316

Please sign in to comment.