From d48dd07eebaa3699892018070be553fccff0d4e4 Mon Sep 17 00:00:00 2001 From: YouWeiDH Date: Mon, 20 Jan 2025 19:44:33 +0800 Subject: [PATCH 01/10] hdong: add search user logic. --- .../Repositories/IBotSharpRepository.cs | 1 + .../Users/IUserService.cs | 1 + .../FileRepository/FileRepository.User.cs | 57 +++++++++++++++ .../Users/Services/UserService.cs | 12 ++++ .../Repository/MongoRepository.User.cs | 69 +++++++++++++++++++ 5 files changed, 140 insertions(+) diff --git a/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs b/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs index d0174467..a752e07c 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs @@ -48,6 +48,7 @@ public interface IBotSharpRepository : IHaveServiceProvider void UpdateUserIsDisable(string userId, bool isDisable) => throw new NotImplementedException(); void UpdateUsersIsDisable(List userIds, bool isDisable) => throw new NotImplementedException(); PagedItems GetUsers(UserFilter filter) => throw new NotImplementedException(); + List SearchLoginUsers(User filter, string source = UserSource.Internal) =>throw new NotImplementedException(); User? GetUserDetails(string userId, bool includeAgent = false) => throw new NotImplementedException(); bool UpdateUser(User user, bool updateUserAgents = false) => throw new NotImplementedException(); diff --git a/src/Infrastructure/BotSharp.Abstraction/Users/IUserService.cs b/src/Infrastructure/BotSharp.Abstraction/Users/IUserService.cs index f92d7225..a9dc0333 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Users/IUserService.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Users/IUserService.cs @@ -8,6 +8,7 @@ public interface IUserService { Task GetUser(string id); Task> GetUsers(UserFilter filter); + Task> SearchLoginUsers(User filter); Task GetUserDetails(string userId, bool includeAgent = false); Task IsAdminUser(string userId); Task GetUserAuthorizations(IEnumerable? agentIds = null); diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs index 9d5b42be..8dfd198d 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs @@ -128,6 +128,63 @@ public partial class FileRepository }; } + public List SearchLoginUsers(User filter, string source = UserSource.Internal) + { + List searchResult = new List(); + + // search by filters + if (!string.IsNullOrWhiteSpace(filter.Id)) + { + var curUser = Users.FirstOrDefault(x => x.Source == source && x.Id == filter.Id.ToLower()); + User user = curUser != null ? curUser : null; + if (user != null) + { + searchResult.Add(user); + } + } + else if (!string.IsNullOrWhiteSpace(filter.Phone) && !string.IsNullOrWhiteSpace(filter.RegionCode)) + { + string[] regionCodeData = filter.RegionCode.Split('|'); + if (regionCodeData.Length == 2) + { + string phoneNoCallingCode = filter.Phone; + string phoneWithCallingCode = filter.Phone; + if (!filter.Phone.StartsWith('+')) + { + phoneNoCallingCode = filter.Phone; + phoneWithCallingCode = $"{regionCodeData[1]}{filter.Phone}"; + } + else + { + phoneNoCallingCode = filter.Phone.Replace(regionCodeData[1], ""); + } + searchResult = Users.AsQueryable() + .Where(x => x.Source == source && (x.Phone == phoneNoCallingCode || x.Phone == phoneWithCallingCode) && x.RegionCode == regionCodeData[0]) + .ToList(); + } + } + else if (!string.IsNullOrWhiteSpace(filter.Email)) + { + var curUser = Users.AsQueryable().FirstOrDefault(x => x.Source == source && x.Email == filter.Email.ToString()); + User user = curUser != null ? curUser : null; + if (user != null) + { + searchResult.Add(user); + } + } + else if (!string.IsNullOrWhiteSpace(filter.UserName)) + { + var curUser = Users.AsQueryable().FirstOrDefault(x => x.Source == source && x.UserName == filter.UserName); + User user = curUser != null ? curUser : null; + if (user != null) + { + searchResult.Add(user); + } + } + + return searchResult; + } + public User? GetUserDetails(string userId, bool includeAgent = false) { if (string.IsNullOrWhiteSpace(userId)) return null; diff --git a/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs b/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs index afb897e7..0af66b30 100644 --- a/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs +++ b/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs @@ -570,6 +570,18 @@ public class UserService : IUserService return false; } + public async Task> SearchLoginUsers(User filter) + { + if (filter == null) + { + return new List(); + } + + var db = _services.GetRequiredService(); + + return db.SearchLoginUsers(filter); + } + public async Task VerifyPhoneExisting(string phone, string regionCode) { if (string.IsNullOrWhiteSpace(phone)) diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.User.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.User.cs index 57ea76b9..9ca34c97 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.User.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.User.cs @@ -233,6 +233,75 @@ public partial class MongoRepository }; } + public List SearchLoginUsers(User filter, string source = UserSource.Internal) + { + List searchResult = new List(); + + // search by filters + if (!string.IsNullOrWhiteSpace(filter.Id)) + { + var curUser = _dc.Users.AsQueryable().FirstOrDefault(x => x.Source == source && x.Id == filter.Id.ToLower()); + User user = curUser != null ? curUser.ToUser() : null; + if (user != null) + { + searchResult.Add(user); + } + } + else if (!string.IsNullOrWhiteSpace(filter.Phone) && !string.IsNullOrWhiteSpace(filter.RegionCode)) + { + string[] regionCodeData = filter.RegionCode.Split('|'); + if (regionCodeData.Length == 2) + { + string phoneNoCallingCode = filter.Phone; + string phoneWithCallingCode = filter.Phone; + if (!filter.Phone.StartsWith('+')) + { + phoneNoCallingCode = filter.Phone; + phoneWithCallingCode = $"{regionCodeData[1]}{filter.Phone}"; + } + else + { + phoneNoCallingCode = filter.Phone.Replace(regionCodeData[1], ""); + } + var phoneUsers = _dc.Users.AsQueryable() + .Where(x => x.Source == source && (x.Phone == phoneNoCallingCode || x.Phone == phoneWithCallingCode) && x.RegionCode == regionCodeData[0]) + .ToList(); + + if (phoneUsers != null && phoneUsers.Count > 0) + { + foreach (var user in phoneUsers) + { + if (user != null) + { + searchResult.Add(user.ToUser()); + } + } + } + + } + } + else if (!string.IsNullOrWhiteSpace(filter.Email)) + { + var curUser = _dc.Users.AsQueryable().FirstOrDefault(x => x.Source == source && x.Email == filter.Email.ToString()); + User user = curUser != null ? curUser.ToUser() : null; + if (user != null) + { + searchResult.Add(user); + } + } + else if (!string.IsNullOrWhiteSpace(filter.UserName)) + { + var curUser = _dc.Users.AsQueryable().FirstOrDefault(x => x.Source == source && x.UserName == filter.UserName); + User user = curUser != null ? curUser.ToUser() : null; + if (user != null) + { + searchResult.Add(user); + } + } + + return searchResult; + } + public User? GetUserDetails(string userId, bool includeAgent = false) { if (string.IsNullOrWhiteSpace(userId)) return null; From 931c738f068cb04cb8052ba32a19a6fb0f17bba4 Mon Sep 17 00:00:00 2001 From: YouWeiDH Date: Tue, 21 Jan 2025 14:52:03 +0800 Subject: [PATCH 02/10] Fix userName can't login in email type. --- .../Repository/FileRepository/FileRepository.User.cs | 4 +++- .../Repository/MongoRepository.User.cs | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs index 8dfd198d..7e3592f3 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs @@ -172,7 +172,9 @@ public partial class FileRepository searchResult.Add(user); } } - else if (!string.IsNullOrWhiteSpace(filter.UserName)) + + + if (searchResult.Count == 0 && !string.IsNullOrWhiteSpace(filter.UserName)) { var curUser = Users.AsQueryable().FirstOrDefault(x => x.Source == source && x.UserName == filter.UserName); User user = curUser != null ? curUser : null; diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.User.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.User.cs index 9ca34c97..95fbf17b 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.User.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.User.cs @@ -289,7 +289,9 @@ public partial class MongoRepository searchResult.Add(user); } } - else if (!string.IsNullOrWhiteSpace(filter.UserName)) + + + if (searchResult.Count == 0 && !string.IsNullOrWhiteSpace(filter.UserName)) { var curUser = _dc.Users.AsQueryable().FirstOrDefault(x => x.Source == source && x.UserName == filter.UserName); User user = curUser != null ? curUser.ToUser() : null; From 2da891013f2239c1e9dcbf8f0a3569dbd829106d Mon Sep 17 00:00:00 2001 From: YouWeiDH Date: Tue, 21 Jan 2025 17:04:42 +0800 Subject: [PATCH 03/10] hdong: fix email case sensitivity issues. --- .../Repository/MongoRepository.User.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.User.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.User.cs index 95fbf17b..90c2a14d 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.User.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.User.cs @@ -282,7 +282,7 @@ public partial class MongoRepository } else if (!string.IsNullOrWhiteSpace(filter.Email)) { - var curUser = _dc.Users.AsQueryable().FirstOrDefault(x => x.Source == source && x.Email == filter.Email.ToString()); + var curUser = _dc.Users.AsQueryable().FirstOrDefault(x => x.Source == source && x.Email == filter.Email.ToLower()); User user = curUser != null ? curUser.ToUser() : null; if (user != null) { From 43eaf46d792b87894216b79fdc6b6f8d56c2b70e Mon Sep 17 00:00:00 2001 From: YouWeiDH Date: Tue, 21 Jan 2025 18:52:35 +0800 Subject: [PATCH 04/10] hdong: fix phone user logic. --- .../Repository/MongoRepository.User.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.User.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.User.cs index 90c2a14d..9f931d60 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.User.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.User.cs @@ -13,7 +13,7 @@ public partial class MongoRepository return user != null ? user.ToUser() : null; } - public User? GetUserByPhone(string phone, string type = UserType.Client, string regionCode = "CN") + public User? GetUserByPhone(string phone, string source = UserType.Internal, string regionCode = "CN") { string phoneSecond = string.Empty; // if phone number length is less than 4, return null @@ -33,7 +33,7 @@ public partial class MongoRepository var user = _dc.Users.AsQueryable().FirstOrDefault(x => (x.Phone == phone || x.Phone == phoneSecond) && (x.RegionCode == regionCode || string.IsNullOrWhiteSpace(x.RegionCode)) - && (x.Type == type)); + && (x.Source == source)); return user != null ? user.ToUser() : null; } From 9ea04ecd7879a0b5f04f270c345021443fabe655 Mon Sep 17 00:00:00 2001 From: YouWeiDH Date: Tue, 21 Jan 2025 20:25:23 +0800 Subject: [PATCH 05/10] hdong:fix default source. --- .../Repositories/IBotSharpRepository.cs | 2 +- .../Repository/FileRepository/FileRepository.User.cs | 6 +++--- .../BotSharp.Core/Users/Services/UserService.cs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs b/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs index a752e07c..789a60bc 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs @@ -27,7 +27,7 @@ public interface IBotSharpRepository : IHaveServiceProvider #region User User? GetUserByEmail(string email) => throw new NotImplementedException(); - User? GetUserByPhone(string phone, string type = UserType.Client, string regionCode = "CN") => throw new NotImplementedException(); + User? GetUserByPhone(string phone, string source = "internal", string regionCode = "CN") => throw new NotImplementedException(); User? GetAffiliateUserByPhone(string phone) => throw new NotImplementedException(); User? GetUserById(string id) => throw new NotImplementedException(); List GetUserByIds(List ids) => throw new NotImplementedException(); diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs index 7e3592f3..be9c7ce5 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs @@ -11,13 +11,13 @@ public partial class FileRepository return Users.FirstOrDefault(x => x.Email == email.ToLower()); } - public User? GetUserByPhone(string phone, string? type = UserType.Client, string regionCode = "CN") + public User? GetUserByPhone(string phone, string? source = UserType.Internal, string regionCode = "CN") { var query = Users.Where(x => x.Phone == phone); - if (!string.IsNullOrEmpty(type)) + if (!string.IsNullOrEmpty(source)) { - query = query.Where(x => x.Type == type); + query = query.Where(x => x.Type == source); } if (!string.IsNullOrEmpty(regionCode)) diff --git a/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs b/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs index 0af66b30..ff0a0d46 100644 --- a/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs +++ b/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs @@ -178,7 +178,7 @@ public class UserService : IUserService var base64 = Encoding.UTF8.GetString(Convert.FromBase64String(authorization)); var (id, password, regionCode) = base64.SplitAsTuple(":"); var db = _services.GetRequiredService(); - var record = db.GetUserByPhone(id, type: UserType.Internal); + var record = db.GetUserByPhone(id, source: UserType.Internal); var isCanLogin = record != null && !record.IsDisabled && record.Type == UserType.Internal && new List { From 618b9f5a81a570f50b332c87600802ff81762b29 Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Tue, 21 Jan 2025 18:36:37 +0000 Subject: [PATCH 06/10] Remove FocusAsync for PressKey --- .../Drivers/PlaywrightDriver/PlaywrightWebDriver.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.cs b/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.cs index 4be41140..4d13e26f 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.cs +++ b/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.cs @@ -75,9 +75,6 @@ public partial class PlaywrightWebDriver : IWebBrowser var page = _instance.GetPage(message.ContextId); if (page != null) { - // Click on the body to give focus to the page - await page.FocusAsync("input"); - await page.Keyboard.PressAsync(key); } } From 136f7eab67504168fffa87d999c7b244e5006a16 Mon Sep 17 00:00:00 2001 From: YouWeiDH Date: Wed, 22 Jan 2025 18:53:10 +0800 Subject: [PATCH 07/10] hdong: roll back type user and remain new logic. --- .../Repositories/IBotSharpRepository.cs | 3 +- .../FileRepository/FileRepository.User.cs | 19 ++++- .../Users/Services/UserService.cs | 83 ++++++++++--------- .../Repository/MongoRepository.User.cs | 26 +++++- 4 files changed, 91 insertions(+), 40 deletions(-) diff --git a/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs b/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs index 789a60bc..c631f2d1 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs @@ -27,7 +27,8 @@ public interface IBotSharpRepository : IHaveServiceProvider #region User User? GetUserByEmail(string email) => throw new NotImplementedException(); - User? GetUserByPhone(string phone, string source = "internal", string regionCode = "CN") => throw new NotImplementedException(); + User? GetUserByPhone(string phone, string type = UserType.Client, string regionCode = "CN") => throw new NotImplementedException(); + User? GetUserByPhoneV2(string phone, string source = UserType.Internal, string regionCode = "CN") => throw new NotImplementedException(); User? GetAffiliateUserByPhone(string phone) => throw new NotImplementedException(); User? GetUserById(string id) => throw new NotImplementedException(); List GetUserByIds(List ids) => throw new NotImplementedException(); diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs index be9c7ce5..373e36b4 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs @@ -11,7 +11,24 @@ public partial class FileRepository return Users.FirstOrDefault(x => x.Email == email.ToLower()); } - public User? GetUserByPhone(string phone, string? source = UserType.Internal, string regionCode = "CN") + public User? GetUserByPhone(string phone, string? type = UserType.Client, string regionCode = "CN") + { + var query = Users.Where(x => x.Phone == phone); + + if (!string.IsNullOrEmpty(type)) + { + query = query.Where(x => x.Type == type); + } + + if (!string.IsNullOrEmpty(regionCode)) + { + query = query.Where(x => x.RegionCode == regionCode); + } + + return query.FirstOrDefault(); + } + + public User? GetUserByPhoneV2(string phone, string? source = UserType.Internal, string regionCode = "CN") { var query = Users.Where(x => x.Phone == phone); diff --git a/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs b/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs index ff0a0d46..651d4c50 100644 --- a/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs +++ b/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs @@ -55,6 +55,11 @@ public class UserService : IUserService if (record == null && !string.IsNullOrWhiteSpace(user.Phone)) { + //if (user.Type != "internal") + //{ + // record = db.GetUserByPhoneV2(user.Phone, regionCode: (string.IsNullOrWhiteSpace(user.RegionCode) ? "CN" : user.RegionCode)); + //} + record = db.GetUserByPhone(user.Phone, regionCode: (string.IsNullOrWhiteSpace(user.RegionCode) ? "CN" : user.RegionCode)); } @@ -178,7 +183,7 @@ public class UserService : IUserService var base64 = Encoding.UTF8.GetString(Convert.FromBase64String(authorization)); var (id, password, regionCode) = base64.SplitAsTuple(":"); var db = _services.GetRequiredService(); - var record = db.GetUserByPhone(id, source: UserType.Internal); + var record = db.GetUserByPhone(id, type: UserType.Internal); var isCanLogin = record != null && !record.IsDisabled && record.Type == UserType.Internal && new List { @@ -477,11 +482,17 @@ public class UserService : IUserService var id = model.UserName; var db = _services.GetRequiredService(); var record = id.Contains("@") ? db.GetUserByEmail(id) : db.GetUserByUserName(id); + if (record == null) { record = db.GetUserByPhone(id, regionCode: (string.IsNullOrWhiteSpace(model.RegionCode) ? "CN" : model.RegionCode)); } + //if (record == null) + //{ + // record = db.GetUserByPhoneV2(id, regionCode: (string.IsNullOrWhiteSpace(model.RegionCode) ? "CN" : model.RegionCode)); + //} + if (record == null) { return default; @@ -621,21 +632,12 @@ public class UserService : IUserService public async Task ResetVerificationCode(User user) { var db = _services.GetRequiredService(); - User record = null; - if (!string.IsNullOrEmpty(user.Email) && !string.IsNullOrEmpty(user.Phone)) + if (!string.IsNullOrWhiteSpace(user.Email) && !string.IsNullOrWhiteSpace(user.Phone)) { return null; } - if (!string.IsNullOrEmpty(user.Phone)) - { - record = db.GetUserByPhone(user.Phone, regionCode: user.RegionCode); - } - - if (!string.IsNullOrEmpty(user.Email)) - { - record = db.GetUserByEmail(user.Email); - } + User? record = GetLoginUserByUniqueFilter(user, db); if (record == null) { @@ -650,6 +652,36 @@ public class UserService : IUserService return record; } + private static User? GetLoginUserByUniqueFilter(User user, IBotSharpRepository db) + { + User? record = null; + if (!string.IsNullOrWhiteSpace(user.Id)) + { + record = db.GetUserById(user.Id); + } + + if (record == null && !string.IsNullOrWhiteSpace(user.Phone)) + { + record = db.GetUserByPhone(user.Phone, regionCode: string.IsNullOrWhiteSpace(user.RegionCode) ? "CN" : user.RegionCode); + //if (record == null) + //{ + // record = db.GetUserByPhoneV2(user.Phone, regionCode: string.IsNullOrWhiteSpace(user.RegionCode) ? "CN" : user.RegionCode); + //} + } + + if (record == null && !string.IsNullOrWhiteSpace(user.Email)) + { + record = db.GetUserByEmail(user.Email); + } + + if (record == null && !string.IsNullOrWhiteSpace(user.UserName)) + { + record = db.GetUserByUserName(user.UserName); + } + + return record; + } + public async Task SendVerificationCodeLogin() { var db = _services.GetRequiredService(); @@ -689,17 +721,7 @@ public class UserService : IUserService } var db = _services.GetRequiredService(); - User? record = null; - - if (!string.IsNullOrEmpty(user.Email)) - { - record = db.GetUserByEmail(user.Email); - } - - if (!string.IsNullOrEmpty(user.Phone)) - { - record = db.GetUserByPhone(user.Phone, regionCode: (string.IsNullOrWhiteSpace(user.RegionCode) ? "CN" : user.RegionCode)); - } + User? record = GetLoginUserByUniqueFilter(user, db); if (record == null) { @@ -724,20 +746,7 @@ public class UserService : IUserService } var db = _services.GetRequiredService(); - User? record = null; - - if (!string.IsNullOrEmpty(user.Id)) - { - record = db.GetUserById(user.Id); - } - else if (!string.IsNullOrEmpty(user.Phone)) - { - record = db.GetUserByPhone(user.Phone, regionCode: (string.IsNullOrWhiteSpace(user.RegionCode) ? "CN" : user.RegionCode)); - } - else if (!string.IsNullOrEmpty(user.Email)) - { - record = db.GetUserByEmail(user.Email); - } + User? record = GetLoginUserByUniqueFilter(user, db); if (record == null) { diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.User.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.User.cs index 9f931d60..3b6dd05f 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.User.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.User.cs @@ -13,7 +13,31 @@ public partial class MongoRepository return user != null ? user.ToUser() : null; } - public User? GetUserByPhone(string phone, string source = UserType.Internal, string regionCode = "CN") + public User? GetUserByPhone(string phone, string type = UserType.Client, string regionCode = "CN") + { + string phoneSecond = string.Empty; + // if phone number length is less than 4, return null + if (string.IsNullOrWhiteSpace(phone) || phone?.Length < 4) + { + return null; + } + + if (regionCode == "CN") + { + phoneSecond = (phone ?? "").StartsWith("+86") ? (phone ?? "").Replace("+86", "") : ($"+86{phone ?? ""}"); + } + else + { + phoneSecond = (phone ?? "").Substring(regionCode == "US" ? 2 : 3); + } + + var user = _dc.Users.AsQueryable().FirstOrDefault(x => (x.Phone == phone || x.Phone == phoneSecond) + && (x.RegionCode == regionCode || string.IsNullOrWhiteSpace(x.RegionCode)) + && (x.Type == type)); + return user != null ? user.ToUser() : null; + } + + public User? GetUserByPhoneV2(string phone, string source = UserType.Internal, string regionCode = "CN") { string phoneSecond = string.Empty; // if phone number length is less than 4, return null From 6fb7c14685fc3e4c8e602812e061a915779e740d Mon Sep 17 00:00:00 2001 From: Kerry Jiang Date: Sat, 1 Feb 2025 13:11:28 -0800 Subject: [PATCH 08/10] centralized package version for some projects --- Directory.Packages.props | 55 +++++++++++++++++++ .../BotSharp.Abstraction.csproj | 29 +++++----- .../BotSharp.Core/BotSharp.Core.csproj | 15 ++--- .../BotSharp.OpenAPI/BotSharp.OpenAPI.csproj | 29 +++++----- .../BotSharp.Plugin.AnthropicAI.csproj | 3 +- .../BotSharp.Plugin.AudioHandler.csproj | 11 ++-- 6 files changed, 101 insertions(+), 41 deletions(-) create mode 100644 Directory.Packages.props diff --git a/Directory.Packages.props b/Directory.Packages.props new file mode 100644 index 00000000..0d0feb13 --- /dev/null +++ b/Directory.Packages.props @@ -0,0 +1,55 @@ + + + 8.0.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Infrastructure/BotSharp.Abstraction/BotSharp.Abstraction.csproj b/src/Infrastructure/BotSharp.Abstraction/BotSharp.Abstraction.csproj index 900bc4a7..531a171b 100644 --- a/src/Infrastructure/BotSharp.Abstraction/BotSharp.Abstraction.csproj +++ b/src/Infrastructure/BotSharp.Abstraction/BotSharp.Abstraction.csproj @@ -8,6 +8,7 @@ Icon.png $(GeneratePackageOnBuild) $(SolutionDir)packages + true @@ -24,20 +25,20 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj b/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj index 37eee3ac..ecc736f2 100644 --- a/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj +++ b/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj @@ -6,6 +6,7 @@ $(BotSharpVersion) $(GeneratePackageOnBuild) $(SolutionDir)packages + true @@ -188,13 +189,13 @@ - - - - - - - + + + + + + + diff --git a/src/Infrastructure/BotSharp.OpenAPI/BotSharp.OpenAPI.csproj b/src/Infrastructure/BotSharp.OpenAPI/BotSharp.OpenAPI.csproj index ef06b4d5..38ec30db 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/BotSharp.OpenAPI.csproj +++ b/src/Infrastructure/BotSharp.OpenAPI/BotSharp.OpenAPI.csproj @@ -8,6 +8,7 @@ $(BotSharpVersion) $(GeneratePackageOnBuild) $(SolutionDir)packages + true @@ -24,26 +25,26 @@ - - + + - - - - - - + + + + + + - - - - - - + + + + + + diff --git a/src/Plugins/BotSharp.Plugin.AnthropicAI/BotSharp.Plugin.AnthropicAI.csproj b/src/Plugins/BotSharp.Plugin.AnthropicAI/BotSharp.Plugin.AnthropicAI.csproj index 0dc416df..4360a7a9 100644 --- a/src/Plugins/BotSharp.Plugin.AnthropicAI/BotSharp.Plugin.AnthropicAI.csproj +++ b/src/Plugins/BotSharp.Plugin.AnthropicAI/BotSharp.Plugin.AnthropicAI.csproj @@ -8,10 +8,11 @@ $(GeneratePackageOnBuild) $(GenerateDocumentationFile) $(SolutionDir)packages + true - + diff --git a/src/Plugins/BotSharp.Plugin.AudioHandler/BotSharp.Plugin.AudioHandler.csproj b/src/Plugins/BotSharp.Plugin.AudioHandler/BotSharp.Plugin.AudioHandler.csproj index ace72c5c..e7459219 100644 --- a/src/Plugins/BotSharp.Plugin.AudioHandler/BotSharp.Plugin.AudioHandler.csproj +++ b/src/Plugins/BotSharp.Plugin.AudioHandler/BotSharp.Plugin.AudioHandler.csproj @@ -9,14 +9,15 @@ $(GeneratePackageOnBuild) $(GenerateDocumentationFile) $(SolutionDir)packages + true - - - - - + + + + + From 78a95914b13e8a16c1d17060ebde5831e71c90bc Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Wed, 5 Feb 2025 17:50:32 -0600 Subject: [PATCH 09/10] add max output token --- .../Agents/Constants/LlmConstant.cs | 6 ++++++ .../Agents/Models/AgentLlmConfig.cs | 10 ++++++++++ .../Statistics/Models/BotSharpStats.cs | 3 ++- .../ViewModels/Agents/AgentCreationModel.cs | 2 +- .../ViewModels/Agents/AgentUpdateModel.cs | 2 +- .../Providers/ChatCompletionProvider.cs | 6 ++++-- src/Plugins/BotSharp.Plugin.AnthropicAI/Using.cs | 1 + .../Providers/Chat/ChatCompletionProvider.cs | 5 ++++- src/Plugins/BotSharp.Plugin.AzureOpenAI/Using.cs | 1 + .../Providers/Chat/ChatCompletionProvider.cs | 4 +++- src/Plugins/BotSharp.Plugin.DeepSeekAI/Using.cs | 1 + .../Providers/Chat/GeminiChatCompletionProvider.cs | 13 ++++++++++++- src/Plugins/BotSharp.Plugin.GoogleAI/Using.cs | 1 + .../Models/AgentLlmConfigMongoElement.cs | 3 +++ .../Providers/Chat/ChatCompletionProvider.cs | 4 +++- .../Realtime/RealTimeCompletionProvider.cs | 4 +++- src/Plugins/BotSharp.Plugin.OpenAI/Using.cs | 1 + 17 files changed, 57 insertions(+), 10 deletions(-) create mode 100644 src/Infrastructure/BotSharp.Abstraction/Agents/Constants/LlmConstant.cs diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/Constants/LlmConstant.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/Constants/LlmConstant.cs new file mode 100644 index 00000000..3919ca57 --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/Constants/LlmConstant.cs @@ -0,0 +1,6 @@ +namespace BotSharp.Abstraction.Agents.Constants; + +public static class LlmConstant +{ + public const int DEFAULT_MAX_OUTPUT_TOKEN = 1024; +} diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentLlmConfig.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentLlmConfig.cs index 8025c2b8..f1df3a01 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentLlmConfig.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentLlmConfig.cs @@ -22,6 +22,16 @@ public class AgentLlmConfig [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? Model { get; set; } + /// + /// Max recursion depth + /// [JsonPropertyName("max_recursion_depth")] public int MaxRecursionDepth { get; set; } = 3; + + /// + /// Max output token + /// + [JsonPropertyName("max_output_tokens")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public int? MaxOutputTokens { get; set; } } diff --git a/src/Infrastructure/BotSharp.Abstraction/Statistics/Models/BotSharpStats.cs b/src/Infrastructure/BotSharp.Abstraction/Statistics/Models/BotSharpStats.cs index 33178d6a..c0163a7e 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Statistics/Models/BotSharpStats.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Statistics/Models/BotSharpStats.cs @@ -52,7 +52,7 @@ public class BotSharpStats public static (DateTime, DateTime) BuildTimeInterval(DateTime recordTime, StatsInterval interval) { DateTime startTime = recordTime; - DateTime endTime = DateTime.UtcNow; + DateTime endTime = startTime; switch (interval) { @@ -70,6 +70,7 @@ public class BotSharpStats break; } + endTime = endTime.AddSeconds(-1); startTime = DateTime.SpecifyKind(startTime, DateTimeKind.Utc); endTime = DateTime.SpecifyKind(endTime, DateTimeKind.Utc); return (startTime, endTime); diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentCreationModel.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentCreationModel.cs index bb26836c..8e4d915d 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentCreationModel.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentCreationModel.cs @@ -80,7 +80,7 @@ public class AgentCreationModel MaxMessageCount = MaxMessageCount, Profiles = Profiles, Labels = Labels, - LlmConfig = LlmConfig, + LlmConfig = LlmConfig ?? new(), KnowledgeBases = KnowledgeBases, Rules = Rules, RoutingRules = RoutingRules?.Select(x => RoutingRuleUpdateModel.ToDomainElement(x))?.ToList() ?? [], diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentUpdateModel.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentUpdateModel.cs index 611d633f..ac2749b5 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentUpdateModel.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentUpdateModel.cs @@ -105,7 +105,7 @@ public class AgentUpdateModel Utilities = Utilities ?? [], KnowledgeBases = KnowledgeBases ?? [], Rules = Rules ?? [], - LlmConfig = LlmConfig + LlmConfig = LlmConfig ?? new() }; return agent; diff --git a/src/Plugins/BotSharp.Plugin.AnthropicAI/Providers/ChatCompletionProvider.cs b/src/Plugins/BotSharp.Plugin.AnthropicAI/Providers/ChatCompletionProvider.cs index 8657b31b..b71306cf 100644 --- a/src/Plugins/BotSharp.Plugin.AnthropicAI/Providers/ChatCompletionProvider.cs +++ b/src/Plugins/BotSharp.Plugin.AnthropicAI/Providers/ChatCompletionProvider.cs @@ -170,12 +170,14 @@ public class ChatCompletionProvider : IChatCompletion var state = _services.GetRequiredService(); var temperature = decimal.Parse(state.GetState("temperature", "0.0")); - var maxToken = int.Parse(state.GetState("max_tokens", "512")); + var maxTokens = int.TryParse(state.GetState("max_tokens"), out var tokens) + ? tokens + : agent.LlmConfig?.MaxOutputTokens ?? LlmConstant.DEFAULT_MAX_OUTPUT_TOKEN; var parameters = new MessageParameters() { Messages = messages, - MaxTokens = maxToken, + MaxTokens = maxTokens, Model = settings.Name, Stream = false, Temperature = temperature, diff --git a/src/Plugins/BotSharp.Plugin.AnthropicAI/Using.cs b/src/Plugins/BotSharp.Plugin.AnthropicAI/Using.cs index d00446fc..b2e4484c 100644 --- a/src/Plugins/BotSharp.Plugin.AnthropicAI/Using.cs +++ b/src/Plugins/BotSharp.Plugin.AnthropicAI/Using.cs @@ -8,6 +8,7 @@ global using Anthropic.SDK; global using Anthropic.SDK.Constants; global using Anthropic.SDK.Messaging; global using BotSharp.Abstraction.Agents; +global using BotSharp.Abstraction.Agents.Constants; global using BotSharp.Abstraction.Agents.Enums; global using BotSharp.Abstraction.Agents.Models; global using BotSharp.Abstraction.Conversations.Models; diff --git a/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/Chat/ChatCompletionProvider.cs b/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/Chat/ChatCompletionProvider.cs index 9879e4fb..3fef7c0c 100644 --- a/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/Chat/ChatCompletionProvider.cs +++ b/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/Chat/ChatCompletionProvider.cs @@ -225,7 +225,10 @@ public class ChatCompletionProvider : IChatCompletion var messages = new List(); var temperature = float.Parse(state.GetState("temperature", "0.0")); - var maxTokens = int.Parse(state.GetState("max_tokens", "1024")); + var maxTokens = int.TryParse(state.GetState("max_tokens"), out var tokens) + ? tokens + : agent.LlmConfig?.MaxOutputTokens ?? LlmConstant.DEFAULT_MAX_OUTPUT_TOKEN; + var options = new ChatCompletionOptions() { Temperature = temperature, diff --git a/src/Plugins/BotSharp.Plugin.AzureOpenAI/Using.cs b/src/Plugins/BotSharp.Plugin.AzureOpenAI/Using.cs index 71f5272d..2cc3faf0 100644 --- a/src/Plugins/BotSharp.Plugin.AzureOpenAI/Using.cs +++ b/src/Plugins/BotSharp.Plugin.AzureOpenAI/Using.cs @@ -5,6 +5,7 @@ global using System.IO; global using System.Threading.Tasks; global using Microsoft.Extensions.DependencyInjection; global using Microsoft.Extensions.Logging; +global using BotSharp.Abstraction.Agents.Constants; global using BotSharp.Abstraction.Agents.Enums; global using BotSharp.Abstraction.Agents.Models; global using BotSharp.Abstraction.Conversations; diff --git a/src/Plugins/BotSharp.Plugin.DeepSeekAI/Providers/Chat/ChatCompletionProvider.cs b/src/Plugins/BotSharp.Plugin.DeepSeekAI/Providers/Chat/ChatCompletionProvider.cs index 474c7350..ef4d0c8a 100644 --- a/src/Plugins/BotSharp.Plugin.DeepSeekAI/Providers/Chat/ChatCompletionProvider.cs +++ b/src/Plugins/BotSharp.Plugin.DeepSeekAI/Providers/Chat/ChatCompletionProvider.cs @@ -201,7 +201,9 @@ public class ChatCompletionProvider : IChatCompletion var messages = new List(); var temperature = float.Parse(state.GetState("temperature", "0.0")); - var maxTokens = int.Parse(state.GetState("max_tokens", "1024")); + var maxTokens = int.TryParse(state.GetState("max_tokens"), out var tokens) + ? tokens + : agent.LlmConfig?.MaxOutputTokens ?? LlmConstant.DEFAULT_MAX_OUTPUT_TOKEN; var options = new ChatCompletionOptions() { Temperature = temperature, diff --git a/src/Plugins/BotSharp.Plugin.DeepSeekAI/Using.cs b/src/Plugins/BotSharp.Plugin.DeepSeekAI/Using.cs index 4fa278e6..751f1aec 100644 --- a/src/Plugins/BotSharp.Plugin.DeepSeekAI/Using.cs +++ b/src/Plugins/BotSharp.Plugin.DeepSeekAI/Using.cs @@ -10,6 +10,7 @@ global using BotSharp.Abstraction.Conversations.Models; global using BotSharp.Abstraction.Agents.Models; global using BotSharp.Abstraction.MLTasks; global using BotSharp.Abstraction.Agents; +global using BotSharp.Abstraction.Agents.Constants; global using BotSharp.Abstraction.Agents.Enums; global using BotSharp.Abstraction.Conversations; global using BotSharp.Abstraction.Loggers; diff --git a/src/Plugins/BotSharp.Plugin.GoogleAI/Providers/Chat/GeminiChatCompletionProvider.cs b/src/Plugins/BotSharp.Plugin.GoogleAI/Providers/Chat/GeminiChatCompletionProvider.cs index 5930a6b9..9567ae57 100644 --- a/src/Plugins/BotSharp.Plugin.GoogleAI/Providers/Chat/GeminiChatCompletionProvider.cs +++ b/src/Plugins/BotSharp.Plugin.GoogleAI/Providers/Chat/GeminiChatCompletionProvider.cs @@ -1,5 +1,6 @@ using BotSharp.Abstraction.Agents; using BotSharp.Abstraction.Agents.Enums; +using BotSharp.Abstraction.Conversations; using BotSharp.Abstraction.Loggers; using Google.Protobuf.WellKnownTypes; using Microsoft.Extensions.Logging; @@ -188,10 +189,20 @@ public class GeminiChatCompletionProvider : IChatCompletion } } + var state = _services.GetRequiredService(); + var temperature = float.Parse(state.GetState("temperature", "0.0")); + var maxTokens = int.TryParse(state.GetState("max_tokens"), out var tokens) + ? tokens + : agent.LlmConfig?.MaxOutputTokens ?? LlmConstant.DEFAULT_MAX_OUTPUT_TOKEN; var request = new GenerateContentRequest { Contents = contents, - Tools = tools + Tools = tools, + GenerationConfig = new() + { + Temperature = temperature, + MaxOutputTokens = maxTokens + } }; var prompt = GetPrompt(systemPrompts, funcPrompts, convPrompts); diff --git a/src/Plugins/BotSharp.Plugin.GoogleAI/Using.cs b/src/Plugins/BotSharp.Plugin.GoogleAI/Using.cs index 17152bf4..c7f6c176 100644 --- a/src/Plugins/BotSharp.Plugin.GoogleAI/Using.cs +++ b/src/Plugins/BotSharp.Plugin.GoogleAI/Using.cs @@ -5,6 +5,7 @@ global using System.Threading.Tasks; global using System.Linq; global using System.Text.Json; global using BotSharp.Abstraction.Conversations.Models; +global using BotSharp.Abstraction.Agents.Constants; global using BotSharp.Abstraction.Agents.Models; global using BotSharp.Abstraction.MLTasks; global using Microsoft.Extensions.Configuration; diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentLlmConfigMongoElement.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentLlmConfigMongoElement.cs index 5251b532..32989ad1 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentLlmConfigMongoElement.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentLlmConfigMongoElement.cs @@ -8,6 +8,7 @@ public class AgentLlmConfigMongoElement public string? Model { get; set; } public bool IsInherit { get; set; } public int MaxRecursionDepth { get; set; } + public int? MaxOutputTokens { get; set; } public static AgentLlmConfigMongoElement? ToMongoElement(AgentLlmConfig? config) { @@ -19,6 +20,7 @@ public class AgentLlmConfigMongoElement Model = config.Model, IsInherit = config.IsInherit, MaxRecursionDepth = config.MaxRecursionDepth, + MaxOutputTokens = config.MaxOutputTokens, }; } @@ -32,6 +34,7 @@ public class AgentLlmConfigMongoElement Model = config.Model, IsInherit = config.IsInherit, MaxRecursionDepth = config.MaxRecursionDepth, + MaxOutputTokens = config.MaxOutputTokens, }; } } diff --git a/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Chat/ChatCompletionProvider.cs b/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Chat/ChatCompletionProvider.cs index 4eae5532..15eb04c5 100644 --- a/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Chat/ChatCompletionProvider.cs +++ b/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Chat/ChatCompletionProvider.cs @@ -202,7 +202,9 @@ public class ChatCompletionProvider : IChatCompletion var messages = new List(); var temperature = float.Parse(state.GetState("temperature", "0.0")); - var maxTokens = int.Parse(state.GetState("max_tokens", "1024")); + var maxTokens = int.TryParse(state.GetState("max_tokens"), out var tokens) + ? tokens + : agent.LlmConfig?.MaxOutputTokens ?? LlmConstant.DEFAULT_MAX_OUTPUT_TOKEN; var options = new ChatCompletionOptions() { Temperature = temperature, diff --git a/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Realtime/RealTimeCompletionProvider.cs b/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Realtime/RealTimeCompletionProvider.cs index 47389499..eb678c5d 100644 --- a/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Realtime/RealTimeCompletionProvider.cs +++ b/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Realtime/RealTimeCompletionProvider.cs @@ -70,7 +70,9 @@ public class RealTimeCompletionProvider : IRealTimeCompletion var messages = new List(); var temperature = float.Parse(state.GetState("temperature", "0.0")); - var maxTokens = int.Parse(state.GetState("max_tokens", "1024")); + var maxTokens = int.TryParse(state.GetState("max_tokens"), out var tokens) + ? tokens + : agent.LlmConfig?.MaxOutputTokens ?? LlmConstant.DEFAULT_MAX_OUTPUT_TOKEN; var options = new ChatCompletionOptions() { ToolChoice = ChatToolChoice.CreateAutoChoice(), diff --git a/src/Plugins/BotSharp.Plugin.OpenAI/Using.cs b/src/Plugins/BotSharp.Plugin.OpenAI/Using.cs index fe9a02b4..ac1022a2 100644 --- a/src/Plugins/BotSharp.Plugin.OpenAI/Using.cs +++ b/src/Plugins/BotSharp.Plugin.OpenAI/Using.cs @@ -6,6 +6,7 @@ global using System.Threading.Tasks; global using Microsoft.Extensions.DependencyInjection; global using Microsoft.Extensions.Logging; global using BotSharp.Abstraction.Agents.Enums; +global using BotSharp.Abstraction.Agents.Constants; global using BotSharp.Abstraction.Agents.Models; global using BotSharp.Abstraction.Conversations; global using BotSharp.Abstraction.Conversations.Models; From 1c7cbbdcf57e3764cf9c7240bef65626033cc309 Mon Sep 17 00:00:00 2001 From: iceljc <46039045+iceljc@users.noreply.github.com> Date: Thu, 6 Feb 2025 13:15:36 -0600 Subject: [PATCH 10/10] Revert "Centralized package version for some projects" --- Directory.Packages.props | 55 ------------------- .../BotSharp.Abstraction.csproj | 29 +++++----- .../BotSharp.Core/BotSharp.Core.csproj | 15 +++-- .../BotSharp.OpenAPI/BotSharp.OpenAPI.csproj | 29 +++++----- .../BotSharp.Plugin.AnthropicAI.csproj | 3 +- .../BotSharp.Plugin.AudioHandler.csproj | 11 ++-- 6 files changed, 41 insertions(+), 101 deletions(-) delete mode 100644 Directory.Packages.props diff --git a/Directory.Packages.props b/Directory.Packages.props deleted file mode 100644 index 0d0feb13..00000000 --- a/Directory.Packages.props +++ /dev/null @@ -1,55 +0,0 @@ - - - 8.0.0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Infrastructure/BotSharp.Abstraction/BotSharp.Abstraction.csproj b/src/Infrastructure/BotSharp.Abstraction/BotSharp.Abstraction.csproj index 4475e1b4..0e69d7b6 100644 --- a/src/Infrastructure/BotSharp.Abstraction/BotSharp.Abstraction.csproj +++ b/src/Infrastructure/BotSharp.Abstraction/BotSharp.Abstraction.csproj @@ -8,7 +8,6 @@ Icon.png $(GeneratePackageOnBuild) $(SolutionDir)packages - true @@ -25,20 +24,20 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj b/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj index ecc736f2..37eee3ac 100644 --- a/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj +++ b/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj @@ -6,7 +6,6 @@ $(BotSharpVersion) $(GeneratePackageOnBuild) $(SolutionDir)packages - true @@ -189,13 +188,13 @@ - - - - - - - + + + + + + + diff --git a/src/Infrastructure/BotSharp.OpenAPI/BotSharp.OpenAPI.csproj b/src/Infrastructure/BotSharp.OpenAPI/BotSharp.OpenAPI.csproj index 38ec30db..ef06b4d5 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/BotSharp.OpenAPI.csproj +++ b/src/Infrastructure/BotSharp.OpenAPI/BotSharp.OpenAPI.csproj @@ -8,7 +8,6 @@ $(BotSharpVersion) $(GeneratePackageOnBuild) $(SolutionDir)packages - true @@ -25,26 +24,26 @@ - - + + - - - - - - + + + + + + - - - - - - + + + + + + diff --git a/src/Plugins/BotSharp.Plugin.AnthropicAI/BotSharp.Plugin.AnthropicAI.csproj b/src/Plugins/BotSharp.Plugin.AnthropicAI/BotSharp.Plugin.AnthropicAI.csproj index 4360a7a9..0dc416df 100644 --- a/src/Plugins/BotSharp.Plugin.AnthropicAI/BotSharp.Plugin.AnthropicAI.csproj +++ b/src/Plugins/BotSharp.Plugin.AnthropicAI/BotSharp.Plugin.AnthropicAI.csproj @@ -8,11 +8,10 @@ $(GeneratePackageOnBuild) $(GenerateDocumentationFile) $(SolutionDir)packages - true - + diff --git a/src/Plugins/BotSharp.Plugin.AudioHandler/BotSharp.Plugin.AudioHandler.csproj b/src/Plugins/BotSharp.Plugin.AudioHandler/BotSharp.Plugin.AudioHandler.csproj index e7459219..ace72c5c 100644 --- a/src/Plugins/BotSharp.Plugin.AudioHandler/BotSharp.Plugin.AudioHandler.csproj +++ b/src/Plugins/BotSharp.Plugin.AudioHandler/BotSharp.Plugin.AudioHandler.csproj @@ -9,15 +9,14 @@ $(GeneratePackageOnBuild) $(GenerateDocumentationFile) $(SolutionDir)packages - true - - - - - + + + + +