Skip to content

Commit 9320b43

Browse files
committed
2.8.1: missing changes restored
1 parent 43d5e92 commit 9320b43

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+5671
-226
lines changed

.gitignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ _pkginfo.txt
210210
*.appx
211211
*.appxbundle
212212
*.appxupload
213+
*.msixbundle
213214

214215
# Visual Studio cache files
215216
# files ending in .cache can be ignored
@@ -353,9 +354,11 @@ wget-log*
353354
# Module packages --------------------------------------------------------------
354355

355356
# Generated exe packages
356-
/src/modules/*/*-[0-9]*.[0-9]*.[0-9]*.zip
357+
/modules/*/*-[0-9]*.[0-9]*.[0-9]*.zip
358+
357359

358360
# Debug debris -----------------------------------------------------------------
359361

360362
/SDK
361-
/debug
363+
/debug
364+
object-detect.exe

.vscode/launch.docker.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
"cwd": "/app/server/",
1818
"stopAtEntry": false,
1919
"requireExactSource": false,
20+
/*
2021
"serverReadyAction": {
2122
"action": "openExternally",
22-
"pattern": "\\bNow listening on:\\s+(https?://\\S+)",
23+
"pattern": "\\blistening on port: (\\d+)",
2324
"uriFormat": "http://localhost:%s/swagger"
2425
},
26+
*/
2527
"env": {
2628
"ASPNETCORE_ENVIRONMENT": "Development",
2729
"RUNNING_IN_VSCODE": "true",
@@ -62,11 +64,13 @@
6264
],
6365
"cwd": "/app/server/",
6466
"stopAtEntry": false,
67+
/*
6568
"serverReadyAction": {
6669
"action": "openExternally",
67-
"pattern": "\\bNow listening on:\\s+(https?://\\S+)",
70+
"pattern": "\\blistening on port: (\\d+)",
6871
"uriFormat": "http://localhost:%s/swagger"
6972
},
73+
*/
7074
"env": {
7175
"ASPNETCORE_ENVIRONMENT": "Development",
7276
"RUNNING_IN_VSCODE": "true",

.vscode/tasks.docker.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"group": "none",
1010
"type": "process",
1111
"command": "bash",
12-
"args": [ "/app/devops/scripts/stop_all.sh" ],
12+
"args": [ "/app/devops/utils/stop_all.sh" ],
1313
"problemMatcher": "$msCompile"
1414
}
1515
]

modules/install_script_help.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ As an example, `requirements.linux.arm64.cuda11_7.txt` would be a requirements f
116116
| `writeLine` | text [foreground [background]]
117117
| `installAptPackages` | "list of packages to install"<br>Installs a list of apt packages. <br>eg `installAptPackages "libjpeg-dev zlib1g-dev libpython3-dev"` |
118118
| `installPythonPackagesByName` | *`PIP module names, separated by space` or `Wheel file path`, `Module name`*<br>- `PIP module name` - the name of the Python module to install, eg 'torch'<br> - `Wheel file path` - instead of a module name you can supply a wheel file path for installation<br> - `Module description` - (optional) the name or description of the module being installed<br>eg `installPythonPackagesByName "torch"`<br>`installPythonPackagesByName "my-torch-wheel.whl" "torch"`<br> - `PIP options` - (optional) Any otions you wish to pass to PIP (eg --index-url)|
119-
| `downloadAndExtract` | *storageUrl filename downloadDirPath dirNameToSave message*<br>`storageUrl` - Url that holds the compressed archive to Download<br>`filename` - Name of the compressed archive to be downloaded<br> `downloadDirPath` - path to where the downloaded compressed archive should be downloaded<br>`dirNameToSave` - name of directory, relative to downloadDirPath, where contents of archive will be extracted and saved<br>`message` - Message to display during download |
120-
| `Download` | *storageUrl downloadDirPath filename moduleDirName message*<br> - `storageUrl` Url that holds the compressed archive to Download<<br> - `downloadDirPath` Path to where the downloaded compressed archive should be downloade<br> - `filename` name of the compressed archive to be downloaded<br> - `dirNameToSave` name of directory, relative to downloadDirPath, where contents of archive will be extracted and saved<br> - `message` Message to display during download |
119+
| `downloadAndExtract` | *assetStorageUrl filename downloadDirPath dirNameToSave message*<br>`assetStorageUrl` - Url that holds the compressed archive to Download<br>`filename` - Name of the compressed archive to be downloaded<br> `downloadDirPath` - path to where the downloaded compressed archive should be downloaded<br>`dirNameToSave` - name of directory, relative to downloadDirPath, where contents of archive will be extracted and saved<br>`message` - Message to display during download |
120+
| `Download` | *assetStorageUrl downloadDirPath filename moduleDirName message*<br> - `assetStorageUrl` Url that holds the compressed archive to Download<<br> - `downloadDirPath` Path to where the downloaded compressed archive should be downloade<br> - `filename` name of the compressed archive to be downloaded<br> - `dirNameToSave` name of directory, relative to downloadDirPath, where contents of archive will be extracted and saved<br> - `message` Message to display during download |
121121
|||
122122
| `getFromServer` | *folder filename moduleAssetDir message*<br>`folder` - name of the folder in the S3 bucket where the file lives<br>`filename` - Name of the compressed archive to be downloaded<br>`moduleAssetDir`- Name of folder in module's directory where archive will be extracted<br>`message` - Message to display during download <br><br>Tnis method will pull an archive from the current CodeProject cloud storage. This storage is read-only and subject to change.|
123123
|||

