Skip to content

Fix RichContent pass alway bug. #197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class Agent
/// </summary>
[JsonIgnore]
public List<string> Samples { get; set; }
= new List<string>();

/// <summary>
/// Functions
Expand Down Expand Up @@ -70,6 +71,7 @@ public class Agent
/// </summary>
[JsonIgnore]
public Dictionary<string, object> TemplateDict { get; set; }
= new Dictionary<string, object>();

public override string ToString()
=> $"{Name} {Id}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ public static string JsonContent(this string text)
public static T? JsonContent<T>(this string text)
{
text = JsonContent(text);
return JsonSerializer.Deserialize<T>(text);

var options = new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
WriteIndented = true,
AllowTrailingCommas = true
};

return JsonSerializer.Deserialize<T>(text, options);
}
}
3 changes: 0 additions & 3 deletions src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,6 @@ private void UpdateAgentAllFields(Agent inputAgent)
}
#endregion

#if !DEBUG
[MemoryCache(10 * 60)]
#endif
public List<string> GetAgentResponses(string agentId, string prefix, string intent)
{
var responses = new List<string>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,22 @@ public async Task<bool> InvokeAgent(string agentId, List<RoleDialogModel> dialog
var settings = _services.GetRequiredService<ChatCompletionSetting>();
var chatCompletion = CompletionProvider.GetChatCompletion(_services, provider: settings.Provider, model: settings.Model);

RoleDialogModel response = chatCompletion.GetChatCompletions(agent, dialogs);
var message = dialogs.Last();
var response = chatCompletion.GetChatCompletions(agent, dialogs);

if (response.Role == AgentRole.Function)
{
await InvokeFunction(agent, response, dialogs);
message = RoleDialogModel.From(message,
role: AgentRole.Function);
message.FunctionName = response.FunctionName;
message.FunctionArgs = response.FunctionArgs;
await InvokeFunction(agent, message, dialogs);
}
else
{
dialogs.Add(response);
dialogs.Add(RoleDialogModel.From(message,
role: AgentRole.Assistant,
content: response.Content));
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ private string GetPrompt(ChatCompletionsOptions chatCompletionsOptions)
{
var functions = string.Join("\r\n", chatCompletionsOptions.Functions.Select(x =>
{
return $"{x.Name}: {x.Description}\r\n{x.Parameters}";
return $"\r\n{x.Name}: {x.Description}\r\n{x.Parameters}";
}));
prompt += $"\r\n[FUNCTIONS]\r\n{functions}\r\n";
}
Expand Down