Skip to content

Commit 4c6c035

Browse files
committed
Plugin IconUrl.
1 parent 0eb9745 commit 4c6c035

File tree

29 files changed

+133
-152
lines changed

29 files changed

+133
-152
lines changed

Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<Project>
22
<PropertyGroup>
3+
<TargetFramework>net6.0</TargetFramework>
34
<LangVersion>10.0</LangVersion>
45
<OutputPath>..\..\..\packages</OutputPath>
56
<BotSharpVersion>0.20.0</BotSharpVersion>

src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentLlmConfig.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ namespace BotSharp.Abstraction.Agents.Models;
22

33
public class AgentLlmConfig
44
{
5+
/// <summary>
6+
/// Is inherited from default Agent Settings
7+
/// </summary>
8+
[JsonPropertyName("is_inherit")]
9+
public bool IsInherit { get; set; }
10+
511
/// <summary>
612
/// Completion Provider
713
/// </summary>

src/Infrastructure/BotSharp.Abstraction/Plugins/IBotSharpPlugin.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ public interface IBotSharpPlugin
77
{
88
string Name => "";
99
string Description => "";
10+
string IconUrl => "https://avatars.githubusercontent.com/u/44989469?s=200&v=4";
1011
void RegisterDI(IServiceCollection services, IConfiguration config);
1112
}

src/Infrastructure/BotSharp.Abstraction/Plugins/Models/PluginDef.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ public class PluginDef
66
public string Name { get; set; }
77
public string Description { get; set; }
88
public string Assembly { get; set; }
9+
[JsonPropertyName("icon_url")]
10+
public string IconUrl { get; set; }
911
}

src/Infrastructure/BotSharp.Abstraction/Repositories/Filters/ConversationFilter.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ namespace BotSharp.Abstraction.Repositories.Filters;
33
public class ConversationFilter
44
{
55
public Pagination Pager { get; set; } = new Pagination();
6+
/// <summary>
7+
/// Conversation Id
8+
/// </summary>
9+
public string? Id { get; set; }
610
public string? AgentId { get; set; }
711
public string? Status { get; set; }
812
public string? Channel { get; set; }

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,15 @@ public async Task<Agent> GetAgent(string id)
2626
{
2727
_logger.LogError($"Can't find agent {id}");
2828
return null;
29-
};
29+
}
30+
31+
// Load llm config
32+
var agentSetting = _services.GetRequiredService<AgentSettings>();
33+
if (profile.LlmConfig == null)
34+
{
35+
profile.LlmConfig = agentSetting.LlmConfig;
36+
profile.LlmConfig.IsInherit = true;
37+
}
3038

3139
return profile;
3240
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ public async Task UpdateAgent(Agent agent, AgentField updateField)
2727
record.Templates = agent.Templates ?? new List<AgentTemplate>();
2828
record.Responses = agent.Responses ?? new List<AgentResponse>();
2929
record.Samples = agent.Samples ?? new List<string>();
30-
record.LlmConfig = agent.LlmConfig;
30+
if (!agent.LlmConfig.IsInherit)
31+
{
32+
record.LlmConfig = agent.LlmConfig;
33+
}
3134

3235
_db.UpdateAgent(record, updateField);
3336
await Task.CompletedTask;

src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ public List<RoleDialogModel> GetDialogHistory(int lastCount = 50)
112112

113113
var dialogs = _storage.GetDialogs(_conversationId);
114114
return dialogs
115-
.Where(x => x.CreatedAt > DateTime.UtcNow.AddHours(-24))
116115
.TakeLast(lastCount)
117116
.ToList();
118117
}

src/Infrastructure/BotSharp.Core/Plugins/PluginLoader.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ public void Load(Action<Assembly> loaded)
5454
Id = module.GetType().FullName,
5555
Name = name,
5656
Description = module.Description,
57-
Assembly = assemblyName
57+
Assembly = assemblyName,
58+
IconUrl = module.IconUrl
5859
});
5960
Console.Write($"Loaded plugin ");
6061
Console.Write(name, Color.Green);
Lines changed: 7 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
using BotSharp.Abstraction.Agents.Models;
2+
using BotSharp.Abstraction.Functions.Models;
3+
14
namespace BotSharp.OpenAPI.Controllers;
25

36
[Authorize]
@@ -46,115 +49,19 @@ public async Task UpdateAgentFromFile([FromRoute] string agentId)
4649
await _agentService.UpdateAgentFromFile(agentId);
4750
}
4851

49-
[HttpPut("/agent/{agentId}/all")]
52+
[HttpPut("/agent/{agentId}")]
5053
public async Task UpdateAgent([FromRoute] string agentId, [FromBody] AgentUpdateModel agent)
5154
{
5255
var model = agent.ToAgent();
5356
model.Id = agentId;
5457
await _agentService.UpdateAgent(model, AgentField.All);
5558
}
5659

