Skip to content

Commit 0420d7f

Browse files
authored
Merge pull request #535 from Qtoss-AI/master
EnumHelper.cs
2 parents 9573ffc + 628c94e commit 0420d7f

File tree

13 files changed

+79
-36
lines changed

13 files changed

+79
-36
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public interface IBotSharpPlugin
2121
/// <summary>
2222
/// Has build-in agent profile with this plugin
2323
/// </summary>
24-
string[] AgentIds => new string[0];
24+
string[] AgentIds => [];
2525

2626
void RegisterDI(IServiceCollection services, IConfiguration config);
2727

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.ComponentModel;
2+
using System.Reflection;
3+
4+
namespace BotSharp.Abstraction.Utilities;
5+
6+
public static class EnumHelper
7+
{
8+
public static string GetDescription(Enum value)
9+
{
10+
FieldInfo fi = value.GetType().GetField(value.ToString());
11+
DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
12+
13+
if (attributes != null && attributes.Length > 0)
14+
return attributes[0].Description;
15+
else
16+
return value.ToString();
17+
}
18+
}

src/Infrastructure/BotSharp.Abstraction/VectorStorage/IVectorDb.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ public interface IVectorDb
44
{
55
Task<List<string>> GetCollections();
66
Task CreateCollection(string collectionName, int dim);
7-
Task Upsert(string collectionName, int id, float[] vector, string text);
7+
Task Upsert(string collectionName, string id, float[] vector, string text, Dictionary<string, string>? payload = null);
88
Task<List<string>> Search(string collectionName, float[] vector, int limit = 5);
99
}

src/Infrastructure/BotSharp.Core/Routing/Handlers/RouteToAgentRoutingHandler.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ await hook.OnNewTaskDetected(message, inst.NextActionReason)
5757
}
5858

5959
message.FunctionArgs = JsonSerializer.Serialize(inst);
60-
var ret = await routing.InvokeFunction(message.FunctionName, message);
60+
if (message.FunctionName != null)
61+
{
62+
var ret = await routing.InvokeFunction(message.FunctionName, message);
63+
}
6164

6265
var agentId = routing.Context.GetCurrentAgentId();
6366

@@ -82,7 +85,7 @@ await hook.OnNewTaskDetected(message, inst.NextActionReason)
8285
}
8386
else
8487
{
85-
ret = await routing.InvokeAgent(agentId, _dialogs, onFunctionExecuting);
88+
var ret = await routing.InvokeAgent(agentId, _dialogs, onFunctionExecuting);
8689
}
8790

8891
var response = _dialogs.Last();

src/Plugins/BotSharp.Plugin.KnowledgeBase/MemVecDb/MemVectorDatabase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public async Task<List<string>> Search(string collectionName, float[] vector, in
3737
return texts;
3838
}
3939

