Skip to content

Commit

Permalink
Merge pull request #1 from ljeanner/lucile-init-cicd-pipeline
Browse files Browse the repository at this point in the history
Lucile init cicd pipeline
  • Loading branch information
ljeanner authored Dec 16, 2024
2 parents 5c27a67 + 9ae2be1 commit 74edcb8
Show file tree
Hide file tree
Showing 42 changed files with 1,234 additions and 285 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/terraform.yml
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
12 changes: 12 additions & 0 deletions VirtualTeacherGenAIDemo.Server/AI/DocIntOCREngine.cs
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();
}
}
}
29 changes: 18 additions & 11 deletions VirtualTeacherGenAIDemo.Server/Controllers/AgentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,13 @@ public async Task<IEnumerable<AgentItem>> GetAgentsByType(string type, bool with
return await _agentService.GetByTypeAsync(type);
}

//function to return all agents
[HttpGet("All")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<IEnumerable<AgentItem>> GetAllAgents()
{

return await _agentService.GetAllAgentsAsync();
}


//function Get by Id
[HttpGet("{id}")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<ActionResult<AgentItem>> Get(string id, string type)
Expand All @@ -56,23 +52,23 @@ public async Task<ActionResult<AgentItem>> Get(string id, string type)
[HttpPost]
[ProducesResponseType(StatusCodes.Status201Created)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<ActionResult<AgentItem>> Post([FromBody] AgentItem agent)
public async Task<ActionResult<AgentItem>> Post(AgentItem agent)
{
if (agent == null)
{
return BadRequest("Agent item is null.");
}

agent.Id = Guid.NewGuid().ToString();

await _agentService.AddAgentAsync(agent);
return CreatedAtAction(nameof(Get), new { id = agent.Id, type = agent.Type }, agent);
}

//For update agent
[HttpPut("{id}")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<IActionResult> Put(string id, [FromBody] AgentItem agent)
public async Task<IActionResult> Put(string id, AgentItem agent)
{
if (agent == null || agent.Id != id)
{
Expand All @@ -85,23 +81,22 @@ public async Task<IActionResult> Put(string id, [FromBody] AgentItem agent)
return NotFound();
}


await _agentService.UpdateAgentAsync(agent);
return NoContent();

}

//For delete agent
[HttpDelete("{agentid}")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<IActionResult> Delete(string agentid, string type )
public async Task<IActionResult> Delete(string agentid, string type)
{
if (string.IsNullOrWhiteSpace(agentid) || string.IsNullOrWhiteSpace(type))
{
return BadRequest("Agent id or type is missing");
}

var agentToDelete = await _agentService.GetByIdAsync(agentid,type);
var agentToDelete = await _agentService.GetByIdAsync(agentid, type);
if (agentToDelete == null)
{
return NotFound("Agent not found");
Expand All @@ -110,5 +105,17 @@ public async Task<IActionResult> Delete(string agentid, string type )
await _agentService.DeleteAgentAsync(agentToDelete);
return NoContent();
}

private async Task HandleFileUpload(IFormFile file)
{
if (file != null && file.Length > 0)
{
var filePath = Path.Combine("uploads", file.FileName);
using (var stream = new FileStream(filePath, FileMode.Create))
{
await file.CopyToAsync(stream);
}
}
}
}
}
8 changes: 4 additions & 4 deletions VirtualTeacherGenAIDemo.Server/Controllers/ChatController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public ChatController(ChatService chatService)

[HttpPost("message",Name = "message")]
[ProducesResponseType(StatusCodes.Status200OK)]
public IResult Post([FromBody] ChatHistoryRequest chatHistory, CancellationToken token)
public IResult Post([FromBody] ChatHistoryRequest chatHistory,string agentId, string connectionId, CancellationToken token)
{
return _chatService.GetChat(chatHistory, token);
return _chatService.GetChat(chatHistory,agentId,connectionId, token);
}


Expand All @@ -41,9 +41,9 @@ public IResult Post([FromBody] ChatHistoryRequest chatHistory, CancellationToken
//Delete chat message
[HttpDelete("message/{messageId}")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task DeleteMessage(string messageId, string chatid, CancellationToken token)
public async Task DeleteMessage([FromBody] DeleteMessageRequest message, CancellationToken token)
{
await _chatService.DeleteMessage(messageId, chatid);
await _chatService.DeleteMessage(message.MessageId, message.SessionId);

}

Expand Down
44 changes: 44 additions & 0 deletions VirtualTeacherGenAIDemo.Server/Controllers/FileUploadController.cs
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();
}
}
}
15 changes: 13 additions & 2 deletions VirtualTeacherGenAIDemo.Server/Controllers/SessionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using VirtualTeacherGenAIDemo.Server.Models.Request;
using VirtualTeacherGenAIDemo.Server.Models.Storage;
using VirtualTeacherGenAIDemo.Server.Services;
using VirtualTeacherGenAIDemo.Server.Storage;

namespace VirtualTeacherGenAIDemo.Server.Controllers
{
Expand All @@ -18,7 +19,7 @@ public SessionController(SessionService sessionService)
}


[HttpGet("history/{userId}", Name ="history")]
[HttpGet("history/{userId}", Name = "history")]
[ProducesResponseType(StatusCodes.Status200OK)]
public IEnumerable<SessionItem> Get(string userId, CancellationToken token)
{
Expand All @@ -34,7 +35,7 @@ public async Task CompleteSession([FromBody] CompleteSessionRequest request, Can
}

//Get all not complete session
[HttpGet("notCompleted/{userId}", Name ="sessions")]
[HttpGet("notCompleted/{userId}", Name = "sessions")]
public IEnumerable<SessionItem> GetNotCompletedSessions(string userId)
{
return _sessionService.GetNotCompletedSession(userId);
Expand All @@ -47,5 +48,15 @@ public async Task<SessionItem> GetSession(string id, string userId)
{
return await _sessionService.GetSession(id, userId);
}

[HttpDelete("delete")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<IActionResult> DeleteSession([FromBody] DeleteSessionRequest request, [FromServices] MessageRepository messageRepository, CancellationToken token)
{
await _sessionService.DeleteSessionAsync(request.SessionId, request.UserId, messageRepository, token);
return Ok();
}


}
}
93 changes: 93 additions & 0 deletions VirtualTeacherGenAIDemo.Server/Controllers/TestParseDocument.cs
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();
}
}
}
Loading

0 comments on commit 74edcb8

Please sign in to comment.