forked from SciSharp/BotSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMembasePlugin.cs
More file actions
64 lines (55 loc) · 2.4 KB
/
MembasePlugin.cs
File metadata and controls
64 lines (55 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using BotSharp.Abstraction.Plugins.Models;
using BotSharp.Abstraction.Rules;
using BotSharp.Plugin.Membase.GraphDb;
using BotSharp.Plugin.Membase.Handlers;
using Refit;
namespace BotSharp.Plugin.Membase;
public class MembasePlugin : IBotSharpPlugin
{
public string Id => "8df12767-9a44-45d9-93cd-12a10adf3933";
public string Name => "Membase";
public string Description => "Document Database with Graph Traversal & Vector Search.";
public string IconUrl => "https://www.membase.dev/favicon.png";
private string _membaseCredential = string.Empty;
private string _membaseProjectId = string.Empty;
public void RegisterDI(IServiceCollection services, IConfiguration config)
{
var settings = new MembaseSettings();
config.Bind("Membase", settings);
services.AddSingleton(sp => settings);
services.AddTransient<MembaseAuthHandler>();
services.AddRefitClient<IMembaseApi>(new RefitSettings
{
CollectionFormat = CollectionFormat.Multi
})
.AddHttpMessageHandler<MembaseAuthHandler>()
.ConfigureHttpClient(c =>
{
c.BaseAddress = new Uri(settings.Host);
// Timeout is set by MembaseGrapbDb internally, but we set it here as well to ensure that the Refit client does not timeout before the graph db does.
c.Timeout = TimeSpan.FromSeconds(90);
});
services.AddScoped<IGraphDb, MembaseGraphDb>();
_membaseCredential = config.GetValue<string>("Membase:ApiKey") ?? string.Empty;
_membaseProjectId = config.GetValue<string>("Membase:ProjectId") ?? string.Empty;
#if DEBUG
services.AddScoped<IRuleFlow<RuleGraph>, DemoRuleGraph>();
#endif
}
public bool AttachMenu(List<PluginMenuDef> menu)
{
var section = menu.First(x => x.Label == "Knowledge Base");
section?.SubMenu?.Add(new PluginMenuDef("Relationships", link: "page/knowledge-base/relationships/membase")
{
EmbeddingInfo = new EmbeddingData
{
Source = "membase",
HtmlTag = "iframe",
Url = $"https://console.membase.dev/query-editor/{_membaseProjectId}?token={_membaseCredential}",
HtmlStyle = "width: 100%; height: 90%;",
FullScreen = true
}
});
return true;
}
}