40-
public async Task Upsert(string collectionName, int id, float[] vector, string text)
40+
public async Task Upsert(string collectionName, string id, float[] vector, string text, Dictionary<string, string>? payload = null)
4141
{
4242
_vectors[collectionName].Add(new VecRecord
4343
{

src/Plugins/BotSharp.Plugin.KnowledgeBase/MemVecDb/VecRecord.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ namespace BotSharp.Plugin.KnowledgeBase.MemVecDb;
22

33
public class VecRecord
44
{
5-
public int Id { get; set; }
5+
public string Id { get; set; }
66
public float[] Vector { get; set; }
77
public string Text { get; set; }
88

src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/KnowledgeService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public async Task EmbedKnowledge(KnowledgeCreationModel knowledge)
3232
foreach (var line in lines)
3333
{
3434
var vec = await textEmbedding.GetVectorAsync(line);
35-
await db.Upsert("shared", idStart, vec, line);
35+
await db.Upsert("shared", idStart.ToString(), vec, line);
3636
idStart++;
3737
Console.WriteLine($"Saved vector {idStart}/{lines.Count}: {line}\n");
3838
}
@@ -55,7 +55,7 @@ public async Task Feed(KnowledgeFeedModel knowledge)
5555
foreach (var line in lines)
5656
{
5757
var vec = await textEmbedding.GetVectorAsync(line);
58-
await db.Upsert(knowledge.AgentId, idStart, vec, line);
58+
await db.Upsert(knowledge.AgentId, idStart.ToString(), vec, line);
5959
idStart++;
6060
Console.WriteLine($"Saved vector {idStart}/{lines.Count}: {line}\n");
6161
}

src/Plugins/BotSharp.Plugin.Qdrant/BotSharp.Plugin.Qdrant.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
</PropertyGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="Aspire.Qdrant.Client" Version="8.0.1" />
15-
<PackageReference Include="Qdrant.Client" Version="1.9.0" />
14+
<PackageReference Include="Qdrant.Client" Version="1.10.0" />
1615
</ItemGroup>
1716

1817
<ItemGroup>

src/Plugins/BotSharp.Plugin.Qdrant/QdrantDb.cs

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ private QdrantClient GetClient()
3232
_client = new QdrantClient
3333
(
3434
host: _setting.Url,
35+
https: true,
3536
apiKey: _setting.ApiKey
3637
);
3738
}
@@ -41,7 +42,7 @@ private QdrantClient GetClient()
4142
public async Task<List<string>> GetCollections()
4243
{
4344
// List all the collections
44-
var collections = await _client.ListCollectionsAsync();
45+
var collections = await GetClient().ListCollectionsAsync();
4546
return collections.ToList();
4647
}
4748

@@ -56,11 +57,6 @@ public async Task CreateCollection(string collectionName, int dim)
5657
Size = (ulong)dim,
5758
Distance = Distance.Cosine
5859
});
59-
60-
var agentService = _services.GetRequiredService<IAgentService>();
61-
var agentDataDir = agentService.GetAgentDataDir(collectionName);
62-
var knowledgePath = Path.Combine(agentDataDir, "knowledge.txt");
63-
File.WriteAllLines(knowledgePath, new string[0]);
6460
}
6561

6662
// Get collection info
@@ -71,26 +67,29 @@ public async Task CreateCollection(string collectionName, int dim)
7167
}
7268
}
7369

74-
public async Task Upsert(string collectionName, int id, float[] vector, string text)
70+
public async Task Upsert(string collectionName, string id, float[] vector, string text, Dictionary<string, string>? payload = null)
7571
{
7672
// Insert vectors
77-
await GetClient().UpsertAsync(collectionName, points: new List<PointStruct>
73+
var point = new PointStruct()
7874
{
79-
new PointStruct()
75+
Id = new PointId()
8076
{
81-
Id = new PointId()
82-
{
83-
Num = (ulong)id,
84-
},
85-
Vectors = vector
86-
}
87-
});
77+
Uuid = id
78+
},
79+
Vectors = vector,
8880

89-
// Store chunks in local file system
90-
var agentService = _services.GetRequiredService<IAgentService>();
91-
var agentDataDir = agentService.GetAgentDataDir(collectionName);
92-
var knowledgePath = Path.Combine(agentDataDir, "knowledge.txt");
93-
File.AppendAllLines(knowledgePath, new[] { text });
81+
Payload = { }
82+
};
83+
84+
foreach (var item in payload)
85+
{
86+
point.Payload.Add(item.Key, item.Value);
87+
}
88+
89+
var result = await GetClient().UpsertAsync(collectionName, points: new List<PointStruct>
90+
{
91+
point
92+
});
9493
}
9594

9695
public async Task<List<string>> Search(string collectionName, float[] vector, int limit = 5)

src/Plugins/BotSharp.Plugin.WebDriver/BotSharp.Plugin.WebDriver.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
</ItemGroup>
1818

1919
<ItemGroup>
20-
<PackageReference Include="Microsoft.Playwright" Version="1.44.0" />
21-
<PackageReference Include="Selenium.WebDriver" Version="4.21.0" />
20+
<PackageReference Include="Microsoft.Playwright" Version="1.45.0" />
21+
<PackageReference Include="Selenium.WebDriver" Version="4.22.0" />
2222
<PackageReference Include="HtmlAgilityPack" Version="1.11.61" />
2323
</ItemGroup>
2424

0 commit comments

Comments
 (0)