Skip to content

Commit e6e0192

Browse files
author
Jicheng Lu
committed
refine update agent in file repository
1 parent feb884d commit e6e0192

File tree

4 files changed

+213
-51
lines changed

4 files changed

+213
-51
lines changed

src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.CreateAgent.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ private Agent FetchAgentFileByName(string agentName, string filePath)
8484

8585
private string FetchInstructionFromFile(string fileDir)
8686
{
87-
var file = Path.Combine(fileDir, "instruction.liquid");
87+
var file = Path.Combine(fileDir, $"instruction.{_agentSettings.TemplateFormat}");
8888
if (!File.Exists(file)) return null;
8989

9090
var instruction = File.ReadAllText(file);
@@ -100,7 +100,7 @@ private List<AgentTemplate> FetchTemplatesFromFile(string fileDir)
100100
var splits = fileName.ToLower().Split('.');
101101
var name = splits[0];
102102
var extension = splits[1];
103-
if (name != "instruction" && extension == "liquid")
103+
if (name != "instruction" && extension == _agentSettings.TemplateFormat)
104104
{
105105
var content = File.ReadAllText(file);
106106
templates.Add(new AgentTemplate(name, content));

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@ public partial class AgentService : IAgentService
99
private readonly IBotSharpRepository _db;
1010
private readonly ILogger _logger;
1111
private readonly IUserIdentity _user;
12-
private readonly AgentSettings _settings;
12+
private readonly AgentSettings _agentSettings;
1313
private readonly JsonSerializerOptions _options;
1414

1515
public AgentService(IServiceProvider services,
1616
IBotSharpRepository db,
1717
ILogger<AgentService> logger,
1818
IUserIdentity user,
19-
AgentSettings settings)
19+
AgentSettings agentSettings)
2020
{
2121
_services = services;
2222
_db = db;
2323
_logger = logger;
2424
_user = user;
25-
_settings = settings;
25+
_agentSettings = agentSettings;
2626
_options = new JsonSerializerOptions
2727
{
2828
PropertyNameCaseInsensitive = true,
@@ -40,7 +40,7 @@ public string GetDataDir()
4040
public string GetAgentDataDir(string agentId)
4141
{
4242
var dbSettings = _services.GetRequiredService<BotSharpDatabaseSettings>();
43-
var dir = Path.Combine(dbSettings.FileRepository, _settings.DataDir, agentId);
43+
var dir = Path.Combine(dbSettings.FileRepository, _agentSettings.DataDir, agentId);
4444
if (!Directory.Exists(dir))
4545
{
4646
Directory.CreateDirectory(dir);

src/Infrastructure/BotSharp.Core/Repository/BotSharpDbContext.cs

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using BotSharp.Abstraction.Agents.Enums;
21
using BotSharp.Abstraction.Agents.Models;
32
using BotSharp.Abstraction.Repositories;
43
using BotSharp.Abstraction.Routing.Models;
@@ -72,89 +71,99 @@ public int Transaction<TTableInterface>(Action action)
7271
}
7372

7473

75-
76-
public void CreateNewConversation(Conversation conversation)
74+
#region Agent
75+
public Agent GetAgent(string agentId)
7776
{
7877
throw new NotImplementedException();
7978
}
8079

81-
public List<RoutingItem> CreateRoutingItems(List<RoutingItem> routingItems)
80+
public void UpdateAgent(Agent agent, AgentField field)
8281
{
8382
throw new NotImplementedException();
8483
}
8584

86-
public List<RoutingProfile> CreateRoutingProfiles(List<RoutingProfile> profiles)
85+
public string GetAgentTemplate(string agentId, string templateName)
8786
{
8887
throw new NotImplementedException();
8988
}
9089

91-
public void CreateUser(User user)
90+
public List<string> GetAgentResponses(string agentId, string prefix, string intent)
9291
{
9392
throw new NotImplementedException();
9493
}
94+
#endregion
9595

96-
public void DeleteRoutingItems()
96+
97+
#region Conversation
98+
public void CreateNewConversation(Conversation conversation)
9799
{
98100
throw new NotImplementedException();
99101
}
100102

101-
public void DeleteRoutingProfiles()
103+
public Conversation GetConversation(string conversationId)
102104
{
103105
throw new NotImplementedException();
104106
}
105107

106-
public Agent GetAgent(string agentId)
108+
public List<Conversation> GetConversations(string userId)
107109
{
108110
throw new NotImplementedException();
109111
}
110112

111-
public List<string> GetAgentResponses(string agentId, string prefix, string intent)
113+
public string GetConversationDialog(string conversationId)
112114
{
113115
throw new NotImplementedException();
114116
}
115117

116-
public Conversation GetConversation(string conversationId)
118+
public List<StateKeyValue> GetConversationStates(string conversationId)
117119
{
118120
throw new NotImplementedException();
119121
}
120122

121-
public string GetConversationDialog(string conversationId)
123+
public void UpdateConversationDialog(string conversationId, string dialogs)
122124
{
123125
throw new NotImplementedException();
124126
}
125127

126-
public List<Conversation> GetConversations(string userId)
128+
public void UpdateConversationStates(string conversationId, List<StateKeyValue> states)
127129
{
128130
throw new NotImplementedException();
129131
}
132+
#endregion
130133

131-
public List<StateKeyValue> GetConversationStates(string conversationId)
134+
135+
#region User
136+
public User GetUserByEmail(string email)
132137
{
133138
throw new NotImplementedException();
134139
}
135140

136-
public User GetUserByEmail(string email)
141+
public void CreateUser(User user)
137142
{
138143
throw new NotImplementedException();
139144
}
145+
#endregion
140146

141-
public void UpdateAgent(Agent agent, AgentField field)
147+
148+
#region Routing
149+
public List<RoutingItem> CreateRoutingItems(List<RoutingItem> routingItems)
142150
{
143151
throw new NotImplementedException();
144152
}
145153

146-
public void UpdateConversationDialog(string conversationId, string dialogs)
154+
public List<RoutingProfile> CreateRoutingProfiles(List<RoutingProfile> profiles)
147155
{
148156
throw new NotImplementedException();
149157
}
150158

151-
public void UpdateConversationStates(string conversationId, List<StateKeyValue> states)
159+
public void DeleteRoutingItems()
152160
{
153161
throw new NotImplementedException();
154162
}
155163

156-
public string GetAgentTemplate(string agentId, string templateName)
164+
public void DeleteRoutingProfiles()
157165
{
158166
throw new NotImplementedException();
159167
}
168+
#endregion
160169
}

0 commit comments

Comments
 (0)