Merge pull request #115 from hchen2020/master
Catch and log function call error.
This commit is contained in:
commit
88a69f3d1d
|
|
@ -8,4 +8,5 @@ public class AgentSettings
|
|||
public string RouterId { get; set; }
|
||||
public string DataDir { get; set; }
|
||||
public string TemplateFormat { get; set; }
|
||||
public int MaxRecursiveDepth { get; set; } = 3;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,24 +0,0 @@
|
|||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace BotSharp.Abstraction.Functions.Models;
|
||||
|
||||
public class FunctionExecutionValidationResult
|
||||
{
|
||||
public FunctionExecutionValidationResult()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public FunctionExecutionValidationResult(string validationStatus, string? validationMessage = null)
|
||||
{
|
||||
ValidationStatus = validationStatus;
|
||||
ValidationMessage = validationMessage;
|
||||
}
|
||||
|
||||
[JsonPropertyName("validation_status")]
|
||||
public string ValidationStatus { get; set; }
|
||||
|
||||
[JsonPropertyName("validation_message")]
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
public string ValidationMessage { get; set; }
|
||||
}
|
||||
|
|
@ -29,9 +29,17 @@ public partial class ConversationService
|
|||
await hook.OnFunctionExecuting(msg);
|
||||
}
|
||||
|
||||
// Execute function
|
||||
await fn.Execute(msg);
|
||||
|
||||
try
|
||||
{
|
||||
// Execute function
|
||||
await fn.Execute(msg);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
msg.ExecutionResult = ex.Message;
|
||||
_logger.LogError(msg.ExecutionResult);
|
||||
}
|
||||
|
||||
// After functions have been executed
|
||||
foreach (var hook in hooks)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -7,13 +7,13 @@ namespace BotSharp.Core.Conversations.Services;
|
|||
|
||||
public partial class ConversationService
|
||||
{
|
||||
const int maxRecursiveDepth = 3;
|
||||
int currentRecursiveDepth = 0;
|
||||
|
||||
private async Task<bool> GetChatCompletionsAsyncRecursively(IChatCompletion chatCompletion,
|
||||
string conversationId,
|
||||
Agent agent,
|
||||
List<RoleDialogModel> wholeDialogs,
|
||||
int maxRecursiveDepth,
|
||||
Func<RoleDialogModel, Task> onMessageReceived,
|
||||
Func<RoleDialogModel, Task> onFunctionExecuting,
|
||||
Func<RoleDialogModel, Task> onFunctionExecuted)
|
||||
|
|
@ -83,6 +83,7 @@ public partial class ConversationService
|
|||
conversationId,
|
||||
agent,
|
||||
wholeDialogs,
|
||||
maxRecursiveDepth,
|
||||
onMessageReceived,
|
||||
onFunctionExecuting,
|
||||
onFunctionExecuted);
|
||||
|
|
|
|||
|
|
@ -65,11 +65,14 @@ public partial class ConversationService
|
|||
await hook.BeforeCompletion();
|
||||
}
|
||||
|
||||
var agentSettings = _services.GetRequiredService<AgentSettings>();
|
||||
|
||||
var chatCompletion = GetChatCompletion();
|
||||
var result = await GetChatCompletionsAsyncRecursively(chatCompletion,
|
||||
conversationId,
|
||||
agent,
|
||||
wholeDialogs,
|
||||
agentSettings.MaxRecursiveDepth,
|
||||
onMessageReceived,
|
||||
onFunctionExecuting,
|
||||
onFunctionExecuted);
|
||||
|
|
|
|||
Loading…
Reference in a new issue