Skip to content
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