src/SDK/NET/API/ApiClient.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System.Net.Http.Json;
2-
using CodeProject.AI.SDK.API;
2+
using CodeProject.AI.SDK.Common;
33

4-
namespace CodeProject.AI.API
4+
namespace CodeProject.AI.SDK.API
55
{
66
/// <summary>
77
/// Contains the data to be sent as part of a request to the server
@@ -105,9 +105,9 @@ protected HttpClient Client
105105
/// Initializes a new instance of the ApiClient class.
106106
/// </summary>
107107
/// <param name="port">The oort for the HTTP calls</param>
108-
public ApiClient(int port)
108+
public ApiClient(int port = 0)
109109
{
110-
Port = port;
110+
Port = port <= 0 ? Constants.DefaultPort : port;
111111
}
112112

113113
/// <summary>

src/SDK/NET/API/ServerResponses.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
using System.Net;
22

3+
using CodeProject.AI.SDK.Modules;
4+
using CodeProject.AI.SDK.Common;
5+
using CodeProject.AI.SDK.Server;
6+
37
namespace CodeProject.AI.SDK.API
48
{
59
/// <summary>

src/SDK/NET/Auxiliary.info

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<!-- This file deliberately empty -->
3+
</Project>

src/SDK/NET/Analysis/BackendClient.cs renamed to src/SDK/NET/Backend/BackendClient.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
namespace CodeProject.AI.SDK
1010
{
1111
/// <summary>
12-
/// Represents an HTTP client to get requests and return responses to the CodeProject.AI server.
12+
/// Represents an HTTP client for modules that gets requests and returns responses to the
13+
/// CodeProject.AI server.
1314
/// </summary>
1415
public class BackendClient
1516
{
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System.Text.Json.Serialization;
2+
3+
namespace CodeProject.AI.SDK
4+
{
5+
#pragma warning disable IDE1006 // Naming Styles
6+
7+
/// <summary>
8+
/// Base class for queued requests for the backend. The naming here is for legacy backwards
9+
/// compatibility, and should probably be updated to something sensible.
10+
/// </summary>
11+
/// <remarks>We should rename reqtype to command and just have BackendRequest. We don't need
12+
/// this base class.</remarks>
13+
public class BackendRequestBase
14+
{
15+
/// <summary>
16+
/// Gets the request unique id. Used to return the response to the correct caller.
17+
/// </summary>
18+
[JsonInclude]
19+
public string reqid { get; private set; } = Guid.NewGuid().ToString();
20+
21+
/// <summary>
22+
/// Gets or sets the request type.
23+
/// </summary>
24+
[JsonInclude]
25+
public string? reqtype { get; protected set; }
26+
}
27+
28+
/// <summary>
29+
/// Request with payload.
30+
/// </summary>
31+
public class BackendRequest : BackendRequestBase
32+
{
33+
/// <summary>
34+
/// Gets or sets the payload.
35+
/// </summary>
36+
[JsonInclude]
37+
public RequestPayload payload { get; protected set; }
38+
39+
/// <summary>
40+
/// Instantiates a new instance of the <cref="BackendRequest" /> class.
41+
/// TODO: Normalise the input. Currently reqtype == payload.command. One or the other, please.
42+
/// </summary>
43+
/// <param name="payload">The request payload</param>
44+
public BackendRequest(RequestPayload payload)
45+
{
46+
this.reqtype = payload.command ?? string.Empty;
47+
this.payload = payload;
48+
}
49+
}
50+
51+
#pragma warning restore IDE1006 // Naming Styles
52+
}

src/SDK/NET/Analysis/ModuleWorkerBase.cs renamed to src/SDK/NET/Backend/ModuleWorkerBase.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Net.Http.Json;
44

55
using CodeProject.AI.SDK.API;
6-
using CodeProject.AI.SDK.Common;
76
using CodeProject.AI.SDK.Utils;
87

98
using Microsoft.Extensions.Configuration;
@@ -104,6 +103,23 @@ public ModuleWorkerBase(ILogger logger, IConfiguration configuration,
104103
string currentModuleDirPath = GetModuleDirectoryPath();
105104
string currentDirName = new DirectoryInfo(currentModuleDirPath).Name;
106105

106+
// TODO: We could load the settings directly from the modulesettings files rather than rely
107+
// rely environment variables:
108+
/*
109+
// Load up the module's settings and start the module
110+
var config = new ConfigurationBuilder();
111+
config.AddModuleSettingsConfigFiles(moduleDirPath, false);
112+
IConfiguration configuration = config.Build();
113+
114+
// Bind the values in the configuration to a ModuleConfig object
115+
string moduleId = [get module id from config]
116+
var moduleConfig = new ModuleConfig();
117+
configuration.Bind($"Modules:{moduleId}", moduleConfig);
118+
119+
// Complete the ModuleConfig's setup.
120+
if (moduleConfig.Initialise(moduleId, moduleDirPath, ModuleLocation.Internal))
121+
*/
122+
107123
_moduleId = configuration.GetValue<string?>("CPAI_MODULE_ID", null) ?? currentDirName;
108124
ModuleName = configuration.GetValue<string?>("CPAI_MODULE_NAME", null) ?? _moduleId;
109125
moduleDirPath = configuration.GetValue<string?>("CPAI_MODULE_PATH", null) ?? currentModuleDirPath;

src/SDK/NET/Common/RequestFormFile.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using CodeProject.AI.SDK.Utils;
2+
3+
using SkiaSharp;
4+
5+
namespace CodeProject.AI.SDK
6+
{
7+
public class RequestFormFile
8+
{
9+
/// <summary>
10+
/// Gets or sets the form field name of the file being passed.
11+
/// </summary>
12+
public string? name { get; set; }
13+
14+
/// <summary>
15+
/// Gets or sets the name of the file being passed.
16+
/// </summary>
17+
public string? filename { get; set; }
18+
19+
/// <summary>
20+
/// Gets or sets the content type of the file being passed.
21+
/// </summary>
22+
public string? contentType { get; set; }
23+
24+
/// <summary>
25+
/// Gets or sets the actual file data being passed.
26+
/// </summary>
27+
public byte[]? data { get; set; }
28+
29+
/// <summary>
30+
/// Converts the RequestFormFile to an Image.
31+
/// </summary>
32+
/// <returns>The image, or null if conversion fails.</returns>
33+
public SKImage? AsImage()
34+
{
35+
return ImageUtils.GetImage(data);
36+
}
37+
}
38+
39+
#pragma warning restore IDE1006 // Naming Styles
40+
}

src/SDK/NET/Analysis/BackendRequests.cs renamed to src/SDK/NET/Common/RequestPayload.cs

Lines changed: 30 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,7 @@
11
using System.Diagnostics;
2-
using System.Text.Json.Serialization;
3-
4-
using CodeProject.AI.SDK.Utils;
5-
6-
using SkiaSharp;
72

83
namespace CodeProject.AI.SDK
94
{
10-
#pragma warning disable IDE1006 // Naming Styles
11-
12-
/// <summary>
13-
/// Base class for queued requests for the backend. The naming here is for legacy backwards
14-
/// compatibility, and should probably be updated to something sensible.
15-
/// </summary>
16-
/// <remarks>We should rename reqtype to command and just have BackendRequest. We don't need
17-
/// this base class.</remarks>
18-
public class BackendRequestBase
19-
{
20-
/// <summary>
21-
/// Gets the request unique id. Used to return the response to the correct caller.
22-
/// </summary>
23-
[JsonInclude]
24-
public string reqid { get; private set; } = Guid.NewGuid().ToString();
25-
26-
/// <summary>
27-
/// Gets or sets the request type.
28-
/// </summary>
29-
[JsonInclude]
30-
public string? reqtype { get; protected set; }
31-
}
32-
33-
/// <summary>
34-
/// Request with payload.
35-
/// </summary>
36-
public class BackendRequest : BackendRequestBase
37-
{
38-
/// <summary>
39-
/// Gets or sets the payload.
40-
/// </summary>
41-
[JsonInclude]
42-
public RequestPayload payload { get; protected set; }
43-
44-
/// <summary>
45-
/// Instantiates a new instance of the <cref="BackendRequest" /> class.
46-
/// TODO: Normalise the input. Currently reqtype == payload.command. One or the other, please.
47-
/// </summary>
48-
/// <param name="payload">The request payload</param>
49-
public BackendRequest(RequestPayload payload)
50-
{
51-
this.reqtype = payload.command ?? string.Empty;
52-
this.payload = payload;
53-
}
54-
}
55-
565
public class RequestPayload
576
{
587
/// <summary>
@@ -222,6 +171,36 @@ public void AddFile(string filePath)
222171
}
223172
}
224173

174+
/// <summary>
175+
/// Adds a file stream to the payload
176+
/// </summary>
177+
/// <param name="stream">The stream to the file to add</param>
178+
/// <param name="filePath">The path to the file to add</param>
179+
/// <remarks>Could be used with a FormFile from a form post,</remarks>
180+
public void AddFile(Stream stream, string filePath)
181+
{
182+
// NOTE: Path.GetExtension and Path.GetFileName works with file paths and urls.
183+
try
184+
{
185+
using BinaryReader reader = new BinaryReader(stream);
186+
var formFile = new RequestFormFile()
187+
{
188+
name = "image",
189+
filename = Path.GetFileName(filePath),
190+
contentType = "image/" + Path.GetExtension(filePath).Substring(1),
191+
data = reader.ReadBytes((int)stream.Length)
192+
};
193+
194+
var allFiles = files as List<RequestFormFile> ?? new List<RequestFormFile>();
195+
allFiles.Add(formFile);
196+
197+
files = allFiles;
198+
}
199+
catch (Exception e)
200+
{
201+
Debug.WriteLine("Error adding file: " + e.Message);
202+
}
203+
}
225204
/// <summary>
226205
/// Gets a File from the payload by name.
227206
/// </summary>
@@ -243,37 +222,5 @@ public void AddFile(string filePath)
243222
}
244223
}
245224

246-
public class RequestFormFile
247-
{
248-
/// <summary>
249-
/// Gets or sets the form field name of the file being passed.
250-
/// </summary>
251-
public string? name { get; set; }
252-
253-
/// <summary>
254-
/// Gets or sets the name of the file being passed.
255-
/// </summary>
256-
public string? filename { get; set; }
257-
258-
/// <summary>
259-
/// Gets or sets the content type of the file being passed.
260-
/// </summary>
261-
public string? contentType { get; set; }
262-
263-
/// <summary>
264-
/// Gets or sets the actual file data being passed.
265-
/// </summary>
266-
public byte[]? data { get; set; }
267-
268-
/// <summary>
269-
/// Converts the RequestFormFile to an Image.
270-
/// </summary>
271-
/// <returns>The image, or null if conversion fails.</returns>
272-
public SKImage? AsImage()
273-
{
274-
return ImageUtils.GetImage(data);
275-
}
276-
}
277-
278225
#pragma warning restore IDE1006 // Naming Styles
279226
}

src/SDK/NET/API/VersionInfo.cs renamed to src/SDK/NET/Common/VersionInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.Text.Json.Serialization;
22

3-
namespace CodeProject.AI.SDK.API
3+
namespace CodeProject.AI.SDK.Common
44
{
55
/// <summary>
66
/// The current version of the server.

src/SDK/NET/API/ExplorerUI.cs renamed to src/SDK/NET/FrontEndClient/ExplorerUI.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.Text.Json.Serialization;
22

3-
namespace CodeProject.AI.SDK.API
3+
namespace CodeProject.AI.SDK.Server
44
{
55
/// <summary>
66
/// Represents an option in a dropdown menu in the dashboard

0 commit comments

Comments
 (0)