57-
[HttpPut("/agent/{agentId}/name")]
58-
public async Task UpdateAgentName([FromRoute] string agentId, [FromBody] AgentUpdateModel agent)
59-
{
60-
var model = agent.ToAgent();
61-
model.Id = agentId;
62-
await _agentService.UpdateAgent(model, AgentField.Name);
63-
}
64-
65-
[HttpPut("/agent/{agentId}/description")]
66-
public async Task UpdateAgentDescription([FromRoute] string agentId, [FromBody] AgentUpdateModel agent)
67-
{
68-
var model = agent.ToAgent();
69-
model.Id = agentId;
70-
await _agentService.UpdateAgent(model, AgentField.Description);
71-
}
72-
73-
[HttpPut("/agent/{agentId}/is-public")]
74-
public async Task UpdateAgentIsPublic([FromRoute] string agentId, [FromBody] AgentUpdateModel agent)
75-
{
76-
var model = agent.ToAgent();
77-
model.Id = agentId;
78-
await _agentService.UpdateAgent(model, AgentField.IsPublic);
79-
}
80-
81-
[HttpPut("/agent/{agentId}/disabled")]
82-
public async Task UpdateAgentDisabled([FromRoute] string agentId, [FromBody] AgentUpdateModel agent)
83-
{
84-
var model = agent.ToAgent();
85-
model.Id = agentId;
86-
await _agentService.UpdateAgent(model, AgentField.Disabled);
87-
}
88-
89-
[HttpPut("/agent/{agentId}/allow-routing")]
90-
public async Task UpdateAgentAllowRouting([FromRoute] string agentId, [FromBody] AgentUpdateModel agent)
91-
{
92-
var model = agent.ToAgent();
93-
model.Id = agentId;
94-
await _agentService.UpdateAgent(model, AgentField.AllowRouting);
95-
}
96-
97-
[HttpPut("/agent/{agentId}/profiles")]
98-
public async Task UpdateAgentProfiles([FromRoute] string agentId, [FromBody] AgentUpdateModel agent)
99-
{
100-
var model = agent.ToAgent();
101-
model.Id = agentId;
102-
await _agentService.UpdateAgent(model, AgentField.Profiles);
103-
}
104-
105-
[HttpPut("/agent/{agentId}/routing-rules")]
106-
public async Task UpdateAgentRoutingRules([FromRoute] string agentId, [FromBody] AgentUpdateModel agent)
107-
{
108-
var model = agent.ToAgent();
109-
model.Id = agentId;
110-
await _agentService.UpdateAgent(model, AgentField.RoutingRule);
111-
}
112-
113-
[HttpPut("/agent/{agentId}/instruction")]
114-
public async Task UpdateAgentInstruction([FromRoute] string agentId, [FromBody] AgentUpdateModel agent)
115-
{
116-
var model = agent.ToAgent();
117-
model.Id = agentId;
118-
await _agentService.UpdateAgent(model, AgentField.Instruction);
119-
}
120-
121-
[HttpPut("/agent/{agentId}/functions")]
122-
public async Task UpdateAgentFunctions([FromRoute] string agentId, [FromBody] AgentUpdateModel agent)
123-
{
124-
var model = agent.ToAgent();
125-
model.Id = agentId;
126-
await _agentService.UpdateAgent(model, AgentField.Function);
127-
}
128-
129-
[HttpPut("/agent/{agentId}/templates")]
130-
public async Task UpdateAgentTemplates([FromRoute] string agentId, [FromBody] AgentUpdateModel agent)
131-
{
132-
var model = agent.ToAgent();
133-
model.Id = agentId;
134-
await _agentService.UpdateAgent(model, AgentField.Template);
135-
}
136-
137-
[HttpPut("/agent/{agentId}/responses")]
138-
public async Task UpdateAgentResponses([FromRoute] string agentId, [FromBody] AgentUpdateModel agent)
139-
{
140-
var model = agent.ToAgent();
141-
model.Id = agentId;
142-
await _agentService.UpdateAgent(model, AgentField.Response);
143-
}
144-
145-
[HttpPut("/agent/{agentId}/samples")]
146-
public async Task UpdateAgentSamples([FromRoute] string agentId, [FromBody] AgentUpdateModel agent)
147-
{
148-
var model = agent.ToAgent();
149-
model.Id = agentId;
150-
await _agentService.UpdateAgent(model, AgentField.Sample);
151-
}
152-
153-
[HttpPut("/agent/{agentId}/llm-config")]
154-
public async Task UpdateAgentLlmConfig([FromRoute] string agentId, [FromBody] AgentUpdateModel agent)
60+
[HttpPatch("/agent/{agentId}/{field}")]
61+
public async Task PatchAgentByField([FromRoute] string agentId, AgentField field, [FromBody] AgentUpdateModel agent)
15562
{
15663
var model = agent.ToAgent();
15764
model.Id = agentId;
158-
await _agentService.UpdateAgent(model, AgentField.LlmConfig);
65+
await _agentService.UpdateAgent(model, field);
15966
}
16067
}

0 commit comments

Comments
 (0)