Skip to content

Commit

Permalink
adding in source code
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafael-Pascoal committed May 28, 2024
1 parent e43d912 commit 02f431b
Show file tree
Hide file tree
Showing 56 changed files with 1,430 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34723.18
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AzureDocumentIntelligenceAPI", "AzureDocumentIntelligenceAPI\AzureDocumentIntelligenceAPI.csproj", "{A2D64584-0E8B-4FB5-B1B1-698C105562B3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A2D64584-0E8B-4FB5-B1B1-698C105562B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A2D64584-0E8B-4FB5-B1B1-698C105562B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A2D64584-0E8B-4FB5-B1B1-698C105562B3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A2D64584-0E8B-4FB5-B1B1-698C105562B3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CFE9E77C-70DA-4AE3-A676-923A16152618}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@AzureDocumentIntelligenceAPI_HostAddress = http://localhost:5124

GET {{AzureDocumentIntelligenceAPI_HostAddress}}/weatherforecast/
Accept: application/json

###
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
using Microsoft.AspNetCore.Mvc;
using AzureDocumentIntelligenceAPI.Services;
using AzureDocumentIntelligenceAPI.Models;
using AzureDocumentIntelligenceAPI.Models.ClassifyDocument;
using AzureDocumentIntelligenceAPI.Models.ClassifyDocument;

