refine instruct request model
This commit is contained in:
parent
96b891897c
commit
512d459c6b
|
|
@ -1,7 +0,0 @@
|
|||
namespace BotSharp.Abstraction.Files.Models;
|
||||
|
||||
public class InputMessageFiles
|
||||
{
|
||||
public List<BotSharpFile> Files { get; set; } = new List<BotSharpFile>();
|
||||
public BotSharpFile? Mask { get; set; }
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
namespace BotSharp.Abstraction.Models;
|
||||
|
||||
public class AiModel
|
||||
{
|
||||
public string Id { get; set; } = string.Empty;
|
||||
public string Model { get; set; } = string.Empty;
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public int MaxLength { get; set; }
|
||||
public int TokenLimit { get; set; }
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
namespace BotSharp.Abstraction.Models;
|
||||
|
||||
public class MessageConfig : InputMessageFiles
|
||||
public class MessageConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// Completion Provider
|
||||
|
|
@ -15,7 +15,7 @@ public class MessageConfig : InputMessageFiles
|
|||
public virtual string? Model { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Model name
|
||||
/// Model id
|
||||
/// </summary>
|
||||
[JsonPropertyName("model_id")]
|
||||
public virtual string? ModelId { get; set; } = null;
|
||||
|
|
@ -34,7 +34,7 @@ public class MessageConfig : InputMessageFiles
|
|||
/// <summary>
|
||||
/// Conversation states from input
|
||||
/// </summary>
|
||||
public List<MessageState> States { get; set; } = new List<MessageState>();
|
||||
public List<MessageState> States { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Agent task id
|
||||
|
|
|
|||
|
|
@ -294,9 +294,7 @@ public class ConversationController : ControllerBase
|
|||
}
|
||||
|
||||
[HttpPost("/conversation/{agentId}/{conversationId}/sse")]
|
||||
public async Task SendMessageSse([FromRoute] string agentId,
|
||||
[FromRoute] string conversationId,
|
||||
[FromBody] NewMessageModel input)
|
||||
public async Task SendMessageSse([FromRoute] string agentId, [FromRoute] string conversationId, [FromBody] NewMessageModel input)
|
||||
{
|
||||
var conv = _services.GetRequiredService<IConversationService>();
|
||||
var inputMsg = new RoleDialogModel(AgentRole.User, input.Text)
|
||||
|
|
@ -391,7 +389,7 @@ public class ConversationController : ControllerBase
|
|||
}
|
||||
|
||||
[HttpPost("/agent/{agentId}/conversation/{conversationId}/upload")]
|
||||
public async Task<string> UploadConversationMessageFiles([FromRoute] string agentId, [FromRoute] string conversationId, [FromBody] NewMessageModel input)
|
||||
public async Task<string> UploadConversationMessageFiles([FromRoute] string agentId, [FromRoute] string conversationId, [FromBody] InputMessageFiles input)
|
||||
{
|
||||
var convService = _services.GetRequiredService<IConversationService>();
|
||||
convService.SetConversationId(conversationId, input.States);
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ using BotSharp.Abstraction.Instructs;
|
|||
using BotSharp.Abstraction.Instructs.Models;
|
||||
using BotSharp.Core.Infrastructures;
|
||||
using BotSharp.OpenAPI.ViewModels.Instructs;
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
|
||||
namespace BotSharp.OpenAPI.Controllers;
|
||||
|
||||
|
|
@ -21,8 +20,7 @@ public class InstructModeController : ControllerBase
|
|||
}
|
||||
|
||||
[HttpPost("/instruct/{agentId}")]
|
||||
public async Task<InstructResult> InstructCompletion([FromRoute] string agentId,
|
||||
[FromBody] InstructMessageModel input)
|
||||
public async Task<InstructResult> InstructCompletion([FromRoute] string agentId, [FromBody] InstructMessageModel input)
|
||||
{
|
||||
var state = _services.GetRequiredService<IConversationStateService>();
|
||||
input.States.ForEach(x => state.SetState(x.Key, x.Value, activeRounds: x.ActiveRounds, source: StateSource.External));
|
||||
|
|
@ -80,7 +78,7 @@ public class InstructModeController : ControllerBase
|
|||
|
||||
#region Read image
|
||||
[HttpPost("/instruct/multi-modal")]
|
||||
public async Task<string> MultiModalCompletion([FromBody] IncomingMessageModel input)
|
||||
public async Task<string> MultiModalCompletion([FromBody] MultiModalRequest input)
|
||||
{
|
||||
var state = _services.GetRequiredService<IConversationStateService>();
|
||||
input.States.ForEach(x => state.SetState(x.Key, x.Value, activeRounds: x.ActiveRounds, source: StateSource.External));
|
||||
|
|
@ -102,7 +100,7 @@ public class InstructModeController : ControllerBase
|
|||
|
||||
#region Generate image
|
||||
[HttpPost("/instruct/image-generation")]
|
||||
public async Task<ImageGenerationViewModel> ImageGeneration([FromBody] IncomingMessageModel input)
|
||||
public async Task<ImageGenerationViewModel> ImageGeneration([FromBody] ImageGenerationRequest input)
|
||||
{
|
||||
var state = _services.GetRequiredService<IConversationStateService>();
|
||||
input.States.ForEach(x => state.SetState(x.Key, x.Value, activeRounds: x.ActiveRounds, source: StateSource.External));
|
||||
|
|
@ -128,7 +126,7 @@ public class InstructModeController : ControllerBase
|
|||
|
||||
#region Edit image
|
||||
[HttpPost("/instruct/image-variation")]
|
||||
public async Task<ImageGenerationViewModel> ImageVariation([FromBody] IncomingMessageModel input)
|
||||
public async Task<ImageGenerationViewModel> ImageVariation([FromBody] ImageVariationRequest input)
|
||||
{
|
||||
var state = _services.GetRequiredService<IConversationStateService>();
|
||||
input.States.ForEach(x => state.SetState(x.Key, x.Value, activeRounds: x.ActiveRounds, source: StateSource.External));
|
||||
|
|
@ -136,14 +134,13 @@ public class InstructModeController : ControllerBase
|
|||
|
||||
try
|
||||
{
|
||||
var image = input.Files.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x.FileUrl) || !string.IsNullOrWhiteSpace(x.FileData));
|
||||
if (image == null)
|
||||
if (input.File == null)
|
||||
{
|
||||
return new ImageGenerationViewModel { Message = "Error! Cannot find an image!" };
|
||||
}
|
||||
|
||||
var fileInstruct = _services.GetRequiredService<IFileInstructService>();
|
||||
var message = await fileInstruct.VaryImage(input.Provider, input.Model, image);
|
||||
var message = await fileInstruct.VaryImage(input.Provider, input.Model, input.File);
|
||||
imageViewModel.Content = message.Content;
|
||||
imageViewModel.Images = message.GeneratedImages.Select(x => ImageViewModel.ToViewModel(x)).ToList();
|
||||
return imageViewModel;
|
||||
|
|
@ -158,7 +155,7 @@ public class InstructModeController : ControllerBase
|
|||
}
|
||||
|
||||
[HttpPost("/instruct/image-edit")]
|
||||
public async Task<ImageGenerationViewModel> ImageEdit([FromBody] IncomingMessageModel input)
|
||||
public async Task<ImageGenerationViewModel> ImageEdit([FromBody] ImageEditRequest input)
|
||||
{
|
||||
var fileInstruct = _services.GetRequiredService<IFileInstructService>();
|
||||
var state = _services.GetRequiredService<IConversationStateService>();
|
||||
|
|
@ -167,12 +164,11 @@ public class InstructModeController : ControllerBase
|
|||
|
||||
try
|
||||
{
|
||||
var image = input.Files.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x.FileUrl) || !string.IsNullOrWhiteSpace(x.FileData));
|
||||
if (image == null)
|
||||
if (input.File == null)
|
||||
{
|
||||
return new ImageGenerationViewModel { Message = "Error! Cannot find a valid image file!" };
|
||||
}
|
||||
var message = await fileInstruct.EditImage(input.Provider, input.Model, input.Text, image);
|
||||
var message = await fileInstruct.EditImage(input.Provider, input.Model, input.Text, input.File);
|
||||
imageViewModel.Content = message.Content;
|
||||
imageViewModel.Images = message.GeneratedImages.Select(x => ImageViewModel.ToViewModel(x)).ToList();
|
||||
return imageViewModel;
|
||||
|
|
@ -187,7 +183,7 @@ public class InstructModeController : ControllerBase
|
|||
}
|
||||
|
||||
[HttpPost("/instruct/image-mask-edit")]
|
||||
public async Task<ImageGenerationViewModel> ImageMaskEdit([FromBody] IncomingMessageModel input)
|
||||
public async Task<ImageGenerationViewModel> ImageMaskEdit([FromBody] ImageMaskEditRequest input)
|
||||
{
|
||||
var fileInstruct = _services.GetRequiredService<IFileInstructService>();
|
||||
var state = _services.GetRequiredService<IConversationStateService>();
|
||||
|
|
@ -196,7 +192,7 @@ public class InstructModeController : ControllerBase
|
|||
|
||||
try
|
||||
{
|
||||
var image = input.Files.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x.FileUrl) || !string.IsNullOrWhiteSpace(x.FileData));
|
||||
var image = input.File;
|
||||
var mask = input.Mask;
|
||||
if (image == null || mask == null)
|
||||
{
|
||||
|
|
@ -219,7 +215,7 @@ public class InstructModeController : ControllerBase
|
|||
|
||||
#region Pdf
|
||||
[HttpPost("/instruct/pdf-completion")]
|
||||
public async Task<PdfCompletionViewModel> PdfCompletion([FromBody] IncomingMessageModel input)
|
||||
public async Task<PdfCompletionViewModel> PdfCompletion([FromBody] MultiModalRequest input)
|
||||
{
|
||||
var state = _services.GetRequiredService<IConversationStateService>();
|
||||
input.States.ForEach(x => state.SetState(x.Key, x.Value, activeRounds: x.ActiveRounds, source: StateSource.External));
|
||||
|
|
@ -244,7 +240,7 @@ public class InstructModeController : ControllerBase
|
|||
|
||||
#region Audio
|
||||
[HttpPost("/instruct/audio-completion")]
|
||||
public async Task<AudioCompletionViewModel> AudioCompletion([FromBody] IncomingMessageModel input)
|
||||
public async Task<AudioCompletionViewModel> AudioCompletion([FromBody] AudioCompletionRequest input)
|
||||
{
|
||||
var fileInstruct = _services.GetRequiredService<IFileInstructService>();
|
||||
var state = _services.GetRequiredService<IConversationStateService>();
|
||||
|
|
@ -253,7 +249,7 @@ public class InstructModeController : ControllerBase
|
|||
|
||||
try
|
||||
{
|
||||
var audio = input.Files.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x.FileUrl) || !string.IsNullOrWhiteSpace(x.FileData));
|
||||
var audio = input.File;
|
||||
if (audio == null)
|
||||
{
|
||||
return new AudioCompletionViewModel { Message = "Error! Cannot find a valid audio file!" };
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
namespace BotSharp.OpenAPI.ViewModels.Conversations;
|
||||
|
||||
public class InputMessageFiles
|
||||
{
|
||||
public List<MessageState> States { get; set; } = new();
|
||||
public List<BotSharpFile> Files { get; set; } = new();
|
||||
}
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace BotSharp.Abstraction.Instructs.Models;
|
||||
|
||||
public class InstructBaseRequest
|
||||
{
|
||||
[JsonPropertyName("provider")]
|
||||
public virtual string? Provider { get; set; } = null;
|
||||
|
||||
[JsonPropertyName("model")]
|
||||
public virtual string? Model { get; set; } = null;
|
||||
|
||||
[JsonPropertyName("model_id")]
|
||||
public virtual string? ModelId { get; set; } = null;
|
||||
|
||||
[JsonPropertyName("states")]
|
||||
public List<MessageState> States { get; set; } = new();
|
||||
}
|
||||
|
||||
public class MultiModalRequest : InstructBaseRequest
|
||||
{
|
||||
[JsonPropertyName("text")]
|
||||
public string Text { get; set; } = string.Empty;
|
||||
|
||||
[JsonPropertyName("files")]
|
||||
public List<BotSharpFile> Files { get; set; } = new();
|
||||
}
|
||||
|
||||
public class ImageGenerationRequest : InstructBaseRequest
|
||||
{
|
||||
[JsonPropertyName("text")]
|
||||
public string Text { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public class ImageVariationRequest : InstructBaseRequest
|
||||
{
|
||||
[JsonPropertyName("file")]
|
||||
public BotSharpFile File { get; set; }
|
||||
}
|
||||
|
||||
public class ImageEditRequest : InstructBaseRequest
|
||||
{
|
||||
[JsonPropertyName("text")]
|
||||
public string Text { get; set; } = string.Empty;
|
||||
|
||||
[JsonPropertyName("file")]
|
||||
public BotSharpFile File { get; set; }
|
||||
}
|
||||
|
||||
public class ImageMaskEditRequest : InstructBaseRequest
|
||||
{
|
||||
[JsonPropertyName("text")]
|
||||
public string Text { get; set; } = string.Empty;
|
||||
|
||||
[JsonPropertyName("file")]
|
||||
public BotSharpFile File { get; set; }
|
||||
|
||||
[JsonPropertyName("mask")]
|
||||
public BotSharpFile Mask { get; set; }
|
||||
}
|
||||
|
||||
public class AudioCompletionRequest : InstructBaseRequest
|
||||
{
|
||||
[JsonPropertyName("file")]
|
||||
public BotSharpFile File { get; set; }
|
||||
}
|
||||
Loading…
Reference in a new issue