Skip to content
Merged
Prev Previous commit
Next Next commit
use service name in logs instead of hardcoded value, fall back to app ID
Signed-off-by: Julien Veyssier <[email protected]>
  • Loading branch information
julien-nc committed Jul 10, 2025
commit f00717ea9a39daef286028f802866fe0fe2164a7
20 changes: 11 additions & 9 deletions lib/TaskProcessing/AudioToAudioChatProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ public function process(?string $userId, array $input, callable $reportProgress)

$sttModel = $this->appConfig->getValueString(Application::APP_ID, 'default_stt_model_id', Application::DEFAULT_MODEL_ID) ?: Application::DEFAULT_MODEL_ID;

$serviceName = $this->appConfig->getValueString(Application::APP_ID, 'service_name') ?: Application::APP_ID;

/////////////// Using the chat API if connected to OpenAI
if ($this->openAiAPIService->isUsingOpenAi()) {
$b64Audio = base64_encode($inputFile->getContent());
Expand All @@ -216,7 +218,7 @@ public function process(?string $userId, array $input, callable $reportProgress)
$inputTranscription = $this->openAiAPIService->transcribeFile($userId, $inputFile, false, $sttModel);
$result['input_transcript'] = $inputTranscription;
} catch (Exception $e) {
$this->logger->warning('OpenAI\'s Whisper transcription failed with: ' . $e->getMessage(), ['exception' => $e]);
$this->logger->warning($serviceName . ' transcription failed with: ' . $e->getMessage(), ['exception' => $e]);
}

return $result;
Expand All @@ -227,19 +229,19 @@ public function process(?string $userId, array $input, callable $reportProgress)
try {
$inputTranscription = $this->openAiAPIService->transcribeFile($userId, $inputFile, false, $sttModel);
} catch (Exception $e) {
$this->logger->warning('OpenAI\'s Whisper transcription failed with: ' . $e->getMessage(), ['exception' => $e]);
throw new RuntimeException('OpenAI\'s Whisper transcription failed with: ' . $e->getMessage());
$this->logger->warning($serviceName . ' transcription failed with: ' . $e->getMessage(), ['exception' => $e]);
throw new RuntimeException($serviceName . ' transcription failed with: ' . $e->getMessage());
}

// free prompt
try {
$completion = $this->openAiAPIService->createChatCompletion($userId, $llmModel, $inputTranscription, $systemPrompt, $history, 1, 1000);
$completion = $completion['messages'];
} catch (Exception $e) {
throw new RuntimeException('OpenAI/LocalAI request failed: ' . $e->getMessage());
throw new RuntimeException($serviceName . ' chat completion request failed: ' . $e->getMessage());
}
if (count($completion) === 0) {
throw new RuntimeException('No completion in OpenAI/LocalAI response.');
throw new RuntimeException('No completion in ' . $serviceName . ' response.');
}
$llmResult = array_pop($completion);

Expand All @@ -248,17 +250,17 @@ public function process(?string $userId, array $input, callable $reportProgress)
$apiResponse = $this->openAiAPIService->requestSpeechCreation($userId, $llmResult, $ttsModel, $outputVoice, $speed);

if (!isset($apiResponse['body'])) {
$this->logger->warning('OpenAI/LocalAI\'s text to speech generation failed: no speech returned');
throw new RuntimeException('OpenAI/LocalAI\'s text to speech generation failed: no speech returned');
$this->logger->warning($serviceName . ' text to speech generation failed: no speech returned');
throw new RuntimeException($serviceName . ' text to speech generation failed: no speech returned');
}
return [
'output' => $apiResponse['body'],
'output_transcript' => $llmResult,
'input_transcript' => $inputTranscription,
];
} catch (\Exception $e) {
$this->logger->warning('OpenAI/LocalAI\'s text to speech generation failed with: ' . $e->getMessage(), ['exception' => $e]);
throw new RuntimeException('OpenAI/LocalAI\'s text to speech generation failed with: ' . $e->getMessage());
$this->logger->warning($serviceName . ' text to speech generation failed with: ' . $e->getMessage(), ['exception' => $e]);
throw new RuntimeException($serviceName . ' text to speech generation failed with: ' . $e->getMessage());
}
}
}