namespace AzureDocumentIntelligenceAPI.Controllers
{
[ApiController]
[Route("[controller]")]
public class TestController : ControllerBase
{
private readonly AzureDocumentIntelligenceClient _client;
private readonly ILogger<TestController> _logger;

public TestController(AzureDocumentIntelligenceClient client, ILogger<TestController> logger)
{
_client = client;
_logger = logger;
}

//[HttpPost("build-classifier")]
//public async Task<IActionResult> BuildClassifier(BuildDocumentClassifierRequestBody requestBody)
//{
// try
// {
// _logger.LogInformation("Received request to build classifier.");
// var result = await _client.BuildClassifierAsync(requestBody);
// return Ok(result);
// }
// catch (Exception ex)
// {
// _logger.LogError(ex, $"Error occurred while building classifier. {ex.Message}");
// return StatusCode(500, $"Erro: {ex.Message}\n{ex.StackTrace}");
// }
//}

[HttpPost("classify-document")]
public async Task<IActionResult> ClassifyDocument(ClassifyDocumentRequestBody requestBody)
{
try
{
_logger.LogInformation("Received request to classify document.");
var result = await _client.ClassifyDocumentAsync(requestBody);
return Ok(result);
}
catch (Exception ex)
{
_logger.LogError(ex, $"Error occurred while classifying document. {ex.Message}");
return StatusCode(500, $"Erro: {ex.Message}\n{ex.StackTrace}");
}
}

//[HttpPost("classify-document-from-stream")]
//public async Task<IActionResult> ClassifyDocumentFromStream()
//{
// try
// {
// using (var stream = new MemoryStream())
// {
// await Request.Body.CopyToAsync(stream);
// stream.Seek(0, SeekOrigin.Begin);
// var result = await _client.ClassifyDocumentFromStreamAsync(stream);
// return Ok(result);
// }
// }
// catch (Exception ex)
// {
// return StatusCode(500, $"Erro: {ex.Message}");
// }
//}

//[HttpDelete("delete-classifier/{classifierId}")]
//public async Task<IActionResult> DeleteClassifier(string classifierId)
//{
// try
// {
// await _client.DeleteClassifierAsync(classifierId);
// return NoContent();
// }
// catch (Exception ex)
// {
// return StatusCode(500, $"Erro: {ex.Message}");
// }
//}

//[HttpGet("get-classifier/{classifierId}")]
//public async Task<IActionResult> GetClassifier(string classifierId)
//{
// try
// {
// var result = await _client.GetClassifierAsync(classifierId);
// return Ok(result);
// }
// catch (Exception ex)
// {
// return StatusCode(500, $"Erro: {ex.Message}");
// }
//}

//[HttpGet("get-classify-result/{operationId}")]
//public async Task<IActionResult> GetClassifyResult(string operationId)
//{
// try
// {
// var result = await _client.GetClassifyResultAsync(operationId);
// return Ok(result);
// }
// catch (Exception ex)
// {
// return StatusCode(500, $"Erro: {ex.Message}");
// }
//}

//[HttpGet("list-classifiers")]
//public async Task<IActionResult> ListClassifiers()
//{
// try
// {
// var result = await _client.ListClassifiersAsync();
// return Ok(result);
// }
// catch (Exception ex)
// {
// _logger.LogError(ex, $"Error occurred while listing classifiers. {ex.Message}");
// return StatusCode(500, $"Erro: {ex.Message}");
// }
//}


//[HttpPost("analyze-document")]
//public async Task<IActionResult> AnalyzeDocument([FromBody] AnalyzeDocumentRequestBody requestBody)
//{
// try
// {
// _logger.LogInformation("Received request to analyze document.");
// var result = await _client.AnalyzeDocumentAsync(requestBody);
// return Ok(result);
// }
// catch (Exception ex)
// {
// _logger.LogError(ex, $"Error occurred while analyzing document. {ex.Message}");
// return StatusCode(500, $"Erro: {ex.Message}\n{ex.StackTrace}");
// }
//}

//[HttpPost("analyze-document-from-stream")]
//public async Task<IActionResult> AnalyzeDocumentFromStream()
//{
// try
// {
// _logger.LogInformation("Received request to analyze document from stream.");
// using (var stream = new MemoryStream())
// {
// await Request.Body.CopyToAsync(stream);
// stream.Seek(0, SeekOrigin.Begin);
// var result = await _client.AnalyzeDocumentFromStreamAsync(stream);
// return Ok(result);
// }
// }
// catch (Exception ex)
// {
// _logger.LogError(ex, $"Error occurred while analyzing document from stream. {ex.Message}");
// return StatusCode(500, $"Erro: {ex.Message}\n{ex.StackTrace}");
// }
//}

//[HttpPost("build-model")]
//public async Task<IActionResult> BuildModel([FromBody] BuildDocumentModelRequestBody requestBody)
//{
// try
// {
// _logger.LogInformation("Received request to build model.");
// var result = await _client.BuildModelAsync(requestBody);
// return Ok(result);
// }
// catch (Exception ex)
// {
// _logger.LogError(ex, $"Error occurred while building model. {ex.Message}");
// return StatusCode(500, $"Erro: {ex.Message}\n{ex.StackTrace}");
// }
//}

//[HttpDelete("delete-model/{modelId}")]
//public async Task<IActionResult> DeleteModel(string modelId)
//{
// try
// {
// _logger.LogInformation($"Received request to delete model with modelId: {modelId}");
// await _client.DeleteModelAsync(modelId);
// return NoContent();
// }
// catch (Exception ex)
// {
// _logger.LogError(ex, $"Error occurred while deleting model. {ex.Message}");
// return StatusCode(500, $"Erro: {ex.Message}\n{ex.StackTrace}");
// }
//}

//[HttpGet("get-analyze-result/{operationId}")]
//public async Task<IActionResult> GetAnalyzeResult(string operationId)
//{
// try
// {
// _logger.LogInformation($"Received request to get analyze result with operationId: {operationId}");
// var result = await _client.GetAnalyzeResultAsync(operationId);
// return Ok(result);
// }
// catch (Exception ex)
// {
// _logger.LogError(ex, $"Error occurred while getting analyze result. {ex.Message}");
// return StatusCode(500, $"Erro: {ex.Message}\n{ex.StackTrace}");
// }
//}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Newtonsoft.Json;

namespace AzureDocumentIntelligenceAPI.Models
{
public class AzureBlobContentSource
{
/// <summary>
/// Azure Blob Storage container URL.
/// </summary>
[JsonProperty("containerUrl")]
public string? ContainerUrl { get; set; } = "";

/// <summary>
/// Blob name prefix.
/// </summary>
[JsonProperty("prefix")]
public string? Prefix { get; set; } = "";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Newtonsoft.Json;

namespace AzureDocumentIntelligenceAPI.Models
{
public class AzureBlobFileListContentSource
{
/// <summary>
/// Azure Blob Storage container URL.
/// </summary>
[JsonProperty("containerUrl")]
public string ContainerUrl { get; set; } = "";

/// <summary>
/// Path to a JSONL file within the container specifying a subset of documents.
/// </summary>
[JsonProperty("fileList")]
public string FileList { get; set; } = "";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Newtonsoft.Json;

namespace AzureDocumentIntelligenceAPI.Models
{
// Request body for building a document classifier.
public class BuildDocumentClassifierRequestBody
{
/// <summary>
/// Base classifierId on top of which to train the classifier.
/// </summary>
[JsonProperty("baseClassifierId")]
public string? BaseClassifierId { get; set; }

/// <summary>
/// Unique document classifier name.
/// </summary>
[JsonProperty("classifierId")]
public string? ClassifierId { get; set; }

/// <summary>
/// Document classifier description.
/// </summary>
[JsonProperty("description")]
public string? Description { get; set; }

/// <summary>
/// List of document types to classify against.
/// </summary>
[JsonProperty("docTypes")]
public List<ClassifierDocumentTypeDetails>? DocTypes { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Newtonsoft.Json;

namespace AzureDocumentIntelligenceAPI.Models
{
public class ClassifierDocumentTypeDetails
{
/// <summary>
/// Azure Blob Storage file list specifying the training data for a classifier document type. Either azureBlobSource or azureBlobFileListSource must be specified.
/// </summary>
[JsonProperty("azureBlobFileListSource")]
public AzureBlobFileListContentSource? AzureBlobFileListSource { get; set; }

/// <summary>
/// Azure Blob Storage location containing the training data for a classifier document type. Either azureBlobSource or azureBlobFileListSource must be specified.
/// </summary>
[JsonProperty("azureBlobSource")]
public AzureBlobContentSource? AzureBlobSource { get; set; }

/// <summary>
/// Type of training data source.
/// </summary>
[JsonProperty("sourceKind")]
public ContentSourceKind SourceKind { get; set; }
}
}
Loading

0 comments on commit 02f431b

Please sign in to comment.