Skip to content

Commit 50a94f3

Browse files
Merge branch 'master' into lida_dev
2 parents 63659d5 + e1aeb79 commit 50a94f3

File tree

35 files changed

+897
-51
lines changed

35 files changed

+897
-51
lines changed

src/Infrastructure/BotSharp.Abstraction/Files/Utilities/FileUtility.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,20 @@ public static string GetFileContentType(string fileName)
5858

5959
return contentType;
6060
}
61+
62+
public static List<string> GetMimeFileTypes(IEnumerable<string> fileTypes)
63+
{
64+
var provider = new FileExtensionContentTypeProvider();
65+
var mimeTypes = provider.Mappings.Where(x => fileTypes.Any(type => x.Value.Contains(type))).Select(x => x.Key).ToList();
66+
67+
return mimeTypes;
68+
}
69+
70+
public static List<string> GetContentFileTypes(IEnumerable<string> mimeTypes)
71+
{
72+
var provider = new FileExtensionContentTypeProvider();
73+
var mappings = provider.Mappings.Where(x => mimeTypes.Any(type => x.Key.Contains(type))).Select(x => x.Value).ToList();
74+
75+
return mappings;
76+
}
6177
}

src/Infrastructure/BotSharp.Abstraction/Infrastructures/ICacheService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ public interface ICacheService
55
Task<T?> GetAsync<T>(string key);
66
Task<object> GetAsync(string key, Type type);
77
Task SetAsync<T>(string key, T value, TimeSpan? expiry);
8+
Task RemoveAsync(string key);
89
}

src/Infrastructure/BotSharp.Abstraction/Infrastructures/SharpCacheAttribute.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ public override void OnEntry(MethodContext context)
3131
var value = cache.GetAsync(key, context.TaskReturnType).Result;
3232
if (value != null)
3333
{
34-
context.ReplaceReturnValue(this, value);
34+
// check if the cache is out of date
35+
var isOutOfDate = IsOutOfDate(context, value).Result;
36+
37+
if (!isOutOfDate)
38+
{
39+
context.ReplaceReturnValue(this, value);
40+
}
3541
}
3642
}
3743

@@ -58,6 +64,11 @@ public override void OnSuccess(MethodContext context)
5864
}
5965
}
6066

67+
public virtual Task<bool> IsOutOfDate(MethodContext context, object value)
68+
{
69+
return Task.FromResult(false);
70+
}
71+
6172
private string GetCacheKey(SharpCacheSettings settings, MethodContext context)
6273
{
6374
var key = settings.Prefix + "-" + context.Method.Name;

src/Infrastructure/BotSharp.Abstraction/VectorStorage/IVectorDb.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public interface IVectorDb
1212
Task<IEnumerable<VectorCollectionData>> GetCollectionData(string collectionName, IEnumerable<Guid> ids, bool withPayload = false, bool withVector = false);
1313
Task<bool> CreateCollection(string collectionName, int dimension);
1414
Task<bool> DeleteCollection(string collectionName);
15-
Task<bool> Upsert(string collectionName, Guid id, float[] vector, string text, Dictionary<string, string>? payload = null);
15+
Task<bool> Upsert(string collectionName, Guid id, float[] vector, string text, Dictionary<string, object>? payload = null);
1616
Task<IEnumerable<VectorCollectionData>> Search(string collectionName, float[] vector, IEnumerable<string>? fields, int limit = 5, float confidence = 0.5f, bool withVector = false);
1717
Task<bool> DeleteCollectionData(string collectionName, List<Guid> ids);
1818
Task<bool> DeleteCollectionAllData(string collectionName);

src/Infrastructure/BotSharp.Abstraction/VectorStorage/Models/VectorCollectionData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ namespace BotSharp.Abstraction.VectorStorage.Models;
33
public class VectorCollectionData
44
{
55
public string Id { get; set; }
6-
public Dictionary<string, string> Data { get; set; } = new();
6+
public Dictionary<string, object> Data { get; set; } = new();
77
public double? Score { get; set; }
88

99
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]

src/Infrastructure/BotSharp.Abstraction/VectorStorage/Models/VectorCreateModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ public class VectorCreateModel
66
{
77
public string Text { get; set; }
88
public string DataSource { get; set; } = VectorDataSource.Api;
9-
public Dictionary<string, string>? Payload { get; set; }
9+
public Dictionary<string, object>? Payload { get; set; }
1010
}

src/Infrastructure/BotSharp.Core/Infrastructures/MemoryCacheService.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,9 @@ public async Task SetAsync<T>(string key, T value, TimeSpan? expiry)
3232
AbsoluteExpirationRelativeToNow = expiry
3333
});
3434
}
35+
36+
public async Task RemoveAsync(string key)
37+
{
38+
_cache.Remove(key);
39+
}
3540
}

src/Infrastructure/BotSharp.Core/Infrastructures/RedisCacheService.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,20 @@ public async Task SetAsync<T>(string key, T value, TimeSpan? expiry)
7676
var db = redis.GetDatabase();
7777
await db.StringSetAsync(key, JsonConvert.SerializeObject(value), expiry);
7878
}
79+
80+
public async Task RemoveAsync(string key)
81+
{
82+
if (string.IsNullOrEmpty(_settings.Redis))
83+
{
84+
return;
85+
}
86+
87+
if (redis == null)
88+
{
89+
redis = ConnectionMultiplexer.Connect(_settings.Redis);
90+
}
91+
92+
var db = redis.GetDatabase();
93+
await db.KeyDeleteAsync(key);
94+
}
7995
}

src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,13 @@ private string GenerateJwtToken(User user)
291291

292292
private async Task SaveUserTokenExpiresCache(string userId, DateTime expires, int expireInMinutes)
293293
{
294-
var _cacheService = _services.GetRequiredService<ICacheService>();
295-
await _cacheService.SetAsync<DateTime>(GetUserTokenExpiresCacheKey(userId), expires, TimeSpan.FromMinutes(expireInMinutes));
294+
var config = _services.GetService<IConfiguration>();
295+
var enableSingleLogin = bool.Parse(config["Jwt:EnableSingleLogin"] ?? "false");
296+
if (enableSingleLogin)
297+
{
298+
var _cacheService = _services.GetRequiredService<ICacheService>();
299+
await _cacheService.SetAsync(GetUserTokenExpiresCacheKey(userId), expires, TimeSpan.FromMinutes(expireInMinutes));
300+
}
296301
}
297302

298303
private string GetUserTokenExpiresCacheKey(string userId)

src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/VectorKnowledgeCreateRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ public class VectorKnowledgeCreateRequest
1111
public string DataSource { get; set; } = VectorDataSource.Api;
1212

1313
[JsonPropertyName("payload")]
14-
public Dictionary<string, string>? Payload { get; set; }
14+
public Dictionary<string, object>? Payload { get; set; }
1515
}

0 commit comments

Comments
 (0)