Merge branch 'SciSharp:master' into master
This commit is contained in:
commit
8cdab6b356
|
|
@ -17,6 +17,6 @@ public interface IConversationStateService
|
|||
int activeRounds = -1, string valueType = StateDataType.String, string source = StateSource.User, bool readOnly = false);
|
||||
void SaveStateByArgs(JsonDocument args);
|
||||
bool RemoveState(string name);
|
||||
void CleanStates();
|
||||
void CleanStates(params string[] keepStates);
|
||||
void Save();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,4 +7,6 @@ public class StateConst
|
|||
public const string NEXT_ACTION_AGENT = "next_action_agent";
|
||||
public const string NEXT_ACTION_REASON = "next_action_reason";
|
||||
public const string USER_GOAL_AGENT = "user_goal_agent";
|
||||
|
||||
public const string LANGUAGE = "language";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
using BotSharp.Abstraction.Infrastructures.Enums;
|
||||
|
||||
namespace BotSharp.Core.Conversations.Services;
|
||||
|
||||
public partial class ConversationService : IConversationService
|
||||
|
|
@ -19,7 +21,8 @@ public partial class ConversationService : IConversationService
|
|||
if (resetStates)
|
||||
{
|
||||
var states = _services.GetRequiredService<IConversationStateService>();
|
||||
states.CleanStates();
|
||||
// keep language state
|
||||
states.CleanStates(StateConst.LANGUAGE);
|
||||
}
|
||||
|
||||
var hooks = _services.GetServices<IConversationHook>()
|
||||
|
|
|
|||
|
|
@ -270,7 +270,7 @@ public class ConversationStateService : IConversationStateService, IDisposable
|
|||
return true;
|
||||
}
|
||||
|
||||
public void CleanStates()
|
||||
public void CleanStates(params string[] keepStates)
|
||||
{
|
||||
var routingCtx = _services.GetRequiredService<IRoutingContext>();
|
||||
var curMsgId = routingCtx.MessageId;
|
||||
|
|
@ -278,6 +278,12 @@ public class ConversationStateService : IConversationStateService, IDisposable
|
|||
|
||||
foreach (var key in _curStates.Keys)
|
||||
{
|
||||
// skip state
|
||||
if (keepStates.Contains(key))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var value = _curStates[key];
|
||||
if (value == null || !value.Versioning || value.Values.IsNullOrEmpty()) continue;
|
||||
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ public partial class RoutingService : IRoutingService
|
|||
{
|
||||
var translator = _services.GetRequiredService<ITranslationService>();
|
||||
|
||||
var language = states.GetState("language", LanguageType.UNKNOWN);
|
||||
var language = states.GetState(StateConst.LANGUAGE, LanguageType.UNKNOWN);
|
||||
if (language != LanguageType.ENGLISH)
|
||||
{
|
||||
message.SecondaryContent = message.Content;
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ namespace BotSharp.Logger.Hooks
|
|||
var agentService = _services.GetRequiredService<IAgentService>();
|
||||
var router = await agentService.LoadAgent(AIAssistant);
|
||||
var translator = _services.GetRequiredService<ITranslationService>();
|
||||
var language = _states.GetState("language", LanguageType.ENGLISH);
|
||||
var language = _states.GetState(StateConst.LANGUAGE, LanguageType.ENGLISH);
|
||||
if (language != LanguageType.UNKNOWN && language != LanguageType.ENGLISH)
|
||||
{
|
||||
if (message.RichContent != null)
|
||||
|
|
|
|||
|
|
@ -61,10 +61,10 @@ public class TranslationService : ITranslationService
|
|||
{
|
||||
// Override language if it's Unknown, it's used to output the corresponding language.
|
||||
var states = _services.GetRequiredService<IConversationStateService>();
|
||||
if (!states.ContainsState("language"))
|
||||
if (!states.ContainsState(StateConst.LANGUAGE))
|
||||
{
|
||||
var inputLanguage = string.IsNullOrEmpty(translatedStringList.InputLanguage) ? LanguageType.ENGLISH : translatedStringList.InputLanguage;
|
||||
states.SetState("language", inputLanguage, activeRounds: 1);
|
||||
states.SetState(StateConst.LANGUAGE, inputLanguage, activeRounds: 1);
|
||||
}
|
||||
|
||||
var translatedTexts = translatedStringList.Texts;
|
||||
|
|
@ -302,7 +302,7 @@ public class TranslationService : ITranslationService
|
|||
TemplateDict = new Dictionary<string, object>
|
||||
{
|
||||
{ "text_list", texts },
|
||||
{ "language", language }
|
||||
{ StateConst.LANGUAGE, language }
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -22,17 +22,19 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="8.0.2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="8.0.4" />
|
||||
<PackageReference Include="AspNet.Security.OAuth.GitHub" Version="8.0.0" />
|
||||
<PackageReference Include="AspNet.Security.OAuth.Keycloak" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="8.0.2" />
|
||||
<PackageReference Include="AspNet.Security.OAuth.Weixin" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.4" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="8.0.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="6.0.27" />
|
||||
<PackageReference Include="AspNet.Security.OAuth.GitHub" Version="6.0.15" />
|
||||
<PackageReference Include="AspNet.Security.OAuth.Keycloak" Version="6.0.15" />
|
||||
<PackageReference Include="AspNet.Security.OAuth.Weixin" Version="6.0.15" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.25" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="6.0.26" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
|
|
@ -126,6 +126,20 @@ public static class BotSharpOpenApiExtensions
|
|||
});
|
||||
}
|
||||
|
||||
// Wexin OAuth
|
||||
if (!string.IsNullOrWhiteSpace(config["OAuth:Wexin:ClientId"]) && !string.IsNullOrWhiteSpace(config["OAuth:Wexin:ClientSecret"]))
|
||||
{
|
||||
builder = builder.AddWeixin(options =>
|
||||
{
|
||||
options.ClientId = config["OAuth:GitHub:ClientId"];
|
||||
options.ClientSecret = config["OAuth:GitHub:ClientSecret"];
|
||||
options.Scope.Add("user:email");
|
||||
options.Backchannel = builder.Services.BuildServiceProvider()
|
||||
.GetRequiredService<IHttpClientFactory>()
|
||||
.CreateClient();
|
||||
});
|
||||
}
|
||||
|
||||
// Add services to the container.
|
||||
services.AddControllers()
|
||||
.AddJsonOptions(options =>
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="LLamaSharp" Version="0.11.2" />
|
||||
<PackageReference Include="LLamaSharp" Version="0.12.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>$(TargetFramework)</TargetFramework>
|
||||
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Serilog.Extensions.Hosting" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.6" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.20.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -33,6 +33,10 @@
|
|||
"ClientId": "",
|
||||
"ClientSecret": "",
|
||||
"Version": 22
|
||||
},
|
||||
"Weixin": {
|
||||
"AppId": "",
|
||||
"AppSecret": ""
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue