Skip to content

Commit

Permalink
解决查询详情未传递模型名称
Browse files Browse the repository at this point in the history
  • Loading branch information
239573049 committed Aug 15, 2024
1 parent ab9f918 commit 009997d
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ public async Task RemoveWiki(RemoveWikiCommand command)

await wikiRepository.RemoveDetailsAsync(ids);

var wiki = await wikiRepository.FindAsync(command.Id);

foreach (var id in ids)
try
{
var memoryServerless = wikiMemoryService.CreateMemoryServerless(string.Empty,string.Empty);
var memoryServerless = wikiMemoryService.CreateMemoryServerless(wiki.EmbeddingModel, wiki.Model);
await memoryServerless.DeleteDocumentAsync(id.ToString(), "wiki");
}
catch (Exception e)
Expand Down Expand Up @@ -102,7 +104,7 @@ public async Task RemoveWikiDetailsCommand(RemoveWikiDetailsCommand command)

try
{
var memoryServerless = wikiMemoryService.CreateMemoryServerless(string.Empty,string.Empty);
var memoryServerless = wikiMemoryService.CreateMemoryServerless(string.Empty, string.Empty);
await memoryServerless.DeleteDocumentAsync(command.Id.ToString(), "wiki");
}
catch (Exception e)
Expand All @@ -114,7 +116,8 @@ public async Task RemoveWikiDetailsCommand(RemoveWikiDetailsCommand command)
[EventHandler]
public async Task RemoveWikiDetailVectorQuantityAsync(RemoveWikiDetailVectorQuantityCommand command)
{
var memoryServerless = wikiMemoryService.CreateMemoryServerless(string.Empty,string.Empty);

var memoryServerless = wikiMemoryService.CreateMemoryServerless(string.Empty, string.Empty);
await memoryServerless.DeleteDocumentAsync(command.DocumentId, "wiki");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ public async Task GetWikiDetails(WikiDetailsQuery query)
[EventHandler]
public async Task WikiDetailVectorQuantityAsync(WikiDetailVectorQuantityQuery query)
{
var memoryServerless = wikiMemoryService.CreateMemoryServerless(string.Empty,string.Empty);
var wiki = await wikiRepository.FindAsync(x => long.Parse(query.WikiDetailId) == x.Id);

var memoryServerless = wikiMemoryService.CreateMemoryServerless(wiki.EmbeddingModel, wiki.Model);
var memoryDbs = memoryServerless.Orchestrator.GetMemoryDbs();

var result = new PaginatedListBase<WikiDetailVectorQuantityDto>();
Expand Down Expand Up @@ -92,7 +94,10 @@ public async Task WikiDetailVectorQuantityAsync(WikiDetailVectorQuantityQuery qu
public async Task SearchVectorQuantityAsync(SearchVectorQuantityQuery query)
{
var stopwatch = Stopwatch.StartNew();
var memoryServerless = wikiMemoryService.CreateMemoryServerless(string.Empty,string.Empty);

var wiki = await wikiRepository.FindAsync(query.WikiId);

var memoryServerless = wikiMemoryService.CreateMemoryServerless(wiki.EmbeddingModel, wiki.Model);
var searchResult = await memoryServerless.SearchAsync(query.Search, "wiki",
new MemoryFilter().ByTag("wikiId", query.WikiId.ToString()), minRelevance: query.MinRelevance, limit: 5);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public async Task InsertAsync(FastWikiFunctionCall functionCall)
{
await Context.FunctionCalls.AddAsync(functionCall);

await UnitOfWork.SaveChangesAsync();
await Context.SaveChangesAsync();
}

private IQueryable<FastWikiFunctionCall> CreateQuery(Guid? userId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ public async Task<long> GetCountAsync(string? keyword)

public async Task<bool> DeleteAsync(Guid id)
{
// 管理员不能删除
// 管理员不能删除
return await Context.Users.Where(x => x.Id == id && x.Role != RoleType.Admin).ExecuteDeleteAsync() > 1;
}

public async Task<bool> DisableAsync(Guid id, bool disable)
{
// 管理员不能禁用
// 管理员不能禁用
return await Context.Users.Where(x => x.Id == id && x.Role != RoleType.Admin)
.ExecuteUpdateAsync(item => item.SetProperty(x => x.IsDisable, disable)) > 0;
}
Expand All @@ -44,6 +44,13 @@ public async Task<bool> IsExistAccountAsync(string account)
return await Context.Users.AnyAsync(x => x.Account == account);
}

public async Task InsertAsync(User user)
{
await Context.Users.AddAsync(user);

await Context.SaveChangesAsync();
}

private IQueryable<User> GetQuery(string? keyword)
{
var query = Context.Users.AsQueryable();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,49 +1,56 @@
namespace FastWiki.Service.Domain.Users.Repositories;

/// <summary>
/// 用户仓储
/// 用户仓储
/// </summary>
public interface IUserRepository : IRepository<User, Guid>
{
/// <summary>
/// 获取用户列表
/// 获取用户列表
/// </summary>
Task<List<User>> GetListAsync(string? keyword, int page, int pageSize);

/// <summary>
/// 获取用户数量
/// 获取用户数量
/// </summary>
/// <param name="keyword"></param>
/// <returns></returns>
Task<long> GetCountAsync(string? keyword);

/// <summary>
/// 删除用户
/// 删除用户
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
Task<bool> DeleteAsync(Guid id);

/// <summary>
/// 禁用用户/启用用户
/// 禁用用户/启用用户
/// </summary>
/// <param name="id"></param>
/// <param name="disable">是否禁用</param>
/// <param name="disable">是否禁用</param>
/// <returns></returns>
Task<bool> DisableAsync(Guid id, bool disable);

/// <summary>
/// 修改角色
/// 修改角色
/// </summary>
/// <param name="id"></param>
/// <param name="role"></param>
/// <returns></returns>
Task UpdateRoleAsync(Guid id, RoleType role);

/// <summary>
/// 验证账户是否存在
/// 验证账户是否存在
/// </summary>
/// <param name="account"></param>
/// <returns></returns>
Task<bool> IsExistAccountAsync(string account);

/// <summary>
/// 添加
/// </summary>
/// <param name="user"></param>
/// <returns></returns>
Task InsertAsync(User user);
}
2 changes: 1 addition & 1 deletion src/Service/FastWiki.Service/Service/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public async Task CreateAsync(CreateUserInput input)
"https://blog-simple.oss-cn-shenzhen.aliyuncs.com/Avatar.jpg", input.Email, input.Phone,
false);

await userRepository.AddAsync(user);
await userRepository.InsertAsync(user);
}

[Authorize]
Expand Down

0 comments on commit 009997d

Please sign in to comment.