-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileOperationPlugin.cs
More file actions
39 lines (33 loc) · 1.58 KB
/
FileOperationPlugin.cs
File metadata and controls
39 lines (33 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System.ComponentModel;
using Microsoft.SemanticKernel;
namespace SolBro
{
public class FileOperationPlugin
{
private const string OutputDir = "generated_files";
[KernelFunction("create_file")]
[Description("Creates a file with the given content and returns the file path. Use this when a user asks you to create, write, edit, or generate a document/file. Supported formats: .txt, .csv, .json, .xml, .md, .html, .py, .cs, .js, .ts, .sql, .yml, .yaml")]
public async Task<string> CreateFileAsync(
[Description("The filename with extension, e.g. 'players.csv' or 'report.txt'")] string filename,
[Description("The full text content to write to the file")] string content)
{
try
{
filename = Path.GetFileName(filename);
if (string.IsNullOrWhiteSpace(filename))
return "Error: Invalid filename.";
Directory.CreateDirectory(OutputDir);
var uniqueName = $"{Guid.NewGuid():N}_{filename}";
var filePath = Path.Combine(OutputDir, uniqueName);
await File.WriteAllTextAsync(filePath, content);
Console.WriteLine($"[FilePlugin] Created file: {filePath} ({content.Length} chars)");
return $"GENERATED_FILE:{filePath}|FILENAME:{filename}";
}
catch (Exception ex)
{
Console.WriteLine($"[FilePlugin] Error creating file: {ex.Message}");
return $"Error creating file: {ex.Message}";
}
}
}
}