Merge branch 'SciSharp:master' into master
This commit is contained in:
commit
2d7e66b550
|
|
@ -0,0 +1,6 @@
|
||||||
|
namespace BotSharp.Abstraction.Agents.Constants;
|
||||||
|
|
||||||
|
public static class LlmConstant
|
||||||
|
{
|
||||||
|
public const int DEFAULT_MAX_OUTPUT_TOKEN = 1024;
|
||||||
|
}
|
||||||
|
|
@ -22,6 +22,16 @@ public class AgentLlmConfig
|
||||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||||
public string? Model { get; set; }
|
public string? Model { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Max recursion depth
|
||||||
|
/// </summary>
|
||||||
[JsonPropertyName("max_recursion_depth")]
|
[JsonPropertyName("max_recursion_depth")]
|
||||||
public int MaxRecursionDepth { get; set; } = 3;
|
public int MaxRecursionDepth { get; set; } = 3;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Max output token
|
||||||
|
/// </summary>
|
||||||
|
[JsonPropertyName("max_output_tokens")]
|
||||||
|
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||||
|
public int? MaxOutputTokens { get; set; }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,55 +34,32 @@ public interface IBotSharpRepository : IHaveServiceProvider
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region User
|
#region User
|
||||||
User? GetUserByEmail(string email)
|
User? GetUserByEmail(string email) => throw new NotImplementedException();
|
||||||
=> throw new NotImplementedException();
|
User? GetUserByPhone(string phone, string type = UserType.Client, string regionCode = "CN") => throw new NotImplementedException();
|
||||||
User? GetUserByPhone(string phone, string type = UserType.Client, string regionCode = "CN")
|
User? GetUserByPhoneV2(string phone, string source = UserType.Internal, string regionCode = "CN") => throw new NotImplementedException();
|
||||||
=> throw new NotImplementedException();
|
User? GetAffiliateUserByPhone(string phone) => throw new NotImplementedException();
|
||||||
User? GetAffiliateUserByPhone(string phone)
|
User? GetUserById(string id) => throw new NotImplementedException();
|
||||||
=> throw new NotImplementedException();
|
List<User> GetUserByIds(List<string> ids) => throw new NotImplementedException();
|
||||||
User? GetUserById(string id)
|
List<User> GetUsersByAffiliateId(string affiliateId) => throw new NotImplementedException();
|
||||||
=> throw new NotImplementedException();
|
User? GetUserByUserName(string userName) => throw new NotImplementedException();
|
||||||
List<User> GetUserByIds(List<string> ids)
|
void UpdateUserName(string userId, string userName) => throw new NotImplementedException();
|
||||||
=> throw new NotImplementedException();
|
Dashboard? GetDashboard(string id = null) => throw new NotImplementedException();
|
||||||
List<User> GetUsersByAffiliateId(string affiliateId)
|
void CreateUser(User user) => throw new NotImplementedException();
|
||||||
=> throw new NotImplementedException();
|
void UpdateExistUser(string userId, User user) => throw new NotImplementedException();
|
||||||
User? GetUserByUserName(string userName)
|
void UpdateUserVerified(string userId) => throw new NotImplementedException();
|
||||||
=> throw new NotImplementedException();
|
void AddDashboardConversation(string userId, string conversationId) => throw new NotImplementedException();
|
||||||
void UpdateUserName(string userId, string userName)
|
void RemoveDashboardConversation(string userId, string conversationId) => throw new NotImplementedException();
|
||||||
=> throw new NotImplementedException();
|
void UpdateDashboardConversation(string userId, DashboardConversation dashConv) => throw new NotImplementedException();
|
||||||
Dashboard? GetDashboard(string userId = null)
|
void UpdateUserVerificationCode(string userId, string verficationCode) => throw new NotImplementedException();
|
||||||
=> throw new NotImplementedException();
|
void UpdateUserPassword(string userId, string password) => throw new NotImplementedException();
|
||||||
void CreateUser(User user)
|
void UpdateUserEmail(string userId, string email) => throw new NotImplementedException();
|
||||||
=> throw new NotImplementedException();
|
void UpdateUserPhone(string userId, string Iphone, string regionCode) => throw new NotImplementedException();
|
||||||
void UpdateExistUser(string userId, User user)
|
void UpdateUserIsDisable(string userId, bool isDisable) => throw new NotImplementedException();
|
||||||
=> throw new NotImplementedException();
|
void UpdateUsersIsDisable(List<string> userIds, bool isDisable) => throw new NotImplementedException();
|
||||||
void UpdateUserVerified(string userId)
|
PagedItems<User> GetUsers(UserFilter filter) => throw new NotImplementedException();
|
||||||
=> throw new NotImplementedException();
|
List<User> SearchLoginUsers(User filter, string source = UserSource.Internal) =>throw new NotImplementedException();
|
||||||
void AddDashboardConversation(string userId, string conversationId)
|
User? GetUserDetails(string userId, bool includeAgent = false) => throw new NotImplementedException();
|
||||||
=> throw new NotImplementedException();
|
bool UpdateUser(User user, bool updateUserAgents = false) => throw new NotImplementedException();
|
||||||
void RemoveDashboardConversation(string userId, string conversationId)
|
|
||||||
=> throw new NotImplementedException();
|
|
||||||
void UpdateDashboardConversation(string userId, DashboardConversation dashConv)
|
|
||||||
=> throw new NotImplementedException();
|
|
||||||
void UpdateUserVerificationCode(string userId, string verficationCode)
|
|
||||||
=> throw new NotImplementedException();
|
|
||||||
void UpdateUserPassword(string userId, string password)
|
|
||||||
=> throw new NotImplementedException();
|
|
||||||
void UpdateUserEmail(string userId, string email)
|
|
||||||
=> throw new NotImplementedException();
|
|
||||||
void UpdateUserPhone(string userId, string Iphone, string regionCode)
|
|
||||||
=> throw new NotImplementedException();
|
|
||||||
void UpdateUserIsDisable(string userId, bool isDisable)
|
|
||||||
=> throw new NotImplementedException();
|
|
||||||
void UpdateUsersIsDisable(List<string> userIds, bool isDisable)
|
|
||||||
=> throw new NotImplementedException();
|
|
||||||
PagedItems<User> GetUsers(UserFilter filter)
|
|
||||||
=> throw new NotImplementedException();
|
|
||||||
User? GetUserDetails(string userId, bool includeAgent = false)
|
|
||||||
=> throw new NotImplementedException();
|
|
||||||
bool UpdateUser(User user, bool updateUserAgents = false)
|
|
||||||
=> throw new NotImplementedException();
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Agent
|
#region Agent
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ public class BotSharpStats
|
||||||
public static (DateTime, DateTime) BuildTimeInterval(DateTime recordTime, StatsInterval interval)
|
public static (DateTime, DateTime) BuildTimeInterval(DateTime recordTime, StatsInterval interval)
|
||||||
{
|
{
|
||||||
DateTime startTime = recordTime;
|
DateTime startTime = recordTime;
|
||||||
DateTime endTime = DateTime.UtcNow;
|
DateTime endTime = startTime;
|
||||||
|
|
||||||
switch (interval)
|
switch (interval)
|
||||||
{
|
{
|
||||||
|
|
@ -70,6 +70,7 @@ public class BotSharpStats
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
endTime = endTime.AddSeconds(-1);
|
||||||
startTime = DateTime.SpecifyKind(startTime, DateTimeKind.Utc);
|
startTime = DateTime.SpecifyKind(startTime, DateTimeKind.Utc);
|
||||||
endTime = DateTime.SpecifyKind(endTime, DateTimeKind.Utc);
|
endTime = DateTime.SpecifyKind(endTime, DateTimeKind.Utc);
|
||||||
return (startTime, endTime);
|
return (startTime, endTime);
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ public interface IUserService
|
||||||
{
|
{
|
||||||
Task<User> GetUser(string id);
|
Task<User> GetUser(string id);
|
||||||
Task<PagedItems<User>> GetUsers(UserFilter filter);
|
Task<PagedItems<User>> GetUsers(UserFilter filter);
|
||||||
|
Task<List<User>> SearchLoginUsers(User filter);
|
||||||
Task<User?> GetUserDetails(string userId, bool includeAgent = false);
|
Task<User?> GetUserDetails(string userId, bool includeAgent = false);
|
||||||
Task<bool> IsAdminUser(string userId);
|
Task<bool> IsAdminUser(string userId);
|
||||||
Task<UserAuthorization> GetUserAuthorizations(IEnumerable<string>? agentIds = null);
|
Task<UserAuthorization> GetUserAuthorizations(IEnumerable<string>? agentIds = null);
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,23 @@ public partial class FileRepository
|
||||||
return query.FirstOrDefault();
|
return query.FirstOrDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public User? GetUserByPhoneV2(string phone, string? source = UserType.Internal, string regionCode = "CN")
|
||||||
|
{
|
||||||
|
var query = Users.Where(x => x.Phone == phone);
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(source))
|
||||||
|
{
|
||||||
|
query = query.Where(x => x.Type == source);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(regionCode))
|
||||||
|
{
|
||||||
|
query = query.Where(x => x.RegionCode == regionCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
return query.FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
public User? GetAffiliateUserByPhone(string phone)
|
public User? GetAffiliateUserByPhone(string phone)
|
||||||
{
|
{
|
||||||
return Users.FirstOrDefault(x => x.Phone == phone && x.Type == UserType.Affiliate);
|
return Users.FirstOrDefault(x => x.Phone == phone && x.Type == UserType.Affiliate);
|
||||||
|
|
@ -128,6 +145,65 @@ public partial class FileRepository
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<User> SearchLoginUsers(User filter, string source = UserSource.Internal)
|
||||||
|
{
|
||||||
|
List<User> searchResult = new List<User>();
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
if (user != null)
|
||||||
|
{
|
||||||
|
searchResult.Add(user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return searchResult;
|
||||||
|
}
|
||||||
|
|
||||||
public User? GetUserDetails(string userId, bool includeAgent = false)
|
public User? GetUserDetails(string userId, bool includeAgent = false)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(userId)) return null;
|
if (string.IsNullOrWhiteSpace(userId)) return null;
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,11 @@ public class UserService : IUserService
|
||||||
|
|
||||||
if (record == null && !string.IsNullOrWhiteSpace(user.Phone))
|
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));
|
record = db.GetUserByPhone(user.Phone, regionCode: (string.IsNullOrWhiteSpace(user.RegionCode) ? "CN" : user.RegionCode));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -477,11 +482,17 @@ public class UserService : IUserService
|
||||||
var id = model.UserName;
|
var id = model.UserName;
|
||||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||||
var record = id.Contains("@") ? db.GetUserByEmail(id) : db.GetUserByUserName(id);
|
var record = id.Contains("@") ? db.GetUserByEmail(id) : db.GetUserByUserName(id);
|
||||||
|
|
||||||
if (record == null)
|
if (record == null)
|
||||||
{
|
{
|
||||||
record = db.GetUserByPhone(id, regionCode: (string.IsNullOrWhiteSpace(model.RegionCode) ? "CN" : model.RegionCode));
|
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)
|
if (record == null)
|
||||||
{
|
{
|
||||||
return default;
|
return default;
|
||||||
|
|
@ -570,6 +581,18 @@ public class UserService : IUserService
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<List<User>> SearchLoginUsers(User filter)
|
||||||
|
{
|
||||||
|
if (filter == null)
|
||||||
|
{
|
||||||
|
return new List<User>();
|
||||||
|
}
|
||||||
|
|
||||||
|
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||||
|
|
||||||
|
return db.SearchLoginUsers(filter);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<bool> VerifyPhoneExisting(string phone, string regionCode)
|
public async Task<bool> VerifyPhoneExisting(string phone, string regionCode)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(phone))
|
if (string.IsNullOrWhiteSpace(phone))
|
||||||
|
|
@ -609,21 +632,12 @@ public class UserService : IUserService
|
||||||
public async Task<User> ResetVerificationCode(User user)
|
public async Task<User> ResetVerificationCode(User user)
|
||||||
{
|
{
|
||||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||||
User record = null;
|
if (!string.IsNullOrWhiteSpace(user.Email) && !string.IsNullOrWhiteSpace(user.Phone))
|
||||||
if (!string.IsNullOrEmpty(user.Email) && !string.IsNullOrEmpty(user.Phone))
|
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(user.Phone))
|
User? record = GetLoginUserByUniqueFilter(user, db);
|
||||||
{
|
|
||||||
record = db.GetUserByPhone(user.Phone, regionCode: user.RegionCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(user.Email))
|
|
||||||
{
|
|
||||||
record = db.GetUserByEmail(user.Email);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (record == null)
|
if (record == null)
|
||||||
{
|
{
|
||||||
|
|
@ -638,6 +652,36 @@ public class UserService : IUserService
|
||||||
return record;
|
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<bool> SendVerificationCodeLogin()
|
public async Task<bool> SendVerificationCodeLogin()
|
||||||
{
|
{
|
||||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||||
|
|
@ -677,17 +721,7 @@ public class UserService : IUserService
|
||||||
}
|
}
|
||||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||||
|
|
||||||
User? record = null;
|
User? record = GetLoginUserByUniqueFilter(user, db);
|
||||||
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (record == null)
|
if (record == null)
|
||||||
{
|
{
|
||||||
|
|
@ -712,20 +746,7 @@ public class UserService : IUserService
|
||||||
}
|
}
|
||||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||||
|
|
||||||
User? record = null;
|
User? record = GetLoginUserByUniqueFilter(user, db);
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (record == null)
|
if (record == null)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ public class AgentCreationModel
|
||||||
MaxMessageCount = MaxMessageCount,
|
MaxMessageCount = MaxMessageCount,
|
||||||
Profiles = Profiles,
|
Profiles = Profiles,
|
||||||
Labels = Labels,
|
Labels = Labels,
|
||||||
LlmConfig = LlmConfig,
|
LlmConfig = LlmConfig ?? new(),
|
||||||
KnowledgeBases = KnowledgeBases,
|
KnowledgeBases = KnowledgeBases,
|
||||||
Rules = Rules,
|
Rules = Rules,
|
||||||
RoutingRules = RoutingRules?.Select(x => RoutingRuleUpdateModel.ToDomainElement(x))?.ToList() ?? [],
|
RoutingRules = RoutingRules?.Select(x => RoutingRuleUpdateModel.ToDomainElement(x))?.ToList() ?? [],
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,7 @@ public class AgentUpdateModel
|
||||||
Utilities = Utilities ?? [],
|
Utilities = Utilities ?? [],
|
||||||
KnowledgeBases = KnowledgeBases ?? [],
|
KnowledgeBases = KnowledgeBases ?? [],
|
||||||
Rules = Rules ?? [],
|
Rules = Rules ?? [],
|
||||||
LlmConfig = LlmConfig
|
LlmConfig = LlmConfig ?? new()
|
||||||
};
|
};
|
||||||
|
|
||||||
return agent;
|
return agent;
|
||||||
|
|
|
||||||
|
|
@ -170,12 +170,14 @@ public class ChatCompletionProvider : IChatCompletion
|
||||||
|
|
||||||
var state = _services.GetRequiredService<IConversationStateService>();
|
var state = _services.GetRequiredService<IConversationStateService>();
|
||||||
var temperature = decimal.Parse(state.GetState("temperature", "0.0"));
|
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()
|
var parameters = new MessageParameters()
|
||||||
{
|
{
|
||||||
Messages = messages,
|
Messages = messages,
|
||||||
MaxTokens = maxToken,
|
MaxTokens = maxTokens,
|
||||||
Model = settings.Name,
|
Model = settings.Name,
|
||||||
Stream = false,
|
Stream = false,
|
||||||
Temperature = temperature,
|
Temperature = temperature,
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ global using Anthropic.SDK;
|
||||||
global using Anthropic.SDK.Constants;
|
global using Anthropic.SDK.Constants;
|
||||||
global using Anthropic.SDK.Messaging;
|
global using Anthropic.SDK.Messaging;
|
||||||
global using BotSharp.Abstraction.Agents;
|
global using BotSharp.Abstraction.Agents;
|
||||||
|
global using BotSharp.Abstraction.Agents.Constants;
|
||||||
global using BotSharp.Abstraction.Agents.Enums;
|
global using BotSharp.Abstraction.Agents.Enums;
|
||||||
global using BotSharp.Abstraction.Agents.Models;
|
global using BotSharp.Abstraction.Agents.Models;
|
||||||
global using BotSharp.Abstraction.Conversations.Models;
|
global using BotSharp.Abstraction.Conversations.Models;
|
||||||
|
|
|
||||||
|
|
@ -225,7 +225,10 @@ public class ChatCompletionProvider : IChatCompletion
|
||||||
var messages = new List<ChatMessage>();
|
var messages = new List<ChatMessage>();
|
||||||
|
|
||||||
var temperature = float.Parse(state.GetState("temperature", "0.0"));
|
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()
|
var options = new ChatCompletionOptions()
|
||||||
{
|
{
|
||||||
Temperature = temperature,
|
Temperature = temperature,
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ global using System.IO;
|
||||||
global using System.Threading.Tasks;
|
global using System.Threading.Tasks;
|
||||||
global using Microsoft.Extensions.DependencyInjection;
|
global using Microsoft.Extensions.DependencyInjection;
|
||||||
global using Microsoft.Extensions.Logging;
|
global using Microsoft.Extensions.Logging;
|
||||||
|
global using BotSharp.Abstraction.Agents.Constants;
|
||||||
global using BotSharp.Abstraction.Agents.Enums;
|
global using BotSharp.Abstraction.Agents.Enums;
|
||||||
global using BotSharp.Abstraction.Agents.Models;
|
global using BotSharp.Abstraction.Agents.Models;
|
||||||
global using BotSharp.Abstraction.Conversations;
|
global using BotSharp.Abstraction.Conversations;
|
||||||
|
|
|
||||||
|
|
@ -201,7 +201,9 @@ public class ChatCompletionProvider : IChatCompletion
|
||||||
var messages = new List<ChatMessage>();
|
var messages = new List<ChatMessage>();
|
||||||
|
|
||||||
var temperature = float.Parse(state.GetState("temperature", "0.0"));
|
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()
|
var options = new ChatCompletionOptions()
|
||||||
{
|
{
|
||||||
Temperature = temperature,
|
Temperature = temperature,
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ global using BotSharp.Abstraction.Conversations.Models;
|
||||||
global using BotSharp.Abstraction.Agents.Models;
|
global using BotSharp.Abstraction.Agents.Models;
|
||||||
global using BotSharp.Abstraction.MLTasks;
|
global using BotSharp.Abstraction.MLTasks;
|
||||||
global using BotSharp.Abstraction.Agents;
|
global using BotSharp.Abstraction.Agents;
|
||||||
|
global using BotSharp.Abstraction.Agents.Constants;
|
||||||
global using BotSharp.Abstraction.Agents.Enums;
|
global using BotSharp.Abstraction.Agents.Enums;
|
||||||
global using BotSharp.Abstraction.Conversations;
|
global using BotSharp.Abstraction.Conversations;
|
||||||
global using BotSharp.Abstraction.Loggers;
|
global using BotSharp.Abstraction.Loggers;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
using BotSharp.Abstraction.Agents;
|
using BotSharp.Abstraction.Agents;
|
||||||
using BotSharp.Abstraction.Agents.Enums;
|
using BotSharp.Abstraction.Agents.Enums;
|
||||||
|
using BotSharp.Abstraction.Conversations;
|
||||||
using BotSharp.Abstraction.Loggers;
|
using BotSharp.Abstraction.Loggers;
|
||||||
using Google.Protobuf.WellKnownTypes;
|
using Google.Protobuf.WellKnownTypes;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
@ -188,10 +189,20 @@ public class GeminiChatCompletionProvider : IChatCompletion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var state = _services.GetRequiredService<IConversationStateService>();
|
||||||
|
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
|
var request = new GenerateContentRequest
|
||||||
{
|
{
|
||||||
Contents = contents,
|
Contents = contents,
|
||||||
Tools = tools
|
Tools = tools,
|
||||||
|
GenerationConfig = new()
|
||||||
|
{
|
||||||
|
Temperature = temperature,
|
||||||
|
MaxOutputTokens = maxTokens
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var prompt = GetPrompt(systemPrompts, funcPrompts, convPrompts);
|
var prompt = GetPrompt(systemPrompts, funcPrompts, convPrompts);
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ global using System.Threading.Tasks;
|
||||||
global using System.Linq;
|
global using System.Linq;
|
||||||
global using System.Text.Json;
|
global using System.Text.Json;
|
||||||
global using BotSharp.Abstraction.Conversations.Models;
|
global using BotSharp.Abstraction.Conversations.Models;
|
||||||
|
global using BotSharp.Abstraction.Agents.Constants;
|
||||||
global using BotSharp.Abstraction.Agents.Models;
|
global using BotSharp.Abstraction.Agents.Models;
|
||||||
global using BotSharp.Abstraction.MLTasks;
|
global using BotSharp.Abstraction.MLTasks;
|
||||||
global using Microsoft.Extensions.Configuration;
|
global using Microsoft.Extensions.Configuration;
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ public class AgentLlmConfigMongoElement
|
||||||
public string? Model { get; set; }
|
public string? Model { get; set; }
|
||||||
public bool IsInherit { get; set; }
|
public bool IsInherit { get; set; }
|
||||||
public int MaxRecursionDepth { get; set; }
|
public int MaxRecursionDepth { get; set; }
|
||||||
|
public int? MaxOutputTokens { get; set; }
|
||||||
|
|
||||||
public static AgentLlmConfigMongoElement? ToMongoElement(AgentLlmConfig? config)
|
public static AgentLlmConfigMongoElement? ToMongoElement(AgentLlmConfig? config)
|
||||||
{
|
{
|
||||||
|
|
@ -19,6 +20,7 @@ public class AgentLlmConfigMongoElement
|
||||||
Model = config.Model,
|
Model = config.Model,
|
||||||
IsInherit = config.IsInherit,
|
IsInherit = config.IsInherit,
|
||||||
MaxRecursionDepth = config.MaxRecursionDepth,
|
MaxRecursionDepth = config.MaxRecursionDepth,
|
||||||
|
MaxOutputTokens = config.MaxOutputTokens,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -32,6 +34,7 @@ public class AgentLlmConfigMongoElement
|
||||||
Model = config.Model,
|
Model = config.Model,
|
||||||
IsInherit = config.IsInherit,
|
IsInherit = config.IsInherit,
|
||||||
MaxRecursionDepth = config.MaxRecursionDepth,
|
MaxRecursionDepth = config.MaxRecursionDepth,
|
||||||
|
MaxOutputTokens = config.MaxOutputTokens,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,30 @@ public partial class MongoRepository
|
||||||
return user != null ? user.ToUser() : null;
|
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
|
||||||
|
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.Source == source));
|
||||||
|
return user != null ? user.ToUser() : null;
|
||||||
|
}
|
||||||
|
|
||||||
public User? GetAffiliateUserByPhone(string phone)
|
public User? GetAffiliateUserByPhone(string phone)
|
||||||
{
|
{
|
||||||
var user = _dc.Users.AsQueryable().FirstOrDefault(x => x.Phone == phone && x.Type == UserType.Affiliate);
|
var user = _dc.Users.AsQueryable().FirstOrDefault(x => x.Phone == phone && x.Type == UserType.Affiliate);
|
||||||
|
|
@ -233,6 +257,77 @@ public partial class MongoRepository
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<User> SearchLoginUsers(User filter, string source = UserSource.Internal)
|
||||||
|
{
|
||||||
|
List<User> searchResult = new List<User>();
|
||||||
|
|
||||||
|
// 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.ToLower());
|
||||||
|
User user = curUser != null ? curUser.ToUser() : null;
|
||||||
|
if (user != null)
|
||||||
|
{
|
||||||
|
searchResult.Add(user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
if (user != null)
|
||||||
|
{
|
||||||
|
searchResult.Add(user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return searchResult;
|
||||||
|
}
|
||||||
|
|
||||||
public User? GetUserDetails(string userId, bool includeAgent = false)
|
public User? GetUserDetails(string userId, bool includeAgent = false)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(userId)) return null;
|
if (string.IsNullOrWhiteSpace(userId)) return null;
|
||||||
|
|
|
||||||
|
|
@ -202,7 +202,9 @@ public class ChatCompletionProvider : IChatCompletion
|
||||||
var messages = new List<ChatMessage>();
|
var messages = new List<ChatMessage>();
|
||||||
|
|
||||||
var temperature = float.Parse(state.GetState("temperature", "0.0"));
|
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()
|
var options = new ChatCompletionOptions()
|
||||||
{
|
{
|
||||||
Temperature = temperature,
|
Temperature = temperature,
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,9 @@ public class RealTimeCompletionProvider : IRealTimeCompletion
|
||||||
var messages = new List<ChatMessage>();
|
var messages = new List<ChatMessage>();
|
||||||
|
|
||||||
var temperature = float.Parse(state.GetState("temperature", "0.0"));
|
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()
|
var options = new ChatCompletionOptions()
|
||||||
{
|
{
|
||||||
ToolChoice = ChatToolChoice.CreateAutoChoice(),
|
ToolChoice = ChatToolChoice.CreateAutoChoice(),
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ global using Microsoft.Extensions.DependencyInjection;
|
||||||
global using Microsoft.Extensions.Logging;
|
global using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
global using BotSharp.Abstraction.Agents.Enums;
|
global using BotSharp.Abstraction.Agents.Enums;
|
||||||
|
global using BotSharp.Abstraction.Agents.Constants;
|
||||||
global using BotSharp.Abstraction.Agents.Models;
|
global using BotSharp.Abstraction.Agents.Models;
|
||||||
global using BotSharp.Abstraction.Conversations;
|
global using BotSharp.Abstraction.Conversations;
|
||||||
global using BotSharp.Abstraction.Conversations.Models;
|
global using BotSharp.Abstraction.Conversations.Models;
|
||||||
|
|
|
||||||
|
|
@ -75,9 +75,6 @@ public partial class PlaywrightWebDriver : IWebBrowser
|
||||||
var page = _instance.GetPage(message.ContextId);
|
var page = _instance.GetPage(message.ContextId);
|
||||||
if (page != null)
|
if (page != null)
|
||||||
{
|
{
|
||||||
// Click on the body to give focus to the page
|
|
||||||
await page.FocusAsync("input");
|
|
||||||
|
|
||||||
await page.Keyboard.PressAsync(key);
|
await page.Keyboard.PressAsync(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue