forked from fwickert/VirtualTeacherGenAIDemo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from ljeanner/lucile-init-cicd-pipeline
Lucile init cicd pipeline
- Loading branch information
Showing
42 changed files
with
1,234 additions
and
285 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
name: Terraform | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
terraform: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Terraform | ||
uses: hashicorp/setup-terraform@v2 | ||
with: | ||
terraform_version: 1.0.11 | ||
|
||
- name: Set up Azure credentials | ||
uses: azure/login@v1 | ||
with: | ||
creds: ${{ secrets.AZURE_CREDENTIALS }} | ||
|
||
- name: Initialize Terraform | ||
run: terraform init | ||
working-directory: ./deploy | ||
|
||
- name: Validate Terraform | ||
run: terraform validate | ||
working-directory: ./deploy | ||
|
||
- name: Plan Terraform | ||
run: terraform plan | ||
working-directory: ./deploy | ||
|
||
- name: Apply Terraform | ||
if: github.ref == 'refs/heads/main' | ||
run: terraform apply -auto-approve | ||
working-directory: ./deploy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using Microsoft.KernelMemory.DataFormats; | ||
|
||
namespace VirtualTeacherGenAIDemo.Server.AI | ||
{ | ||
public class DocIntOCREngine : IOcrEngine | ||
{ | ||
public Task<string> ExtractTextFromImageAsync(Stream imageContent, CancellationToken cancellationToken = default) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
VirtualTeacherGenAIDemo.Server/Controllers/FileUploadController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using System.Collections.Concurrent; | ||
using System.IO; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using VirtualTeacherGenAIDemo.Server.Services; | ||
|
||
namespace VirtualTeacherGenAIDemo.Server.Controllers | ||
{ | ||
[Route("api/[controller]")] | ||
[ApiController] | ||
public class FileUploadController : ControllerBase | ||
{ | ||
private readonly FileUploadService _fileUploadService; | ||
private static readonly ConcurrentDictionary<string, MemoryStream> _fileStreams = new(); | ||
|
||
public FileUploadController([FromServices] FileUploadService fileUploadService) | ||
{ | ||
_fileUploadService = fileUploadService; | ||
} | ||
|
||
[HttpPost()] | ||
public async Task<IActionResult> UploadFile(string connectionId, string agentId, IFormFile file, [FromForm] string fileName, [FromForm] string fileId, [FromForm] int chunkIndex, [FromForm] int totalChunks, CancellationToken token) | ||
{ | ||
if (!_fileStreams.ContainsKey(fileId)) | ||
{ | ||
_fileStreams[fileId] = new MemoryStream(); | ||
} | ||
|
||
var fileStream = _fileStreams[fileId]; | ||
await file.CopyToAsync(fileStream, token); | ||
|
||
if (chunkIndex == totalChunks - 1) | ||
{ | ||
fileStream.Position = 0; | ||
_ = Task.Run(() => _fileUploadService.ParseDocument(fileStream, fileName , agentId, connectionId, token)); | ||
_fileStreams.TryRemove(fileId, out _); | ||
} | ||
|
||
return Ok(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
VirtualTeacherGenAIDemo.Server/Controllers/TestParseDocument.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Azure; | ||
using Azure.AI.DocumentIntelligence; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
using Microsoft.KernelMemory; | ||
using StackExchange.Redis; | ||
|
||
namespace VirtualTeacherGenAIDemo.Server.Controllers | ||
{ | ||
[Route("api/[controller]")] | ||
[ApiController] | ||
public class TestParseDocument : ControllerBase | ||
{ | ||
private IKernelMemory _kernelMemory; | ||
|
||
public TestParseDocument([FromServices] IKernelMemory kernelMemory) | ||
{ | ||
_kernelMemory = kernelMemory; | ||
} | ||
|
||
[HttpGet] | ||
public async Task<IActionResult> Get() | ||
{ | ||
string endpoint = "https://virtualteachdocint.cognitiveservices.azure.com/"; | ||
string key = "7bANKH6Dm7ZIqfrXl4dd3AwUYaQq8TkTrumeJbL4fXXV5bcy8NQhJQQJ99ALAC5RqLJXJ3w3AAALACOGGNQ4"; | ||
|
||
var client = new DocumentIntelligenceClient(new Uri(endpoint), new AzureKeyCredential(key)); | ||
|
||
string filePath = @"D:\temp\chanel\page 7.pdf"; | ||
if (!System.IO.File.Exists(filePath)) | ||
{ | ||
return NotFound("File not found"); | ||
} | ||
|
||
|
||
using (var stream = System.IO.File.OpenRead(filePath)) | ||
{ | ||
var binaryData = BinaryData.FromStream(stream); | ||
|
||
var content = new AnalyzeDocumentContent() { Base64Source = binaryData }; | ||
|
||
|
||
int i = 1; | ||
|
||
while (true) | ||
{ | ||
try | ||
{ | ||
Operation<AnalyzeResult> operation = await client.AnalyzeDocumentAsync(WaitUntil.Completed, "prebuilt-layout", content, outputContentFormat: ContentFormat.Markdown, | ||
pages: i.ToString()); | ||
|
||
|
||
AnalyzeResult result = operation.Value; | ||
|
||
Console.WriteLine(result.Content); | ||
|
||
await _kernelMemory.DeleteDocumentAsync(i.ToString(), index: "test"); | ||
|
||
//Add tag with the agent ID => Thanif I search with agent I can filter by his id. | ||
await _kernelMemory.ImportTextAsync(result.Content, i.ToString(), index: "test"); | ||
i++; | ||
} | ||
catch (Exception ex) | ||
{ | ||
break; | ||
} | ||
|
||
|
||
} | ||
|
||
|
||
|
||
//DocumentUploadRequest documentUploadRequest = new DocumentUploadRequest(); | ||
//documentUploadRequest.Files.Add(new DocumentUploadRequest.UploadedFile() | ||
//{ | ||
// FileContent = stream, | ||
// FileName = "page 7.pdf" | ||
//}); | ||
//documentUploadRequest.DocumentId = "page 7.pdf"; | ||
//documentUploadRequest.Steps.Add(""); | ||
|
||
|
||
|
||
//var docIntOcrEngine = await _kernelMemory.ImportDocumentAsync(documentUploadRequest); | ||
|
||
|
||
} | ||
|
||
return Ok(); | ||
} | ||
} | ||
} |
Oops, something went wrong.