Skip to content

Commit f1bb73d

Browse files
committed
minor change
1 parent 9593021 commit f1bb73d

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

src/Infrastructure/BotSharp.Core/Instructs/Services/InstructService.Execute.cs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public async Task<InstructResult> Execute(
4949

5050
// Run code template
5151
var codeResponse = await RunCode(agent, message, templateName, codeOptions);
52-
if (codeResponse != null)
52+
if (!string.IsNullOrWhiteSpace(codeResponse?.Text))
5353
{
5454
return codeResponse;
5555
}
@@ -266,17 +266,14 @@ await hook.OnResponseGenerated(new InstructResponseModel
266266
UseProcess = useProcess
267267
}, cancellationToken: cts.Token);
268268

269-
if (codeResponse?.Success == true)
269+
instructResult = new InstructResult
270270
{
271-
instructResult = new InstructResult
272-
{
273-
MessageId = message.MessageId,
274-
Template = context.CodeScript?.Name,
275-
Text = codeResponse.Result
276-
};
277-
}
271+
MessageId = message.MessageId,
272+
Template = context.CodeScript?.Name,
273+
Text = codeResponse?.Result ?? string.Empty
274+
};
278275

279-
var codeExeResponse = new CodeExecutionResponseModel
276+
var codeExecution = new CodeExecutionResponseModel
280277
{
281278
CodeProcessor = codeProcessor.Provider,
282279
CodeScript = context.CodeScript,
@@ -288,13 +285,8 @@ await hook.OnResponseGenerated(new InstructResponseModel
288285
// After code execution
289286
foreach (var hook in hooks)
290287
{
291-
await hook.AfterCompletion(agent, instructResult ?? new());
292-
await hook.AfterCodeExecution(agent, codeExeResponse);
293-
}
294-
295-
if (instructResult != null)
296-
{
297-
instructResult.Text = codeExeResponse?.ExecutionResult?.ToString() ?? string.Empty;
288+
await hook.AfterCompletion(agent, instructResult);
289+
await hook.AfterCodeExecution(agent, codeExecution);
298290
}
299291

300292
return instructResult;

0 commit comments

Comments
 (0)