Skip to content

Commit 780bb4e

Browse files
author
Wenbo Cao
committed
Add PaddleOcrConverter
2 parents 14d9066 + 7e95be0 commit 780bb4e

19 files changed

+164
-77
lines changed

docs/llm/prompt.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Prompt Engineering
22

3-
LLM uses prompt as input, and the model produces different outputs according to the input.
3+
LLM uses prompt as input, and the model produces different outputs according to the input.

docs/llm/template.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
# Template
22

3-
We can define the prompt as a template, and the template can be changed according to variables, so that a instruction file can be used to generate a dynamic prompt.
3+
We can define the prompt as a template, and the template can be changed according to variables, so that a instruction file can be used to generate a dynamic prompt.
4+
`BotSharp` uses [liquid](https://shopify.github.io/liquid/) templates to support various complex dynamic prompt engineering.
5+
6+
`ITemplateRender`
7+
```csharp
8+
bool Render(Agent agent, Dictionary<string, object> dict)
9+
```

src/Infrastructure/BotSharp.Abstraction/Agents/IAgentRouting.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ public interface IAgentRouting
44
{
55
Task<Agent> LoadRouter();
66
Task<Agent> LoadCurrentAgent();
7+
RoutingRecord[] GetRoutingRecords();
78
}

src/Infrastructure/BotSharp.Abstraction/Agents/Models/RoutingTable.cs renamed to src/Infrastructure/BotSharp.Abstraction/Agents/Models/RoutingRecord.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,25 @@
22

33
namespace BotSharp.Abstraction.Agents.Models;
44

5-
public class RoutingTable
5+
public class RoutingRecord
66
{
77
[JsonPropertyName("agent_id")]
88
public string AgentId { get; set; }
99

1010
[JsonPropertyName("name")]
11-
public string AgentName { get; set; }
11+
public string Name { get; set; }
12+
13+
[JsonPropertyName("description")]
14+
public string Description { get; set; }
1215

1316
[JsonPropertyName("required")]
1417
public List<string> RequiredFields { get; set; }
1518

19+
[JsonPropertyName("redirect_to")]
20+
public string RedirectTo { get; set; }
21+
1622
public override string ToString()
1723
{
18-
return AgentName;
24+
return Name;
1925
}
2026
}

src/Infrastructure/BotSharp.Abstraction/Agents/Settings/AgentSettings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ public class AgentSettings
88
public string RouterId { get; set; }
99
public string DataDir { get; set; }
1010
public string TemplateFormat { get; set; }
11+
public int MaxRecursiveDepth { get; set; } = 3;
1112
}

src/Infrastructure/BotSharp.Abstraction/BotSharp.Abstraction.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFramework>netstandard2.1</TargetFramework>
55
<Nullable>enable</Nullable>
66
<LangVersion>10.0</LangVersion>
7-
<VersionPrefix>0.9.0</VersionPrefix>
7+
<VersionPrefix>0.9.4</VersionPrefix>
88
<PackageIcon>Icon.png</PackageIcon>
99
</PropertyGroup>
1010

src/Infrastructure/BotSharp.Abstraction/Functions/Models/FunctionExecutionValidationResult.cs

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace BotSharp.Abstraction.Templating;
2+
3+
public interface ITemplateRender
4+
{
5+
bool Render(Agent agent, Dictionary<string, object> dict);
6+
}

src/Infrastructure/BotSharp.Core/Agents/Services/AgentHookBase.cs

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
using BotSharp.Abstraction.Agents.Models;
2-
using Fluid;
32

43
namespace BotSharp.Core.Agents.Services;
54

65
public abstract class AgentHookBase : IAgentHook
76
{
87
protected Agent _agent;
98
public Agent Agent => _agent;
10-
private static readonly FluidParser _parser = new FluidParser();
119

12-
private readonly IServiceProvider _services;
10+
protected readonly IServiceProvider _services;
11+
protected readonly AgentSettings _settings;
1312

14-
public AgentHookBase(IServiceProvider services)
13+
public AgentHookBase(IServiceProvider services, AgentSettings settings)
1514
{
1615
_services = services;
16+
_settings = settings;
1717
}
1818

1919
public void SetAget(Agent agent)
@@ -28,27 +28,7 @@ public virtual bool OnAgentLoading(ref string id)
2828

2929
public virtual bool OnInstructionLoaded(string template, Dictionary<string, object> dict)
3030
{
31-
if (_parser.TryParse(template, out var t, out var error))
32-
{
33-
PopulateStateTokens(dict);
34-
var context = new TemplateContext(dict);
35-
_agent.Instruction = t.Render(context);
36-
return true;
37-
}
38-
else
39-
{
40-
return false;
41-
}
42-
}
43-
44-
private void PopulateStateTokens(Dictionary<string, object> dict)
45-
{
46-
var stateService = _services.GetRequiredService<IConversationStateService>();
47-
var state = stateService.Load();
48-
foreach (var t in state)
49-
{
50-
dict[t.Key] = t.Value;
51-
}
31+
return true;
5232
}
5333

5434
public virtual bool OnFunctionsLoaded(ref string functions)

src/Infrastructure/BotSharp.Core/Agents/Services/AgentRouter.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using BotSharp.Abstraction.Agents;
21
using BotSharp.Abstraction.Agents.Models;
2+
using System.IO;
33

44
namespace BotSharp.Core.Agents.Services;
55

@@ -42,4 +42,12 @@ public async Task<Agent> LoadCurrentAgent()
4242

4343
return agent;
4444
}
45+
46+
public RoutingRecord[] GetRoutingRecords()
47+
{
48+
var agentSettings = _services.GetRequiredService<AgentSettings>();
49+
var dbSettings = _services.GetRequiredService<MyDatabaseSettings>();
50+
var filePath = Path.Combine(dbSettings.FileRepository, agentSettings.DataDir, agentSettings.RouterId, "route.json");
51+
return JsonSerializer.Deserialize<RoutingRecord[]>(File.ReadAllText(filePath));
52+
}
4553
}

0 commit comments

Comments
 (0)