Try catches, ensuring SuccessStatusCode
This commit is contained in:
1 parent
8b476e6939
commit
4494a2a202
4 files changed
+43
-20
No files matched your search
@@ -84,31 +84,54 @@ public class DocumentProcessingService(IServiceScopeFactory scopeFactory, ILogge
|
||||
|
||||
private async Task UnloadModel()
|
||||
{
|
||||
await using var scope = scopeFactory.CreateAsyncScope();
|
||||
var agentService = scope.ServiceProvider.GetRequiredService<LLMAgentService>();
|
||||
try
|
||||
{
|
||||
isWorking = true;
|
||||
await using var scope = scopeFactory.CreateAsyncScope();
|
||||
var agentService = scope.ServiceProvider.GetRequiredService<LLMAgentService>();
|
||||
|
||||
logger.LogInformation($"Unloading Model");
|
||||
isWorking = true;
|
||||
await agentService.UnloadModel();
|
||||
isWorking = false;
|
||||
logger.LogInformation($"Unloading Model");
|
||||
await agentService.UnloadModel();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogError(e.ToString());
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
isWorking = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private async Task<LmStudioLlmResponse> ProcessDocument(PaperlessDocument docToProcess)
|
||||
{
|
||||
await using var scope = scopeFactory.CreateAsyncScope();
|
||||
var agentService = scope.ServiceProvider.GetRequiredService<LLMAgentService>();
|
||||
var repository = scope.ServiceProvider.GetRequiredService<PaperlessDocumentRepository>();
|
||||
var llmResponse = new LmStudioLlmResponse();
|
||||
try
|
||||
{
|
||||
isWorking = true;
|
||||
|
||||
isWorking = true;
|
||||
await using var scope = scopeFactory.CreateAsyncScope();
|
||||
var agentService = scope.ServiceProvider.GetRequiredService<LLMAgentService>();
|
||||
var repository = scope.ServiceProvider.GetRequiredService<PaperlessDocumentRepository>();
|
||||
|
||||
logger.LogInformation($"Processing: {docToProcess}");
|
||||
logger.LogInformation($"Processing: {docToProcess}");
|
||||
|
||||
docToProcess.DocumentState = EDocumentState.Started;
|
||||
await repository.Update(docToProcess);
|
||||
|
||||
var llmResponse = await agentService.ProcessDocumentWithAI(docToProcess);
|
||||
|
||||
isWorking = false;
|
||||
docToProcess.DocumentState = EDocumentState.Started;
|
||||
await repository.Update(docToProcess);
|
||||
|
||||
llmResponse = await agentService.ProcessDocumentWithAI(docToProcess);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogError(e.ToString());
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
isWorking = false;
|
||||
}
|
||||
return llmResponse ?? new LmStudioLlmResponse();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user