ai.muna.muna 0.0.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Editor/Build/AndroidBuildHandler.cs +96 -0
- package/Editor/Build/AndroidBuildHandler.cs.meta +11 -0
- package/Editor/Build/BuildHandler.cs +128 -0
- package/Editor/Build/BuildHandler.cs.meta +11 -0
- package/Editor/Build/LinuxBuildHandler.cs +26 -0
- package/Editor/Build/LinuxBuildHandler.cs.meta +11 -0
- package/Editor/Build/WebGLBuildHandler.cs +69 -0
- package/Editor/Build/WebGLBuildHandler.cs.meta +11 -0
- package/Editor/Build/WindowsBuildHandler.cs +24 -0
- package/Editor/Build/WindowsBuildHandler.cs.meta +11 -0
- package/Editor/Build/iOSBuildHandler.cs +119 -0
- package/Editor/Build/iOSBuildHandler.cs.meta +11 -0
- package/Editor/Build/macOSBuildHandler.cs +133 -0
- package/Editor/Build/macOSBuildHandler.cs.meta +11 -0
- package/Editor/Build.meta +8 -0
- package/Editor/Muna.Editor.asmdef +18 -0
- package/Editor/Muna.Editor.asmdef.meta +7 -0
- package/Editor/MunaMenu.cs +32 -0
- package/Editor/MunaMenu.cs.meta +11 -0
- package/Editor/MunaProjectSettings.cs +43 -0
- package/Editor/MunaProjectSettings.cs.meta +11 -0
- package/Editor/MunaSettingsProvider.cs +27 -0
- package/Editor/MunaSettingsProvider.cs.meta +11 -0
- package/Editor.meta +8 -0
- package/LICENSE +201 -0
- package/LICENSE.meta +7 -0
- package/Plugins/Android/Function.aar +0 -0
- package/Plugins/Android/Function.aar.meta +32 -0
- package/Plugins/Android.meta +8 -0
- package/Plugins/Linux/arm64/libFunction.so +0 -0
- package/Plugins/Linux/arm64/libFunction.so.meta +62 -0
- package/Plugins/Linux/arm64.meta +8 -0
- package/Plugins/Linux/x86_64/libFunction.so +0 -0
- package/Plugins/Linux/x86_64/libFunction.so.meta +82 -0
- package/Plugins/Linux/x86_64.meta +8 -0
- package/Plugins/Linux.meta +8 -0
- package/Plugins/Web/libFunction.a +0 -0
- package/Plugins/Web/libFunction.a.meta +87 -0
- package/Plugins/Web.meta +8 -0
- package/Plugins/Windows/arm64/Function.dll +0 -0
- package/Plugins/Windows/arm64/Function.dll.meta +58 -0
- package/Plugins/Windows/arm64.meta +8 -0
- package/Plugins/Windows/x86_64/Function.dll +0 -0
- package/Plugins/Windows/x86_64/Function.dll.meta +82 -0
- package/Plugins/Windows/x86_64.meta +8 -0
- package/Plugins/Windows.meta +8 -0
- package/Plugins/iOS/Function.xcframework/Info.plist +75 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64/Function.framework/Function +0 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64/Function.framework/Headers/FXNConfiguration.h +313 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64/Function.framework/Headers/FXNPrediction.h +165 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64/Function.framework/Headers/FXNPredictionStream.h +63 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64/Function.framework/Headers/FXNPredictor.h +108 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64/Function.framework/Headers/FXNStatus.h +42 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64/Function.framework/Headers/FXNValue.h +395 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64/Function.framework/Headers/FXNValueMap.h +148 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64/Function.framework/Headers/FXNVersion.h +26 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64/Function.framework/Headers/Function.h +18 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64/Function.framework/Info.plist +0 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64/Function.framework/Modules/module.modulemap +6 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64/Function.framework/PrivacyInfo.xcprivacy +36 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64/Function.framework/_CodeSignature/CodeResources +223 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64_x86_64-simulator/Function.framework/Function +0 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64_x86_64-simulator/Function.framework/Headers/FXNConfiguration.h +313 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64_x86_64-simulator/Function.framework/Headers/FXNPrediction.h +165 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64_x86_64-simulator/Function.framework/Headers/FXNPredictionStream.h +63 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64_x86_64-simulator/Function.framework/Headers/FXNPredictor.h +108 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64_x86_64-simulator/Function.framework/Headers/FXNStatus.h +42 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64_x86_64-simulator/Function.framework/Headers/FXNValue.h +395 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64_x86_64-simulator/Function.framework/Headers/FXNValueMap.h +148 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64_x86_64-simulator/Function.framework/Headers/FXNVersion.h +26 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64_x86_64-simulator/Function.framework/Headers/Function.h +18 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64_x86_64-simulator/Function.framework/Info.plist +0 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64_x86_64-simulator/Function.framework/Modules/module.modulemap +6 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64_x86_64-simulator/Function.framework/PrivacyInfo.xcprivacy +36 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64_x86_64-simulator/Function.framework/_CodeSignature/CodeResources +223 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64/Function.framework/Function +0 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64/Function.framework/Headers/FXNConfiguration.h +313 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64/Function.framework/Headers/FXNPrediction.h +165 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64/Function.framework/Headers/FXNPredictionStream.h +63 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64/Function.framework/Headers/FXNPredictor.h +108 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64/Function.framework/Headers/FXNStatus.h +42 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64/Function.framework/Headers/FXNValue.h +395 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64/Function.framework/Headers/FXNValueMap.h +148 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64/Function.framework/Headers/FXNVersion.h +26 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64/Function.framework/Headers/Function.h +18 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64/Function.framework/Info.plist +0 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64/Function.framework/Modules/module.modulemap +6 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64/Function.framework/PrivacyInfo.xcprivacy +36 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64/Function.framework/_CodeSignature/CodeResources +223 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64_x86_64-simulator/Function.framework/Function +0 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64_x86_64-simulator/Function.framework/Headers/FXNConfiguration.h +313 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64_x86_64-simulator/Function.framework/Headers/FXNPrediction.h +165 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64_x86_64-simulator/Function.framework/Headers/FXNPredictionStream.h +63 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64_x86_64-simulator/Function.framework/Headers/FXNPredictor.h +108 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64_x86_64-simulator/Function.framework/Headers/FXNStatus.h +42 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64_x86_64-simulator/Function.framework/Headers/FXNValue.h +395 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64_x86_64-simulator/Function.framework/Headers/FXNValueMap.h +148 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64_x86_64-simulator/Function.framework/Headers/FXNVersion.h +26 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64_x86_64-simulator/Function.framework/Headers/Function.h +18 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64_x86_64-simulator/Function.framework/Info.plist +0 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64_x86_64-simulator/Function.framework/Modules/module.modulemap +6 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64_x86_64-simulator/Function.framework/PrivacyInfo.xcprivacy +36 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64_x86_64-simulator/Function.framework/_CodeSignature/CodeResources +223 -0
- package/Plugins/iOS/Function.xcframework.meta +83 -0
- package/Plugins/iOS.meta +8 -0
- package/Plugins/macOS/Function.dylib +0 -0
- package/Plugins/macOS/Function.dylib.meta +82 -0
- package/Plugins/macOS.meta +8 -0
- package/Plugins.meta +8 -0
- package/README.md +79 -0
- package/README.md.meta +7 -0
- package/Runtime/API/DotNetClient.cs +106 -0
- package/Runtime/API/DotNetClient.cs.meta +11 -0
- package/Runtime/API/MunaClient.cs +96 -0
- package/Runtime/API/MunaClient.cs.meta +11 -0
- package/Runtime/API.meta +8 -0
- package/Runtime/Beta/BetaClient.cs +33 -0
- package/Runtime/Beta/BetaClient.cs.meta +11 -0
- package/Runtime/Beta/PredictionService.cs +32 -0
- package/Runtime/Beta/PredictionService.cs.meta +11 -0
- package/Runtime/Beta/RemoteAcceleration.cs +38 -0
- package/Runtime/Beta/RemoteAcceleration.cs.meta +11 -0
- package/Runtime/Beta/RemotePredictionService.cs +187 -0
- package/Runtime/Beta/RemotePredictionService.cs.meta +11 -0
- package/Runtime/Beta/Value.cs +92 -0
- package/Runtime/Beta/Value.cs.meta +11 -0
- package/Runtime/Beta.meta +8 -0
- package/Runtime/C/Configuration.cs +139 -0
- package/Runtime/C/Configuration.cs.meta +11 -0
- package/Runtime/C/Function.cs +294 -0
- package/Runtime/C/Function.cs.meta +11 -0
- package/Runtime/C/Prediction.cs +70 -0
- package/Runtime/C/Prediction.cs.meta +11 -0
- package/Runtime/C/PredictionStream.cs +36 -0
- package/Runtime/C/PredictionStream.cs.meta +11 -0
- package/Runtime/C/Predictor.cs +42 -0
- package/Runtime/C/Predictor.cs.meta +11 -0
- package/Runtime/C/Value.cs +194 -0
- package/Runtime/C/Value.cs.meta +11 -0
- package/Runtime/C/ValueMap.cs +50 -0
- package/Runtime/C/ValueMap.cs.meta +11 -0
- package/Runtime/C.meta +8 -0
- package/Runtime/Muna.Runtime.asmdef +27 -0
- package/Runtime/Muna.Runtime.asmdef.meta +7 -0
- package/Runtime/Muna.cs +109 -0
- package/Runtime/Muna.cs.meta +11 -0
- package/Runtime/Services/Prediction.cs +247 -0
- package/Runtime/Services/Prediction.cs.meta +11 -0
- package/Runtime/Services/Predictor.cs +44 -0
- package/Runtime/Services/Predictor.cs.meta +11 -0
- package/Runtime/Services/User.cs +43 -0
- package/Runtime/Services/User.cs.meta +11 -0
- package/Runtime/Services.meta +8 -0
- package/Runtime/Types/Dtype.cs +118 -0
- package/Runtime/Types/Dtype.cs.meta +11 -0
- package/Runtime/Types/Image.cs +93 -0
- package/Runtime/Types/Image.cs.meta +11 -0
- package/Runtime/Types/Prediction.cs +113 -0
- package/Runtime/Types/Prediction.cs.meta +11 -0
- package/Runtime/Types/Predictor.cs +193 -0
- package/Runtime/Types/Predictor.cs.meta +11 -0
- package/Runtime/Types/Tensor.cs +58 -0
- package/Runtime/Types/Tensor.cs.meta +11 -0
- package/Runtime/Types/User.cs +54 -0
- package/Runtime/Types/User.cs.meta +11 -0
- package/Runtime/Types.meta +8 -0
- package/Runtime.meta +8 -0
- package/Unity/API/PredictionCacheClient.cs +144 -0
- package/Unity/API/PredictionCacheClient.cs.meta +11 -0
- package/Unity/API/UnityClient.cs +147 -0
- package/Unity/API/UnityClient.cs.meta +11 -0
- package/Unity/API.meta +8 -0
- package/Unity/Internal/MunaSettings.cs +59 -0
- package/Unity/Internal/MunaSettings.cs.meta +11 -0
- package/Unity/Internal.meta +8 -0
- package/Unity/Muna.Unity.asmdef +29 -0
- package/Unity/Muna.Unity.asmdef.meta +7 -0
- package/Unity/MunaUnity.cs +130 -0
- package/Unity/MunaUnity.cs.meta +11 -0
- package/Unity/Types/CachedPrediction.cs +36 -0
- package/Unity/Types/CachedPrediction.cs.meta +11 -0
- package/Unity/Types.meta +8 -0
- package/Unity.meta +8 -0
- package/package.json +38 -0
- package/package.json.meta +7 -0
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Muna
|
|
3
|
+
* Copyright © 2025 NatML Inc. All rights reserved.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
#nullable enable
|
|
7
|
+
|
|
8
|
+
namespace Muna.Services {
|
|
9
|
+
|
|
10
|
+
using System;
|
|
11
|
+
using System.Collections;
|
|
12
|
+
using System.Collections.Generic;
|
|
13
|
+
using System.Linq;
|
|
14
|
+
using System.IO;
|
|
15
|
+
using System.Runtime.Serialization;
|
|
16
|
+
using System.Threading.Tasks;
|
|
17
|
+
using API;
|
|
18
|
+
using Configuration = C.Configuration;
|
|
19
|
+
using Value = C.Value;
|
|
20
|
+
using ValueMap = C.ValueMap;
|
|
21
|
+
|
|
22
|
+
/// <summary>
|
|
23
|
+
/// Make predictions.
|
|
24
|
+
/// </summary>
|
|
25
|
+
public sealed class PredictionService {
|
|
26
|
+
|
|
27
|
+
#region --Client API--
|
|
28
|
+
/// <summary>
|
|
29
|
+
/// Create a prediction.
|
|
30
|
+
/// </summary>
|
|
31
|
+
/// <param name="tag">Predictor tag.</param>
|
|
32
|
+
/// <param name="inputs">Input values.</param>
|
|
33
|
+
/// <param name="acceleration">Prediction acceleration.</param>
|
|
34
|
+
/// <param name="device">Prediction device. Do not set this unless you know what you are doing.</param>
|
|
35
|
+
/// <param name="clientId">Muna client identifier. Specify this to override the current client identifier.</param>
|
|
36
|
+
/// <param name="configurationId">Configuration identifier. Specify this to override the current client configuration token.</param>
|
|
37
|
+
public async Task<Prediction> Create(
|
|
38
|
+
string tag,
|
|
39
|
+
Dictionary<string, object?>? inputs = null,
|
|
40
|
+
Acceleration acceleration = default,
|
|
41
|
+
IntPtr device = default,
|
|
42
|
+
string? clientId = default,
|
|
43
|
+
string? configurationId = default
|
|
44
|
+
) {
|
|
45
|
+
await Configuration.InitializationTask;
|
|
46
|
+
if (inputs == null)
|
|
47
|
+
return await CreateRawPrediction(tag, clientId, configurationId);
|
|
48
|
+
var predictor = await GetPredictor(tag, acceleration, device, clientId, configurationId);
|
|
49
|
+
using var inputMap = ToValueMap(inputs);
|
|
50
|
+
using var prediction = predictor.CreatePrediction(inputMap);
|
|
51
|
+
return ToPrediction(tag, prediction);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/// <summary>
|
|
55
|
+
/// Stream a prediction.
|
|
56
|
+
/// </summary>
|
|
57
|
+
/// <param name="tag">Predictor tag.</param>
|
|
58
|
+
/// <param name="inputs">Input values.</param>
|
|
59
|
+
/// <param name="acceleration">Prediction acceleration.</param>
|
|
60
|
+
/// <param name="device">Prediction device. Do not set this unless you know what you are doing.</param>
|
|
61
|
+
public async IAsyncEnumerable<Prediction> Stream(
|
|
62
|
+
string tag,
|
|
63
|
+
Dictionary<string, object?> inputs,
|
|
64
|
+
Acceleration acceleration = default,
|
|
65
|
+
IntPtr device = default
|
|
66
|
+
) {
|
|
67
|
+
await Configuration.InitializationTask;
|
|
68
|
+
var predictor = await GetPredictor(tag, acceleration, device);
|
|
69
|
+
using var inputMap = ToValueMap(inputs);
|
|
70
|
+
using var stream = predictor.StreamPrediction(inputMap);
|
|
71
|
+
C.Prediction? prediction = null;
|
|
72
|
+
while ((prediction = stream.ReadNext()) != null)
|
|
73
|
+
using (prediction)
|
|
74
|
+
yield return ToPrediction(tag, prediction);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/// <summary>
|
|
78
|
+
/// Delete a predictor that is loaded in memory.
|
|
79
|
+
/// </summary>
|
|
80
|
+
/// <param name="tag">Predictor tag.</param>
|
|
81
|
+
/// <returns>Whether the predictor was successfully deleted from memory.</returns>
|
|
82
|
+
public async Task<bool> Delete(string tag) {
|
|
83
|
+
await Configuration.InitializationTask;
|
|
84
|
+
if (!cache.TryGetValue(tag, out var predictor))
|
|
85
|
+
return false;
|
|
86
|
+
predictor.Dispose();
|
|
87
|
+
cache.Remove(tag);
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
#endregion
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
#region --Operations--
|
|
94
|
+
private readonly MunaClient client;
|
|
95
|
+
private readonly string cachePath;
|
|
96
|
+
private readonly Dictionary<string, C.Predictor> cache = new();
|
|
97
|
+
|
|
98
|
+
internal PredictionService(MunaClient client) {
|
|
99
|
+
this.client = client;
|
|
100
|
+
this.cachePath = Path.Combine(
|
|
101
|
+
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
|
|
102
|
+
".fxn",
|
|
103
|
+
"cache"
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
private Task<Prediction> CreateRawPrediction(
|
|
108
|
+
string tag,
|
|
109
|
+
string? clientId = default,
|
|
110
|
+
string? configurationId = default
|
|
111
|
+
) => client.Request<Prediction>(
|
|
112
|
+
method: @"POST",
|
|
113
|
+
path: $"/predictions",
|
|
114
|
+
payload: new () {
|
|
115
|
+
[@"tag"] = tag,
|
|
116
|
+
[@"clientId"] = clientId ?? Configuration.ClientId,
|
|
117
|
+
[@"configurationId"] = configurationId ?? Configuration.ConfigurationId,
|
|
118
|
+
}
|
|
119
|
+
)!;
|
|
120
|
+
|
|
121
|
+
private async Task<C.Predictor> GetPredictor(
|
|
122
|
+
string tag,
|
|
123
|
+
Acceleration acceleration = default,
|
|
124
|
+
IntPtr device = default,
|
|
125
|
+
string? clientId = default,
|
|
126
|
+
string? configurationId = default
|
|
127
|
+
) {
|
|
128
|
+
if (cache.TryGetValue(tag, out var p))
|
|
129
|
+
return p;
|
|
130
|
+
var prediction = await CreateRawPrediction(tag, clientId, configurationId);
|
|
131
|
+
using var configuration = new Configuration() {
|
|
132
|
+
tag = prediction.tag,
|
|
133
|
+
token = prediction.configuration!,
|
|
134
|
+
acceleration = acceleration,
|
|
135
|
+
device = device
|
|
136
|
+
};
|
|
137
|
+
foreach (var resource in prediction.resources!)
|
|
138
|
+
await configuration.AddResource(
|
|
139
|
+
resource.type,
|
|
140
|
+
await DownloadResource(resource)
|
|
141
|
+
);
|
|
142
|
+
var predictor = new C.Predictor(configuration);
|
|
143
|
+
cache.Add(tag, predictor);
|
|
144
|
+
return predictor;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
private async Task<string> DownloadResource(PredictionResource resource) {
|
|
148
|
+
var uri = new Uri(resource.url);
|
|
149
|
+
if (uri.IsFile)
|
|
150
|
+
return uri.LocalPath;
|
|
151
|
+
var path = GetResourcePath(resource, cachePath);
|
|
152
|
+
if (File.Exists(path))
|
|
153
|
+
return path;
|
|
154
|
+
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
|
155
|
+
using var dataStream = await client.Download(resource.url);
|
|
156
|
+
using var fileStream = File.Create(path);
|
|
157
|
+
dataStream.CopyTo(fileStream); // CHECK // Async usage
|
|
158
|
+
return path;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
internal static string GetResourcePath(PredictionResource resource, string cacheDir) {
|
|
162
|
+
var uri = new Uri(resource.url);
|
|
163
|
+
var stem = Path.GetFileName(uri.AbsolutePath);
|
|
164
|
+
var path = string.IsNullOrEmpty(resource.name) ?
|
|
165
|
+
Path.Combine(cacheDir, stem) :
|
|
166
|
+
Path.Combine(cacheDir, stem, resource.name);
|
|
167
|
+
return path;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
internal static unsafe Value ToValue(object? value) => value switch {
|
|
171
|
+
Value x => x,
|
|
172
|
+
IntPtr x => new Value(x),
|
|
173
|
+
float x => Value.CreateArray(x),
|
|
174
|
+
double x => Value.CreateArray(x),
|
|
175
|
+
sbyte x => Value.CreateArray(x),
|
|
176
|
+
short x => Value.CreateArray(x),
|
|
177
|
+
int x => Value.CreateArray(x),
|
|
178
|
+
long x => Value.CreateArray(x),
|
|
179
|
+
byte x => Value.CreateArray(x),
|
|
180
|
+
ushort x => Value.CreateArray(x),
|
|
181
|
+
uint x => Value.CreateArray(x),
|
|
182
|
+
ulong x => Value.CreateArray(x),
|
|
183
|
+
bool x => Value.CreateArray(x),
|
|
184
|
+
float[] x => Value.CreateArray(x),
|
|
185
|
+
double[] x => Value.CreateArray(x),
|
|
186
|
+
sbyte[] x => Value.CreateArray(x),
|
|
187
|
+
short[] x => Value.CreateArray(x),
|
|
188
|
+
int[] x => Value.CreateArray(x),
|
|
189
|
+
long[] x => Value.CreateArray(x),
|
|
190
|
+
byte[] x => Value.CreateArray(x),
|
|
191
|
+
ushort[] x => Value.CreateArray(x),
|
|
192
|
+
uint[] x => Value.CreateArray(x),
|
|
193
|
+
ulong[] x => Value.CreateArray(x),
|
|
194
|
+
bool[] x => Value.CreateArray(x),
|
|
195
|
+
Tensor<float> x => Value.CreateArray(x),
|
|
196
|
+
Tensor<double> x => Value.CreateArray(x),
|
|
197
|
+
Tensor<sbyte> x => Value.CreateArray(x),
|
|
198
|
+
Tensor<short> x => Value.CreateArray(x),
|
|
199
|
+
Tensor<int> x => Value.CreateArray(x),
|
|
200
|
+
Tensor<long> x => Value.CreateArray(x),
|
|
201
|
+
Tensor<byte> x => Value.CreateArray(x),
|
|
202
|
+
Tensor<ushort> x => Value.CreateArray(x),
|
|
203
|
+
Tensor<uint> x => Value.CreateArray(x),
|
|
204
|
+
Tensor<ulong> x => Value.CreateArray(x),
|
|
205
|
+
Tensor<bool> x => Value.CreateArray(x),
|
|
206
|
+
string x => Value.CreateString(x),
|
|
207
|
+
Enum x => ToValue(SerializeEnum(x)),
|
|
208
|
+
IList x => Value.CreateList(x),
|
|
209
|
+
IDictionary x => Value.CreateDict(x),
|
|
210
|
+
Image x => Value.CreateImage(x),
|
|
211
|
+
Stream x => Value.CreateBinary(x),
|
|
212
|
+
null => Value.CreateNull(),
|
|
213
|
+
_ => throw new InvalidOperationException($"Cannot create a Muna value from value '{value}' of type {value.GetType()}"),
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
private static ValueMap ToValueMap(Dictionary<string, object?> inputs) {
|
|
217
|
+
var map = new ValueMap();
|
|
218
|
+
foreach (var pair in inputs)
|
|
219
|
+
map[pair.Key] = ToValue(pair.Value);
|
|
220
|
+
return map;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
private static Prediction ToPrediction(string tag, C.Prediction prediction) {
|
|
224
|
+
var outputMap = prediction.results;
|
|
225
|
+
return new Prediction {
|
|
226
|
+
id = prediction.id,
|
|
227
|
+
tag = tag,
|
|
228
|
+
created = DateTime.UtcNow,
|
|
229
|
+
results = outputMap != null ? Enumerable.Range(0, outputMap.size)
|
|
230
|
+
.Select(outputMap.GetKey)
|
|
231
|
+
.Select(outputMap.GetValue)
|
|
232
|
+
.Select(value => value.ToObject())
|
|
233
|
+
.ToArray() : null,
|
|
234
|
+
latency = prediction.latency,
|
|
235
|
+
error = prediction.error,
|
|
236
|
+
logs = prediction.logs,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
private static object SerializeEnum(Enum value) {
|
|
241
|
+
var fieldInfo = value.GetType().GetField(value.ToString());
|
|
242
|
+
var attribute = fieldInfo?.GetCustomAttributes(typeof(EnumMemberAttribute), false)?.FirstOrDefault() as EnumMemberAttribute;
|
|
243
|
+
return (attribute?.IsValueSetExplicitly ?? false) ? attribute.Value : Convert.ToInt32(value);
|
|
244
|
+
}
|
|
245
|
+
#endregion
|
|
246
|
+
}
|
|
247
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Muna
|
|
3
|
+
* Copyright © 2025 NatML Inc. All rights reserved.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
#nullable enable
|
|
7
|
+
|
|
8
|
+
namespace Muna.Services {
|
|
9
|
+
|
|
10
|
+
using System.Threading.Tasks;
|
|
11
|
+
using API;
|
|
12
|
+
|
|
13
|
+
/// <summary>
|
|
14
|
+
/// Manage predictors.
|
|
15
|
+
/// </summary>
|
|
16
|
+
public sealed class PredictorService {
|
|
17
|
+
|
|
18
|
+
#region --Client API--
|
|
19
|
+
/// <summary>
|
|
20
|
+
/// Retrieve a predictor.
|
|
21
|
+
/// </summary>
|
|
22
|
+
/// <param name="tag">Predictor tag.</param>
|
|
23
|
+
public async Task<Predictor?> Retrieve(string tag) {
|
|
24
|
+
try {
|
|
25
|
+
return await client.Request<Predictor>(
|
|
26
|
+
method: @"GET",
|
|
27
|
+
path: $"/predictors/{tag}"
|
|
28
|
+
);
|
|
29
|
+
} catch (MunaAPIException ex) {
|
|
30
|
+
if (ex.status == 404)
|
|
31
|
+
return null;
|
|
32
|
+
throw;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
#endregion
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
#region --Operations--
|
|
39
|
+
private readonly MunaClient client;
|
|
40
|
+
|
|
41
|
+
internal PredictorService(MunaClient client) => this.client = client;
|
|
42
|
+
#endregion
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Muna
|
|
3
|
+
* Copyright © 2025 NatML Inc. All rights reserved.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
#nullable enable
|
|
7
|
+
|
|
8
|
+
namespace Muna.Services {
|
|
9
|
+
|
|
10
|
+
using System.Threading.Tasks;
|
|
11
|
+
using API;
|
|
12
|
+
|
|
13
|
+
/// <summary>
|
|
14
|
+
/// Manage users.
|
|
15
|
+
/// </summary>
|
|
16
|
+
public sealed class UserService {
|
|
17
|
+
|
|
18
|
+
#region --Client API--
|
|
19
|
+
/// <summary>
|
|
20
|
+
/// Retrieve the current user.
|
|
21
|
+
/// </summary>
|
|
22
|
+
public async Task<User?> Retrieve() {
|
|
23
|
+
try {
|
|
24
|
+
return await client.Request<User>(
|
|
25
|
+
method: @"GET",
|
|
26
|
+
path: @"/users"
|
|
27
|
+
);
|
|
28
|
+
} catch (MunaAPIException ex) {
|
|
29
|
+
if (ex.status == 401)
|
|
30
|
+
return null;
|
|
31
|
+
throw;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
#endregion
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
#region --Operations--
|
|
38
|
+
private readonly MunaClient client;
|
|
39
|
+
|
|
40
|
+
internal UserService(MunaClient client) => this.client = client;
|
|
41
|
+
#endregion
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Muna
|
|
3
|
+
* Copyright © 2025 NatML Inc. All rights reserved.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
namespace Muna {
|
|
7
|
+
|
|
8
|
+
using System.Runtime.Serialization;
|
|
9
|
+
using Newtonsoft.Json;
|
|
10
|
+
using Newtonsoft.Json.Converters;
|
|
11
|
+
|
|
12
|
+
/// <summary>
|
|
13
|
+
/// Value type.
|
|
14
|
+
/// </summary>
|
|
15
|
+
[JsonConverter(typeof(StringEnumConverter))]
|
|
16
|
+
public enum Dtype : int { // CHECK // Must match `Function.h`
|
|
17
|
+
/// <summary>
|
|
18
|
+
/// Null or unsupported data type.
|
|
19
|
+
/// </summary>
|
|
20
|
+
[EnumMember(Value = @"null")]
|
|
21
|
+
Null = 0,
|
|
22
|
+
/// <summary>
|
|
23
|
+
/// Type is a generic half-precision float.
|
|
24
|
+
/// </summary>
|
|
25
|
+
[EnumMember(Value = @"float16")]
|
|
26
|
+
Float16 = 1,
|
|
27
|
+
/// <summary>
|
|
28
|
+
/// Type is `float` in C/C++/C#.
|
|
29
|
+
/// </summary>
|
|
30
|
+
[EnumMember(Value = @"float32")]
|
|
31
|
+
Float32 = 2,
|
|
32
|
+
/// <summary>
|
|
33
|
+
/// Type is `double` in C/C++/C#.
|
|
34
|
+
/// </summary>
|
|
35
|
+
[EnumMember(Value = @"float64")]
|
|
36
|
+
Float64 = 3,
|
|
37
|
+
/// <summary>
|
|
38
|
+
/// Type is a `int8_t` in C/C++ and `sbyte` in C#.
|
|
39
|
+
/// </summary>
|
|
40
|
+
[EnumMember(Value = @"int8")]
|
|
41
|
+
Int8 = 4,
|
|
42
|
+
/// <summary>
|
|
43
|
+
/// Type is `int16_t` in C/C++ and `short` in C#.
|
|
44
|
+
/// </summary>
|
|
45
|
+
[EnumMember(Value = @"int16")]
|
|
46
|
+
Int16 = 5,
|
|
47
|
+
/// <summary>
|
|
48
|
+
/// Type is `int32_t` in C/C++ and `int` in C#.
|
|
49
|
+
/// </summary>
|
|
50
|
+
[EnumMember(Value = @"int32")]
|
|
51
|
+
Int32 = 6,
|
|
52
|
+
/// <summary>
|
|
53
|
+
/// Type is `int64_t` in C/C++ and `long` in C#.
|
|
54
|
+
/// </summary>
|
|
55
|
+
[EnumMember(Value = @"int64")]
|
|
56
|
+
Int64 = 7,
|
|
57
|
+
/// <summary>
|
|
58
|
+
/// Type is `uint8_t` in C/C++ and `byte` in C#.
|
|
59
|
+
/// </summary>
|
|
60
|
+
[EnumMember(Value = @"uint8")]
|
|
61
|
+
Uint8 = 8,
|
|
62
|
+
/// <summary>
|
|
63
|
+
/// Type is a `uint16_t` in C/C++ and `ushort` in C#.
|
|
64
|
+
/// </summary>
|
|
65
|
+
[EnumMember(Value = @"uint16")]
|
|
66
|
+
Uint16 = 9,
|
|
67
|
+
/// <summary>
|
|
68
|
+
/// Type is a `uint32_t` in C/C++ and `uint` in C#.
|
|
69
|
+
/// </summary>
|
|
70
|
+
[EnumMember(Value = @"uint32")]
|
|
71
|
+
Uint32 = 10,
|
|
72
|
+
/// <summary>
|
|
73
|
+
/// Type is a `uint64_t` in C/C++ and `ulong` in C#.
|
|
74
|
+
/// </summary>
|
|
75
|
+
[EnumMember(Value = @"uint64")]
|
|
76
|
+
Uint64 = 11,
|
|
77
|
+
/// <summary>
|
|
78
|
+
/// Type is a `bool` in C/C++/C#.
|
|
79
|
+
/// </summary>
|
|
80
|
+
[EnumMember(Value = @"bool")]
|
|
81
|
+
Bool = 12,
|
|
82
|
+
/// <summary>
|
|
83
|
+
/// Type is `std::string` in C++ and `string` in C#.
|
|
84
|
+
/// </summary>
|
|
85
|
+
[EnumMember(Value = @"string")]
|
|
86
|
+
String = 13,
|
|
87
|
+
/// <summary>
|
|
88
|
+
/// Type is a generic list.
|
|
89
|
+
/// </summary>
|
|
90
|
+
[EnumMember(Value = @"list")]
|
|
91
|
+
List = 14,
|
|
92
|
+
/// <summary>
|
|
93
|
+
/// Type is a generic dictionary.
|
|
94
|
+
/// </summary>
|
|
95
|
+
[EnumMember(Value = @"dict")]
|
|
96
|
+
Dict = 15,
|
|
97
|
+
/// <summary>
|
|
98
|
+
/// Type is an encoded image.
|
|
99
|
+
/// </summary>
|
|
100
|
+
[EnumMember(Value = @"image")]
|
|
101
|
+
Image = 16,
|
|
102
|
+
/// <summary>
|
|
103
|
+
/// Type is a binary blob.
|
|
104
|
+
/// </summary>
|
|
105
|
+
[EnumMember(Value = @"binary")]
|
|
106
|
+
Binary = 17,
|
|
107
|
+
/// <summary>
|
|
108
|
+
/// Type is an encoded audio.
|
|
109
|
+
/// </summary>
|
|
110
|
+
[EnumMember(Value = @"audio")]
|
|
111
|
+
Audio = 18,
|
|
112
|
+
/// <summary>
|
|
113
|
+
/// Type is an encoded video.
|
|
114
|
+
/// </summary>
|
|
115
|
+
[EnumMember(Value = @"video")]
|
|
116
|
+
Video = 19,
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Muna
|
|
3
|
+
* Copyright © 2025 NatML Inc. All rights reserved.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
#nullable enable
|
|
7
|
+
|
|
8
|
+
namespace Muna {
|
|
9
|
+
|
|
10
|
+
using Newtonsoft.Json;
|
|
11
|
+
|
|
12
|
+
/// <summary>
|
|
13
|
+
/// Image.
|
|
14
|
+
/// </summary>
|
|
15
|
+
[Preserve]
|
|
16
|
+
public unsafe readonly struct Image {
|
|
17
|
+
|
|
18
|
+
#region --Client API--
|
|
19
|
+
/// <summary>
|
|
20
|
+
/// Image pixel buffer.
|
|
21
|
+
/// This is always 8bpp interleaved by channel.
|
|
22
|
+
/// </summary>
|
|
23
|
+
[JsonIgnore]
|
|
24
|
+
public readonly byte[] data;
|
|
25
|
+
|
|
26
|
+
/// <summary>
|
|
27
|
+
/// Image width.
|
|
28
|
+
/// </summary>
|
|
29
|
+
public readonly int width;
|
|
30
|
+
|
|
31
|
+
/// <summary>
|
|
32
|
+
/// Image height.
|
|
33
|
+
/// </summary>
|
|
34
|
+
public readonly int height;
|
|
35
|
+
|
|
36
|
+
/// <summary>
|
|
37
|
+
/// Image channels.
|
|
38
|
+
/// </summary>
|
|
39
|
+
public readonly int channels;
|
|
40
|
+
|
|
41
|
+
/// <summary>
|
|
42
|
+
/// Create an image.
|
|
43
|
+
/// </summary>
|
|
44
|
+
/// <param name="data">Pixel buffer. The pixel buffer format MUST be `R8`, `RGB888`, or `RGBA8888`.</param>
|
|
45
|
+
/// <param name="width">Image width.</param>
|
|
46
|
+
/// <param name="height">Image height.</param>
|
|
47
|
+
/// <param name="channels">Image channels.</param>
|
|
48
|
+
public Image(byte[] data, int width, int height, int channels) {
|
|
49
|
+
this.data = data;
|
|
50
|
+
this.nativeData = null;
|
|
51
|
+
this.width = width;
|
|
52
|
+
this.height = height;
|
|
53
|
+
this.channels = channels;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/// <summary>
|
|
57
|
+
/// Create an image from a pixel buffer.
|
|
58
|
+
/// NOTE: DO NOT use this overload unless you absolutely know what you are doing.
|
|
59
|
+
/// </summary>
|
|
60
|
+
/// <param name="data">Pixel buffer. The pixel buffer format MUST be `R8`, `RGB888`, or `RGBA8888`.</param>
|
|
61
|
+
/// <param name="width">Image width.</param>
|
|
62
|
+
/// <param name="height">Image height</param>
|
|
63
|
+
/// <param name="channels">Image channels.</param>
|
|
64
|
+
public unsafe Image(byte* data, int width, int height, int channels) { // Enables zero copy into `FXNValue`
|
|
65
|
+
this.data = null!;
|
|
66
|
+
this.nativeData = data;
|
|
67
|
+
this.width = width;
|
|
68
|
+
this.height = height;
|
|
69
|
+
this.channels = channels;
|
|
70
|
+
}
|
|
71
|
+
#endregion
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
#region --Operations--
|
|
75
|
+
private readonly byte* nativeData;
|
|
76
|
+
|
|
77
|
+
[JsonProperty(@"data"), Preserve]
|
|
78
|
+
private readonly string dataPlaceholder {
|
|
79
|
+
get {
|
|
80
|
+
var channelStr = "?";
|
|
81
|
+
switch (channels) {
|
|
82
|
+
case 1: channelStr = "R8"; break;
|
|
83
|
+
case 3: channelStr = "RGB888"; break;
|
|
84
|
+
case 4: channelStr = "RGBA8888"; break;
|
|
85
|
+
}
|
|
86
|
+
return $"<{width}x{height},{channelStr},{data.Length} bytes>";
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public ref byte GetPinnableReference() => ref (nativeData == null ? ref data[0] : ref *nativeData);
|
|
91
|
+
#endregion
|
|
92
|
+
}
|
|
93
|
+
}
|