完善提示词预设的接口,完善转发接口

This commit is contained in:
2024-11-13 14:00:39 +08:00
parent 26d190afa1
commit 3b0c316928
27 changed files with 1487 additions and 99 deletions
+36 -32
View File
@@ -1,5 +1,6 @@
using LMS.Common.Enum;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
@@ -18,44 +19,47 @@ public class Options
public OptionTypeEnum Type { get; set; } = OptionTypeEnum.String;
// 写一个字段,映射Value,判断是不是json字符串,是的话就解析成对象
[NotMapped]
public object? ValueObject
// 写一个字段,映射Value,判断是不是json字符串,是的话就解析成对象
public T? GetValueObject<T>()
{
get
if (string.IsNullOrEmpty(Value))
{
if (string.IsNullOrEmpty(Value))
{
return Value;
}
if (Type == OptionTypeEnum.JSON)
{
return JsonConvert.DeserializeObject(Value ?? "{}");
}
if (Type == OptionTypeEnum.Number)
{
return Convert.ToDouble(Value);
}
return Value;
return default;
}
set
{
if (value == null)
{
Value = string.Empty;
return;
}
if (Type == OptionTypeEnum.JSON)
if (Type == OptionTypeEnum.JSON)
{
return JsonConvert.DeserializeObject<T>(Value ?? "{}");
}
if (Type == OptionTypeEnum.Number)
{
if (double.TryParse(Value, out double result))
{
Value = JsonConvert.SerializeObject(value);
}
else
{
Value = value.ToString();
return (T)Convert.ChangeType(result, typeof(T));
}
return default;
}
return (T)Convert.ChangeType(Value, typeof(T));
}
// 写一个方法,设置Value的值
public void SetValueObject<T>(T value)
{
if (value == null)
{
Value = string.Empty;
return;
}
if (Type == OptionTypeEnum.JSON)
{
Value = JsonConvert.SerializeObject(value);
}
else
{
Value = value.ToString();
}
}
}
+3 -3
View File
@@ -1,4 +1,4 @@
namespace LMS.Repository.Models.DB
namespace LMS.Repository.DB
{
public class Prompt
{
@@ -45,7 +45,7 @@
/// <summary>
/// 创建者
/// </summary>
public string CreateUserId { get; set; }
public long CreateUserId { get; set; }
/// <summary>
/// 创建时间
@@ -55,7 +55,7 @@
/// <summary>
/// 更新者
/// </summary>
public string UpdateUserId { get; set; }
public long UpdateUserId { get; set; }
/// <summary>
/// 更新时间
+6 -32
View File
@@ -1,35 +1,12 @@
namespace LMS.Repository.Models.DB
using LMS.Repository.DTO.PromptTypeDto;
namespace LMS.Repository.Models.DB
{
/// <summary>
/// 提示词类型的库
/// </summary>
public class PromptType
public class PromptType : PromptTypeBasic
{
/// <summary>
/// ID
/// </summary>
public string Id { get; set; }
/// <summary>
/// 提示词类型编码
/// </summary>
public string Code { get; set; }
/// <summary>
/// 提示词类型名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 提示词类型描述
/// </summary>
public string? Remark { get; set; }
/// <summary>
/// 提示词类型状态
/// </summary>
public string Status { get; set; }
/// <summary>
/// 是否删除
/// </summary>
@@ -38,7 +15,7 @@
/// <summary>
/// 创建用户ID
/// </summary>
public string CreateUserId { get; set; }
public long CreateUserId { get; set; }
/// <summary>
/// 创建时间
@@ -48,14 +25,11 @@
/// <summary>
/// 更新者ID
/// </summary>
public string UpdateUserId { get; set; }
public long UpdateUserId { get; set; }
/// <summary>
/// 更新时间
/// </summary>
public DateTime UpdateTime { get; set; }
}
}
+1 -2
View File
@@ -1,5 +1,4 @@
using LMS.Tools.Extensions;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity;
namespace LMS.Repository.Models.DB
{
+15
View File
@@ -0,0 +1,15 @@
using LMS.Repository.DB;
using LMS.Repository.DTO.PromptTypeDto;
using LMS.Repository.DTO.UserDto;
namespace LMS.Repository.DTO.PromptDto;
public class PromptDto : Prompt
{
public UserBaseDto CreatedUser { get; set; }
public UserBaseDto UpdatedUser { get; set; }
public PromptTypeBasic? PromptType { get; set; }
}
@@ -0,0 +1,10 @@
namespace LMS.Repository.DTO.PromptDto;
public class PromptNameDto
{
public string Id { get; set; }
public string Name { get; set; }
public string PromptTypeId { get; set; }
}
@@ -0,0 +1,8 @@
namespace LMS.Repository.DTO.PromptTypeDto;
public class PrompTypeNameModel
{
public string Name { get; set; }
public string Id { get; set; }
}
@@ -0,0 +1,29 @@
namespace LMS.Repository.DTO.PromptTypeDto;
public class PromptTypeBasic
{
/// <summary>
/// ID
/// </summary>
public string Id { get; set; }
/// <summary>
/// 提示词类型编码
/// </summary>
public string Code { get; set; }
/// <summary>
/// 提示词类型名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 提示词类型描述
/// </summary>
public string? Remark { get; set; }
/// <summary>
/// 提示词类型状态
/// </summary>
public string Status { get; set; }
}
@@ -0,0 +1,12 @@
using LMS.Repository.DTO.UserDto;
using LMS.Repository.Models.DB;
namespace LMS.Repository.DTO.PromptTypeDto
{
public class PromptTypeDto : PromptType
{
public UserBaseDto? UpdatedUser { get; set; }
public UserBaseDto? CreatedUser { get; set; }
}
}
+48
View File
@@ -0,0 +1,48 @@
using System.ComponentModel.DataAnnotations;
namespace LMS.Repository.Forward;
public class ForwardModel
{
/// <summary>
/// 提示词类型ID
/// </summary>
[Required]
public string PromptTypeId { get; set; }
/// <summary>
/// 提示词ID
/// </summary>
[Required]
public string PromptId { get; set; }
/// <summary>
/// GPT 请求网址
/// </summary>
[Required]
public string GptUrl { get; set; }
/// <summary>
/// 调用的模型
/// </summary>
[Required]
public string Model { get; set; }
/// <summary>
/// 机器码
/// </summary>
[Required]
public string MachineId { get; set; }
/// <summary>
/// API Key
/// </summary>
[Required]
public string ApiKey { get; set; }
/// <summary>
/// 处理之前的文案,基础文案
/// </summary>
[Required]
public string Word { get; set; } = string.Empty;
}
-4
View File
@@ -6,10 +6,6 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Folder Include="Prompt\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="8.0.8" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
@@ -0,0 +1,45 @@
using System.ComponentModel.DataAnnotations;
namespace LMS.Repository.PromptModel;
public class ModifyPromptModel
{
/// <summary>
/// 名称
/// </summary>
[Required]
public string Name { get; set; }
/// <summary>
/// 提示词类型
/// </summary>
[Required]
public string PromptTypeId { get; set; }
/// <summary>
/// 提示词预设字符串
/// </summary>
[Required]
public string PromptString { get; set; }
/// <summary>
/// 描述
/// </summary>
public string? Description { get; set; }
/// <summary>
/// 备注
/// </summary>
public string? Remark { get; set; }
/// <summary>
/// 版本
/// </summary>
public int Version { get; set; }
[Required]
/// <summary>
/// 状态
/// </summary>
public string Status { get; set; }
}
@@ -0,0 +1,29 @@
using System.ComponentModel.DataAnnotations;
namespace LMS.Repository.PromptModel;
public class ModifyPromptTypeModal
{
/// <summary>
/// 名称
/// </summary>
[Required]
public string Name { get; set; }
/// <summary>
/// 提示词类型编码
/// </summary>
[Required]
public string Code { get; set; }
/// <summary>
/// 状态
/// </summary>
[Required]
public string Status { get; set; }
/// <summary>
/// 备注
/// </summary>
public string? Remark { get; set; } = string.Empty;
}