add arguments in options

This commit is contained in:
Jicheng Lu 2025-09-30 16:03:58 -05:00
parent 1be9ffebaa
commit 75d0cf1ae1
8 changed files with 15 additions and 10 deletions

View file

@ -4,4 +4,5 @@ public class CodeInstructOptions
{
public string? CodeScriptName { get; set; }
public string? CodeInterpretProvider { get; set; }
public List<KeyValue>? Arguments { get; set; }
}

View file

@ -112,7 +112,7 @@ public interface IBotSharpRepository : IHaveServiceProvider
string? GetAgentCodeScript(string agentId, string scriptName)
=> throw new NotImplementedException();
bool UpdateAgentCodeScript(string agentId, AgentCodeScript script)
bool PatchAgentCodeScript(string agentId, AgentCodeScript script)
=> throw new NotImplementedException();
#endregion

View file

@ -56,9 +56,7 @@ public partial class InstructService
var db = _services.GetRequiredService<IBotSharpRepository>();
var state = _services.GetRequiredService<IConversationStateService>();
var arguments = state.GetStates().Select(x => new KeyValue(x.Key, x.Value));
var codeScript = db.GetAgentCodeScript(agentId, codeOptions.CodeScriptName);
if (string.IsNullOrWhiteSpace(codeScript))
{
var error = $"Empty code script. (Agent: {agentId}, Code script: {codeOptions.CodeScriptName})";
@ -67,7 +65,7 @@ public partial class InstructService
}
else
{
var result = await codeInterpreter.RunCode(codeScript, arguments);
var result = await codeInterpreter.RunCode(codeScript, codeOptions.Arguments);
response.Text = result?.Result?.ToString();
}
}

View file

@ -547,6 +547,12 @@ namespace BotSharp.Core.Repository
public string GetAgentTemplate(string agentId, string templateName)
{
if (string.IsNullOrWhiteSpace(agentId)
|| string.IsNullOrWhiteSpace(templateName))
{
return string.Empty;
}
var dir = Path.Combine(_dbSettings.FileRepository, _agentSettings.DataDir, agentId, AGENT_TEMPLATES_FOLDER);
if (!Directory.Exists(dir)) return string.Empty;

View file

@ -13,7 +13,7 @@ public partial class FileRepository
return null;
}
var dir = Path.Combine(_dbSettings.FileRepository, _agentSettings.DataDir, agentId, AGENT_CODE_FOLDER);
var dir = Path.Combine(_dbSettings.FileRepository, _agentSettings.DataDir, agentId, AGENT_CODES_FOLDER);
if (!Directory.Exists(dir))
{
return null;
@ -30,14 +30,14 @@ public partial class FileRepository
return string.Empty;
}
public bool UpdateAgentCodeScript(string agentId, AgentCodeScript script)
public bool PatchAgentCodeScript(string agentId, AgentCodeScript script)
{
if (string.IsNullOrEmpty(agentId) || script == null)
{
return false;
}
var dir = Path.Combine(_dbSettings.FileRepository, _agentSettings.DataDir, agentId, AGENT_CODE_FOLDER);
var dir = Path.Combine(_dbSettings.FileRepository, _agentSettings.DataDir, agentId, AGENT_CODES_FOLDER);
if (!Directory.Exists(dir))
{
return false;

View file

@ -26,7 +26,7 @@ public partial class FileRepository : IBotSharpRepository
private const string AGENT_FUNCTIONS_FOLDER = "functions";
private const string AGENT_TEMPLATES_FOLDER = "templates";
private const string AGENT_RESPONSES_FOLDER = "responses";
private const string AGENT_CODE_FOLDER = "codes";
private const string AGENT_CODES_FOLDER = "codes";
private const string AGENT_TASKS_FOLDER = "tasks";
private const string AGENT_TASK_PREFIX = "#metadata";
private const string AGENT_TASK_SUFFIX = "/metadata";

View file

@ -37,7 +37,7 @@ public class InstructModeController : ControllerBase
var result = await instructor.Execute(agentId,
new RoleDialogModel(AgentRole.User, input.Text),
instruction: input.Instruction,
llmTemplateName: input.Template,
templateName: input.Template,
files: input.Files,
codeOptions: input.CodeOptions);

View file

@ -79,7 +79,7 @@ public class PyInterpretService : ICodeInterpretService
}
catch (Exception ex)
{
var errorMsg = $"Error when executing python code in {nameof(PyInterpretService)}-{Provider}. {ex.Message}";
var errorMsg = $"Error when executing python code in {nameof(PyInterpretService)}: {Provider}. {ex.Message}";
_logger.LogError(ex, errorMsg);
return new CodeInterpretResult