logGptRequest function

void logGptRequest({
  1. required I18nLocale fromLocale,
  2. required I18nLocale toLocale,
  3. required String fromFile,
  4. required String toFile,
  5. required String outDir,
  6. required int promptCount,
  7. required GptPrompt prompt,
  8. required GptResponse response,
})

Logs the GPT request and response to a file.

Implementation

void logGptRequest({
  required I18nLocale fromLocale,
  required I18nLocale toLocale,
  required String fromFile,
  required String toFile,
  required String outDir,
  required int promptCount,
  required GptPrompt prompt,
  required GptResponse response,
}) {
  final path = PathUtils.withFileName(
    directoryPath: outDir,
    fileName: '_gpt_${promptCount.toString().padLeft(2, '0')}.txt',
    pathSeparator: Platform.pathSeparator,
  );
  FileUtils.writeFile(
    path: path,
    content: '''
### Meta ###
From: <${fromLocale.languageTag}> $fromFile
To: <${toLocale.languageTag}> $toFile

### Tokens ###
Input: ${response.promptTokens}
Output: ${response.completionTokens}
Total: ${response.totalTokens}

### Conversation ###

>> System:
${prompt.system}

>> User:
${prompt.user}

>> Assistant:
${response.rawMessage}

### JSON ###
Input:
${_encoder.convert(prompt.userJSON)}

Output:
${_encoder.convert(response.jsonMessage)}
''',
  );

  print(' -> Logs: $path');
}