detect method

Future detect(
  1. String text
)

METHOD FOR DETECTING A STRING OF TEXT LANGUAGE

Implementation

Future<dynamic> detect(String text)async{
  final client = OpenAIClient(
    apiKey: mainClient.openAIApikey,
    organization: mainClient.openAIOrgID,
  );

    ///CHECK IF THE MODEL EXISTS
    if(kAllowedModels.contains(mainClient.model)){
      final res = await client.createChatCompletion(
        request: CreateChatCompletionRequest(
          model: ChatCompletionModel.modelId(mainClient.model),
          maxTokens: 5,
          messages: [
            const ChatCompletionMessage.system(
              content: "You are a helpful translator that detect a text and return only the locale code of the language the text was written in. Example format ' en_us ' ",
            ),
            ChatCompletionMessage.user(
              content: ChatCompletionUserMessageContent.string("what language is '$text' written in"),
            ),
          ],
          temperature: 0,
        ),
      );
      return {"status" : "success", "detected_language" : res.choices.first.message.content, "original_text" : text};
    }else{
      return {"status" : "error", "message" : "Invalid or unsupported openAI model"};
    }
}