Skip to content

Commit 200c042

Browse files
committed
move token out of options
1 parent 51239bc commit 200c042

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

src/Infrastructure/BotSharp.Abstraction/Coding/ICodeProcessor.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using BotSharp.Abstraction.Coding.Models;
22
using BotSharp.Abstraction.Coding.Options;
33
using BotSharp.Abstraction.Coding.Responses;
4+
using System.Threading;
45

56
namespace BotSharp.Abstraction.Coding;
67

@@ -13,9 +14,10 @@ public interface ICodeProcessor
1314
/// </summary>
1415
/// <param name="codeScript">The code scirpt to run</param>
1516
/// <param name="options">Code script execution options</param>
17+
/// <param name="cancellationToken">The cancellation token</param>
1618
/// <returns></returns>
1719
/// <exception cref="NotImplementedException"></exception>
18-
Task<CodeInterpretResponse> RunAsync(string codeScript, CodeInterpretOptions? options = null)
20+
Task<CodeInterpretResponse> RunAsync(string codeScript, CodeInterpretOptions? options = null, CancellationToken? cancellationToken = null)
1921
=> throw new NotImplementedException();
2022

2123
/// <summary>

src/Infrastructure/BotSharp.Abstraction/Coding/Options/CodeInterpretOptions.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,4 @@ public class CodeInterpretOptions
88
public IEnumerable<KeyValue>? Arguments { get; set; }
99
public bool UseLock { get; set; }
1010
public bool UseProcess { get; set; }
11-
public CancellationToken? OperationToken { get; set; }
12-
public CancellationToken? LockToken { get; set; }
1311
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,8 @@ await hook.OnResponseGenerated(new InstructResponseModel
259259
var codeResponse = await codeProcessor.RunAsync(context.CodeScript, options: new()
260260
{
261261
ScriptName = scriptName,
262-
Arguments = context.Arguments,
263-
OperationToken = cts.Token
264-
});
262+
Arguments = context.Arguments
263+
}, cancellationToken: cts.Token);
265264

266265
if (codeResponse == null || !codeResponse.Success)
267266
{

src/Plugins/BotSharp.Plugin.PythonInterpreter/Services/PyCodeInterpreter.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@ public PyCodeInterpreter(
3030

3131
public string Provider => "botsharp-py-interpreter";
3232

33-
public async Task<CodeInterpretResponse> RunAsync(string codeScript, CodeInterpretOptions? options = null)
33+
public async Task<CodeInterpretResponse> RunAsync(string codeScript, CodeInterpretOptions? options = null, CancellationToken? cancellationToken = null)
3434
{
3535
if (options?.UseLock == true)
3636
{
3737
return await _executor.ExecuteAsync(async () =>
3838
{
39-
return await InnerRunCode(codeScript, options);
40-
}, cancellationToken: options?.LockToken ?? CancellationToken.None);
39+
return await InnerRunCode(codeScript, options, cancellationToken);
40+
}, cancellationToken: cancellationToken ?? CancellationToken.None);
4141
}
4242

43-
return await InnerRunCode(codeScript, options);
43+
return await InnerRunCode(codeScript, options, cancellationToken);
4444
}
4545

4646
public async Task<CodeGenerationResult> GenerateCodeScriptAsync(string text, CodeGenerationOptions? options = null)
@@ -98,7 +98,7 @@ public async Task<CodeGenerationResult> GenerateCodeScriptAsync(string text, Cod
9898

9999

100100
#region Private methods
101-
private async Task<CodeInterpretResponse> InnerRunCode(string codeScript, CodeInterpretOptions? options = null)
101+
private async Task<CodeInterpretResponse> InnerRunCode(string codeScript, CodeInterpretOptions? options = null, CancellationToken? cancellationToken = null)
102102
{
103103
var response = new CodeInterpretResponse();
104104
var scriptName = options?.ScriptName ?? codeScript.SubstringMax(30);
@@ -109,11 +109,11 @@ private async Task<CodeInterpretResponse> InnerRunCode(string codeScript, CodeIn
109109

110110
if (options?.UseProcess == true)
111111
{
112-
response = await CoreRunProcess(codeScript, options);
112+
response = await CoreRunProcess(codeScript, options, cancellationToken);
113113
}
114114
else
115115
{
116-
response = await CoreRunScript(codeScript, options);
116+
response = await CoreRunScript(codeScript, options, cancellationToken);
117117
}
118118

119119
_logger.LogWarning($"End running python code script in {Provider}: {scriptName}");
@@ -134,11 +134,11 @@ private async Task<CodeInterpretResponse> InnerRunCode(string codeScript, CodeIn
134134
}
135135
}
136136

137-
private async Task<CodeInterpretResponse> CoreRunScript(string codeScript, CodeInterpretOptions? options = null)
137+
private async Task<CodeInterpretResponse> CoreRunScript(string codeScript, CodeInterpretOptions? options = null, CancellationToken? cancellationToken = null)
138138
{
139139
_logger.LogWarning($"Begin {nameof(CoreRunScript)} in {Provider}: ${options?.ScriptName}");
140140

141-
var token = options?.OperationToken ?? CancellationToken.None;
141+
var token = cancellationToken ?? CancellationToken.None;
142142
token.ThrowIfCancellationRequested();
143143

144144
using (Py.GIL())
@@ -210,9 +210,9 @@ private async Task<CodeInterpretResponse> CoreRunScript(string codeScript, CodeI
210210
}
211211

212212

213-
private async Task<CodeInterpretResponse> CoreRunProcess(string codeScript, CodeInterpretOptions? options = null)
213+
private async Task<CodeInterpretResponse> CoreRunProcess(string codeScript, CodeInterpretOptions? options = null, CancellationToken? cancellationToken = null)
214214
{
215-
var token = options?.OperationToken ?? CancellationToken.None;
215+
var token = cancellationToken ?? CancellationToken.None;
216216

217217
var psi = new ProcessStartInfo
218218
{

0 commit comments

Comments
 (0)