IConversationAttachmentService
This commit is contained in:
parent
2f2ef32b73
commit
b55abdf4dc
|
|
@ -24,7 +24,7 @@ It's written in C# running on .Net Core that is full cross-platform framework, t
|
|||
* Built-in multi-agents and conversation with state management.
|
||||
* Support multiple LLM Planning approaches to handle different tasks.
|
||||
* Built-in RAG related interfaces, Memeory based vector searching.
|
||||
* Support multiple LLM platforms (ChatGPT 3.5 / 4.0, PaLM 2, LLaMA 2).
|
||||
* Support multiple LLM platforms (ChatGPT 3.5 / 4.0, PaLM 2, LLaMA 2, HuggingFace).
|
||||
* Allow multiple agents with different responsibilities cooperate to complete complex tasks.
|
||||
* Build, test, evaluate and audit your LLM agent in one place.
|
||||
* Support different open source UI [Chatbot UI](src/Plugins/BotSharp.Plugin.ChatbotUI/Chatbot-UI.md), [HuggingChat UI](src/Plugins/BotSharp.Plugin.HuggingFace/HuggingChat-UI.md).
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
namespace BotSharp.Abstraction.Conversations;
|
||||
|
||||
public interface IConversationAttachmentService
|
||||
{
|
||||
string GetDirectory(string conversationId);
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
namespace BotSharp.Abstraction.Conversations.Models;
|
||||
|
||||
public class Attachment
|
||||
{
|
||||
public string ContentType { get; set; }
|
||||
|
||||
//
|
||||
// Summary:
|
||||
// Gets the raw Content-Disposition header of the uploaded file.
|
||||
public string ContentDisposition { get; set; }
|
||||
|
||||
//
|
||||
// Summary:
|
||||
// Gets the file length in bytes.
|
||||
public long Length { get; set; }
|
||||
|
||||
//
|
||||
// Summary:
|
||||
// Gets the file name from the Content-Disposition header.
|
||||
public string FileName { get; set; }
|
||||
}
|
||||
|
|
@ -102,6 +102,8 @@ public static class BotSharpServiceCollectionExtensions
|
|||
services.AddScoped<IEvaluatingService, EvaluatingService>();
|
||||
services.AddScoped<IExecutionLogger, ExecutionLogger>();
|
||||
|
||||
services.AddScoped<IConversationAttachmentService, ConversationAttachmentService>();
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
using BotSharp.Abstraction.Repositories;
|
||||
using System.IO;
|
||||
|
||||
namespace BotSharp.Core.Conversations.Services;
|
||||
|
||||
public class ConversationAttachmentService : IConversationAttachmentService
|
||||
{
|
||||
private readonly BotSharpDatabaseSettings _dbSettings;
|
||||
private readonly IServiceProvider _services;
|
||||
|
||||
public ConversationAttachmentService(
|
||||
BotSharpDatabaseSettings dbSettings,
|
||||
IServiceProvider services)
|
||||
{
|
||||
_dbSettings = dbSettings;
|
||||
_services = services;
|
||||
}
|
||||
|
||||
public string GetDirectory(string conversationId)
|
||||
{
|
||||
var dir = Path.Combine(_dbSettings.FileRepository, "conversations", conversationId, "attachments");
|
||||
if (!Directory.Exists(dir))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,8 @@ using BotSharp.Abstraction.ApiAdapters;
|
|||
using BotSharp.Abstraction.Conversations.Models;
|
||||
using BotSharp.Abstraction.Models;
|
||||
using BotSharp.OpenAPI.ViewModels.Conversations;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Net.Http.Headers;
|
||||
|
||||
namespace BotSharp.OpenAPI.Controllers;
|
||||
|
||||
|
|
@ -78,4 +80,31 @@ public class ConversationController : ControllerBase, IApiAdapter
|
|||
|
||||
return response;
|
||||
}
|
||||
|
||||
[HttpPost("/conversation/{agentId}/{conversationId}/attachments")]
|
||||
public IActionResult UploadAttachments([FromRoute] string agentId,
|
||||
[FromRoute] string conversationId,
|
||||
IFormFile[] files)
|
||||
{
|
||||
if (files != null && files.Length > 0)
|
||||
{
|
||||
var attachmentService = _services.GetRequiredService<IConversationAttachmentService>();
|
||||
var dir = attachmentService.GetDirectory(conversationId);
|
||||
foreach (var file in files)
|
||||
{
|
||||
// Save the file, process it, etc.
|
||||
var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
|
||||
var filePath = Path.Combine(dir, fileName);
|
||||
|
||||
using (var stream = new FileStream(filePath, FileMode.Create))
|
||||
{
|
||||
file.CopyTo(stream);
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(new { message = "File uploaded successfully." });
|
||||
}
|
||||
|
||||
return BadRequest(new { message = "Invalid file." });
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue