Skip to content

Commit e87f505

Browse files
authored
Merge pull request #197 from hchen2020/master
Fix RichContent pass alway bug.
2 parents 0aa52c1 + cb15452 commit e87f505

File tree

5 files changed

+23
-8
lines changed

5 files changed

+23
-8
lines changed

src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class Agent
2828
/// </summary>
2929
[JsonIgnore]
3030
public List<string> Samples { get; set; }
31+
= new List<string>();
3132

3233
/// <summary>
3334
/// Functions
@@ -70,6 +71,7 @@ public class Agent
7071
/// </summary>
7172
[JsonIgnore]
7273
public Dictionary<string, object> TemplateDict { get; set; }
74+
= new Dictionary<string, object>();
7375

7476
public override string ToString()
7577
=> $"{Name} {Id}";

src/Infrastructure/BotSharp.Abstraction/Utilities/StringExtensions.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ public static string JsonContent(this string text)
3838
public static T? JsonContent<T>(this string text)
3939
{
4040
text = JsonContent(text);
41-
return JsonSerializer.Deserialize<T>(text);
41+
42+
var options = new JsonSerializerOptions
43+
{
44+
PropertyNameCaseInsensitive = true,
45+
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
46+
WriteIndented = true,
47+
AllowTrailingCommas = true
48+
};
49+
50+
return JsonSerializer.Deserialize<T>(text, options);
4251
}
4352
}

src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -464,9 +464,6 @@ private void UpdateAgentAllFields(Agent inputAgent)
464464
}
465465
#endregion
466466

467-
#if !DEBUG
468-
[MemoryCache(10 * 60)]
469-
#endif
470467
public List<string> GetAgentResponses(string agentId, string prefix, string intent)
471468
{
472469
var responses = new List<string>();

src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,22 @@ public async Task<bool> InvokeAgent(string agentId, List<RoleDialogModel> dialog
2323
var settings = _services.GetRequiredService<ChatCompletionSetting>();
2424
var chatCompletion = CompletionProvider.GetChatCompletion(_services, provider: settings.Provider, model: settings.Model);
2525

26-
RoleDialogModel response = chatCompletion.GetChatCompletions(agent, dialogs);
26+
var message = dialogs.Last();
27+
var response = chatCompletion.GetChatCompletions(agent, dialogs);
2728

2829
if (response.Role == AgentRole.Function)
2930
{
30-
await InvokeFunction(agent, response, dialogs);
31+
message = RoleDialogModel.From(message,
32+
role: AgentRole.Function);
33+
message.FunctionName = response.FunctionName;
34+
message.FunctionArgs = response.FunctionArgs;
35+
await InvokeFunction(agent, message, dialogs);
3136
}
3237
else
3338
{
34-
dialogs.Add(response);
39+
dialogs.Add(RoleDialogModel.From(message,
40+
role: AgentRole.Assistant,
41+
content: response.Content));
3542
}
3643

3744
return true;

src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/ChatCompletionProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ private string GetPrompt(ChatCompletionsOptions chatCompletionsOptions)
298298
{
299299
var functions = string.Join("\r\n", chatCompletionsOptions.Functions.Select(x =>
300300
{
301-
return $"{x.Name}: {x.Description}\r\n{x.Parameters}";
301+
return $"\r\n{x.Name}: {x.Description}\r\n{x.Parameters}";
302302
}));
303303
prompt += $"\r\n[FUNCTIONS]\r\n{functions}\r\n";
304304
}

0 commit comments

Comments
 (0)