mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-02-12 06:41:37 +00:00
Some checks failed
Build and Release / Read metadata (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg updater) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis updater) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage deb updater) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg updater) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis updater) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage deb updater) (push) Has been cancelled
Build and Release / Prepare & create release (push) Has been cancelled
Build and Release / Publish release (push) Has been cancelled
66 lines
2.2 KiB
C#
66 lines
2.2 KiB
C#
using Qdrant.Client;
|
|
using Qdrant.Client.Grpc;
|
|
using AIStudio.Tools.PluginSystem;
|
|
|
|
namespace AIStudio.Tools.Databases.Qdrant;
|
|
|
|
public class QdrantClientImplementation : DatabaseClient
|
|
{
|
|
private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(QdrantClientImplementation).Namespace, nameof(QdrantClientImplementation));
|
|
|
|
private int HttpPort { get; }
|
|
|
|
private int GrpcPort { get; }
|
|
|
|
private QdrantClient GrpcClient { get; }
|
|
|
|
private string Fingerprint { get; }
|
|
|
|
private string ApiToken { get; }
|
|
|
|
public QdrantClientImplementation(string name, string path, int httpPort, int grpcPort, string fingerprint, string apiToken): base(name, path)
|
|
{
|
|
this.HttpPort = httpPort;
|
|
this.GrpcPort = grpcPort;
|
|
this.Fingerprint = fingerprint;
|
|
this.ApiToken = apiToken;
|
|
this.GrpcClient = this.CreateQdrantClient();
|
|
}
|
|
|
|
private const string IP_ADDRESS = "localhost";
|
|
|
|
private QdrantClient CreateQdrantClient()
|
|
{
|
|
var address = "https://" + IP_ADDRESS + ":" + this.GrpcPort;
|
|
var channel = QdrantChannel.ForAddress(address, new ClientConfiguration
|
|
{
|
|
ApiKey = this.ApiToken,
|
|
CertificateThumbprint = this.Fingerprint
|
|
});
|
|
var grpcClient = new QdrantGrpcClient(channel);
|
|
return new QdrantClient(grpcClient);
|
|
}
|
|
|
|
private async Task<string> GetVersion()
|
|
{
|
|
var operation = await this.GrpcClient.HealthAsync();
|
|
return "v"+operation.Version;
|
|
}
|
|
|
|
private async Task<string> GetCollectionsAmount()
|
|
{
|
|
var operation = await this.GrpcClient.ListCollectionsAsync();
|
|
return operation.Count.ToString();
|
|
}
|
|
|
|
public override async IAsyncEnumerable<(string Label, string Value)> GetDisplayInfo()
|
|
{
|
|
yield return (TB("HTTP port"), this.HttpPort.ToString());
|
|
yield return (TB("gRPC port"), this.GrpcPort.ToString());
|
|
yield return (TB("Reported version"), await this.GetVersion());
|
|
yield return (TB("Storage size"), $"{this.GetStorageSize()}");
|
|
yield return (TB("Number of collections"), await this.GetCollectionsAmount());
|
|
}
|
|
|
|
public override void Dispose() => this.GrpcClient.Dispose();
|
|
} |