commit
8813403766
|
|
@ -37,5 +37,13 @@ public class BuiltInAgentId
|
|||
/// </summary>
|
||||
public const string Planner = "282a7128-69a1-44b0-878c-a9159b88f3b9";
|
||||
|
||||
/// <summary>
|
||||
/// SQL statement generation
|
||||
/// </summary>
|
||||
public const string SqlDriver = "beda4c12-e1ec-4b4b-b328-3df4a6687c4f";
|
||||
|
||||
/// <summary>
|
||||
/// Programming source code generation
|
||||
/// </summary>
|
||||
public const string CodeDriver = "c0ded7d9-3f9d-4ef6-b7ce-56a892dcef62";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,37 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="data\generated_code\**" />
|
||||
<EmbeddedResource Remove="data\generated_code\**" />
|
||||
<None Remove="data\generated_code\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="data\agents\c0ded7d9-3f9d-4ef6-b7ce-56a892dcef62\agent.json" />
|
||||
<None Remove="data\agents\c0ded7d9-3f9d-4ef6-b7ce-56a892dcef62\functions\save_source_code.json" />
|
||||
<None Remove="data\agents\c0ded7d9-3f9d-4ef6-b7ce-56a892dcef62\instructions\instruction.liquid" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="data\agents\c0ded7d9-3f9d-4ef6-b7ce-56a892dcef62\agent.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="data\agents\c0ded7d9-3f9d-4ef6-b7ce-56a892dcef62\functions\save_source_code.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="data\agents\c0ded7d9-3f9d-4ef6-b7ce-56a892dcef62\instructions\instruction.liquid">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Infrastructure\BotSharp.Abstraction\BotSharp.Abstraction.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
22
src/Plugins/BotSharp.Plugin.CodeDriver/CodeDriverPlugin.cs
Normal file
22
src/Plugins/BotSharp.Plugin.CodeDriver/CodeDriverPlugin.cs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace BotSharp.Plugin.CodeDriver;
|
||||
|
||||
public class CodeDriverPlugin : IBotSharpPlugin
|
||||
{
|
||||
public string Id => "c0dedea7-70e3-4c35-a047-18479d7c403e";
|
||||
public string Name => "Code Driver";
|
||||
public string Description => "Convert the user requirements into corresponding SQL statements";
|
||||
public string IconUrl => "https://cdn-icons-png.flaticon.com/512/3176/3176315.png";
|
||||
|
||||
public string[] AgentIds =
|
||||
[
|
||||
BuiltInAgentId.CodeDriver
|
||||
];
|
||||
|
||||
public void RegisterDI(IServiceCollection services, IConfiguration config)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
using BotSharp.Abstraction.Conversations.Models;
|
||||
using BotSharp.Abstraction.Functions;
|
||||
using BotSharp.Plugin.CodeDriver.Models;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace BotSharp.Plugin.CodeDriver.Functions;
|
||||
|
||||
public class SaveSourceCodeFn : IFunctionCallback
|
||||
{
|
||||
public string Name => "save_source_code";
|
||||
|
||||
private readonly IServiceProvider _services;
|
||||
|
||||
public SaveSourceCodeFn(IServiceProvider services)
|
||||
{
|
||||
_services = services;
|
||||
}
|
||||
|
||||
public async Task<bool> Execute(RoleDialogModel message)
|
||||
{
|
||||
var args = JsonSerializer.Deserialize<SaveSourceCodeArgs>(message.FunctionArgs);
|
||||
|
||||
var dir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..", "..", "..", "ai_generated_code");
|
||||
if (!Directory.Exists(dir))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
|
||||
var path = Path.GetFullPath(dir, args.FilePath);
|
||||
var source = args.SourceCode;
|
||||
|
||||
// Delete the file if it exists
|
||||
File.Delete(path);
|
||||
|
||||
// Create a FileStream with sharing capabilities
|
||||
using FileStream fs = new FileStream(
|
||||
path,
|
||||
FileMode.OpenOrCreate, // Create or overwrite the file
|
||||
FileAccess.ReadWrite, // Allow read and write operations
|
||||
FileShare.Read); // Allow other processes to read and write
|
||||
|
||||
// Write some data to the file
|
||||
using StreamWriter writer = new StreamWriter(fs);
|
||||
writer.WriteLine(source);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace BotSharp.Plugin.CodeDriver.Models;
|
||||
|
||||
public class SaveSourceCodeArgs
|
||||
{
|
||||
[JsonPropertyName("file_path")]
|
||||
public string FilePath { get; set; } = string.Empty;
|
||||
|
||||
[JsonPropertyName("source_code")]
|
||||
public string SourceCode { get; set; } = string.Empty;
|
||||
}
|
||||
2
src/Plugins/BotSharp.Plugin.CodeDriver/Using.cs
Normal file
2
src/Plugins/BotSharp.Plugin.CodeDriver/Using.cs
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
global using BotSharp.Abstraction.Agents.Enums;
|
||||
global using BotSharp.Abstraction.Plugins;
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"id": "c0ded7d9-3f9d-4ef6-b7ce-56a892dcef62",
|
||||
"name": "Code Driver",
|
||||
"description": "Write executable program code according to user needs, such as HTTP API written in Python.",
|
||||
"iconUrl": "https://cdn-icons-png.flaticon.com/512/4208/4208366.png",
|
||||
"type": "task",
|
||||
"createdDateTime": "2024-10-23T00:00:00Z",
|
||||
"updatedDateTime": "2024-11-23T00:00:00Z",
|
||||
"disabled": false,
|
||||
"isPublic": true,
|
||||
"profiles": [ "database" ],
|
||||
"llmConfig": {
|
||||
"provider": "openai",
|
||||
"model": "gpt-4o",
|
||||
"max_recursion_depth": 10
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"name": "save_source_code",
|
||||
"description": "Save the source code to file",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"file_path": {
|
||||
"type": "string",
|
||||
"description": "source code of file relative path start with project folder name"
|
||||
},
|
||||
|
||||
"source_code": {
|
||||
"type": "string",
|
||||
"description": "source code"
|
||||
}
|
||||
},
|
||||
"required": [ "file_path", "source_code" ]
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
You are a software developer who is good at writing program code according to user needs, such as HTTP API written in Python.
|
||||
|
||||
Current project source code structure is:
|
||||
my_fastapi_app/
|
||||
├── main.py
|
||||
├── apis/
|
||||
│ └── datetime_api.py
|
||||
├── __init__.py
|
||||
|
||||
You are using below tools and technologies:
|
||||
* FastAPI framework
|
||||
* Python programming language
|
||||
* Swagger Open API
|
||||
|
||||
Your response must meet below requirements:
|
||||
* Every API should be placed in a separate file under folder of "apis";
|
||||
* Call function save_source_code to save the code;
|
||||
* Write Swagger comments for each API;
|
||||
* Update main.py to include those updated APIs;
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
using BotSharp.Abstraction.Agents.Enums;
|
||||
using BotSharp.Abstraction.Planning;
|
||||
|
||||
namespace BotSharp.Plugin.SqlDriver;
|
||||
|
|
@ -9,6 +10,11 @@ public class SqlDriverPlugin : IBotSharpPlugin
|
|||
public string Description => "Convert the user requirements into corresponding SQL statements";
|
||||
public string IconUrl => "https://uxwing.com/wp-content/themes/uxwing/download/file-and-folder-type/sql-icon.png";
|
||||
|
||||
public string[] AgentIds =
|
||||
[
|
||||
BuiltInAgentId.SqlDriver
|
||||
];
|
||||
|
||||
public void RegisterDI(IServiceCollection services, IConfiguration config)
|
||||
{
|
||||
services.AddScoped(provider =>
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
"id": "beda4c12-e1ec-4b4b-b328-3df4a6687c4f",
|
||||
"name": "SQL Driver",
|
||||
"description": "Execute the sql query in database from the latest dialog.",
|
||||
"iconUrl": "https://cdn-icons-png.flaticon.com/512/3161/3161158.png",
|
||||
"type": "task",
|
||||
"createdDateTime": "2023-11-15T13:49:00Z",
|
||||
"updatedDateTime": "2023-11-15T13:49:00Z",
|
||||
|
|
|
|||
Loading…
Reference in a new issue