Skip to content

Commit cbc0262

Browse files
author
Chris Maunder
committed
Merge branch 'v2.9.0' of https://github.com/codeproject/CodeProject.AI-Server into v2.9.0
2 parents 9add1f0 + 97aa2ae commit cbc0262

File tree

7 files changed

+100
-32
lines changed

7 files changed

+100
-32
lines changed

.vscode/launch.json

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@
490490
}
491491
},
492492

493+
/*
493494
{
494495
"presentation": {
495496
"group": "9 Demo clients",
@@ -502,25 +503,26 @@
502503
"console": "internalConsole",
503504
"request": "launch",
504505
"preLaunchTask": "build-explorer",
505-
"cwd": "${workspaceFolder}/src/demos/clients/Net/CodeProject.AI.Explorer/",
506+
"cwd": "${workspaceFolder}/src/demos/clients/Net/AiExplorer/",
506507
"env": {
507508
"ASPNETCORE_ENVIRONMENT": "Development",
508509
"RUNNING_IN_VSCODE": "true",
509510
"DOTNET_NOLOGO": "true"
510511
}
511512
},
513+
*/
512514

513515
{
514516
"presentation": {
515517
"group": "9 Demo clients",
516518
// "order": 90
517519
},
518-
"name": "[Win] Run Explorer App",
520+
"name": "[Win] AI Explorer Demo",
519521
"type": "coreclr",
520522
"request": "launch",
521-
"preLaunchTask": "build-explorer",
523+
"preLaunchTask": "build-ai-explorer",
522524
"windows": {
523-
"program": "${workspaceFolder}/src/demos/clients/Net/CodeProject.AI.Explorer/bin/Debug/net8.0-windows/CodeProject.AI.Explorer.exe",
525+
"program": "${workspaceFolder}/src/demos/clients/Net/AiExplorer/bin/Debug/net8.0-windows/AiExplorer.exe",
524526
},
525527
"args": [],
526528
"cwd": "${workspaceFolder}",
@@ -533,6 +535,33 @@
533535
}
534536
},
535537

538+
{
539+
"presentation": {
540+
"group": "9 Demo clients",
541+
// "order": 90
542+
},
543+
"name": "JSON client Demo",
544+
"type": "coreclr",
545+
"request": "launch",
546+
"preLaunchTask": "build-json-client",
547+
"program": "${workspaceFolder}/src/demos/clients/Net/JsonAPI/bin/Debug/net8.0/JsonAPI",
548+
"linux": {
549+
"program": "${workspaceFolder}/src/demos/clients/Net/JsonAPI/bin/Debug/net8.0/JsonAPI.dll",
550+
},
551+
"osx": {
552+
"program": "${workspaceFolder}/src/demos/clients/Net/JsonAPI/bin/Debug/net8.0/JsonAPI.dll",
553+
},
554+
"args": [],
555+
"cwd": "${workspaceFolder}/src/demos/clients/Net/JsonAPI/",
556+
"stopAtEntry": false,
557+
"console": "internalConsole",
558+
"env": {
559+
"ASPNETCORE_ENVIRONMENT": "Development",
560+
"RUNNING_IN_VSCODE": "true",
561+
"DOTNET_NOLOGO": "true"
562+
}
563+
},
564+
536565
{
537566
"presentation": {
538567
"group": "9 Demo clients",

.vscode/tasks.json

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,27 @@
250250
},
251251

252252
{
253-
"label": "build-explorer", // Builds ONLY the Windows Forms .NET demo explorer (windows only)
253+
"label": "build-ai-explorer", // Builds ONLY the Windows Forms .NET demo explorer (windows only)
254254
"type": "process",
255255
"group": "build",
256256
"command": "dotnet",
257257
"args": [
258258
"build",
259-
"${workspaceFolder}/src/demos/clients/Net/CodeProject.AI.Explorer",
259+
"${workspaceFolder}/src/demos/clients/Net/AiExplorer",
260+
"/property:GenerateFullPaths=true",
261+
"/consoleloggerparameters:NoSummary"
262+
],
263+
"problemMatcher": "$msCompile"
264+
},
265+
266+
{
267+
"label": "build-json-client", // Builds ONLY the Windows Forms .NET demo explorer (windows only)
268+
"type": "process",
269+
"group": "build",
270+
"command": "dotnet",
271+
"args": [
272+
"build",
273+
"${workspaceFolder}/src/demos/clients/Net/JsonApi",
260274
"/property:GenerateFullPaths=true",
261275
"/consoleloggerparameters:NoSummary"
262276
],
@@ -293,7 +307,7 @@
293307
"label": "start-explorer", // Starts the Explorer Windows form app. No building or launching of API server done.
294308
"group": "none",
295309
// Windows form apps only work in Windows
296-
"command": "${workspaceFolder}/src/demos/clients/Net/CodeProject.AI.Explorer/bin/Debug/net8.0-windows/win-x64/",
310+
"command": "${workspaceFolder}/src/demos/clients/Net/AiExplorer/bin/Debug/net8.0-windows/win-x64/",
297311
"args": [],
298312
"type": "process"
299313
},

CodeProject.AI.sln

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotNetSimple", "src\demos\m
181181
EndProject
182182
Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "PythonSimple", "src\demos\modules\PythonSimple\PythonSimple.pyproj", "{6AE28B59-221B-4E3D-A66C-E255B26DAC92}"
183183
EndProject
184-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodeProject.AI.Explorer", "src\demos\clients\Net\CodeProject.AI.Explorer\CodeProject.AI.Explorer.csproj", "{1DB03AEC-8318-4F36-9A4B-FCC5BE00A029}"
184+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AiExplorer", "src\demos\clients\Net\AiExplorer\AiExplorer.csproj", "{1DB03AEC-8318-4F36-9A4B-FCC5BE00A029}"
185185
EndProject
186186
Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "Face", "src\demos\clients\Python\Face\Face.pyproj", "{C2500118-FD99-49EF-B726-3E2A3B30A717}"
187187
EndProject
@@ -251,8 +251,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "utils", "utils", "{B2D0FCB2
251251
devops\utils\stop_all.sh = devops\utils\stop_all.sh
252252
EndProjectSection
253253
EndProject
254-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LlamaChatConsole", "src\demos\clients\Net\LlamaChatConsole\LlamaChatConsole.csproj", "{484D0804-BB60-4F8E-99B5-5779B10631D8}"
255-
EndProject
256254
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Go", "Go", "{1E0E93ED-1CBF-4D0D-AFD9-A91ECDB3BBF2}"
257255
ProjectSection(SolutionItems) = preProject
258256
src\demos\clients\Go\object-detect.go = src\demos\clients\Go\object-detect.go
@@ -325,7 +323,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "httpFiles", "httpFiles", "{
325323
jsonPayload.http = jsonPayload.http
326324
EndProjectSection
327325
EndProject
328-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CpaiJsonApiCall", "src\demos\clients\Net\CpaiJsonApiCall\CpaiJsonApiCall.csproj", "{7BFCEBCA-0677-4122-B474-B08D958F7FC7}"
326+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JsonApi", "src\demos\clients\Net\JsonApi\JsonApi.csproj", "{7BFCEBCA-0677-4122-B474-B08D958F7FC7}"
329327
EndProject
330328
Global
331329
GlobalSection(SolutionConfigurationPlatforms) = preSolution

src/demos/clients/Net/AiExplorer/AiExplorer.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<PropertyGroup>
77
<RootNamespace>CodeProject.AI.Explorer</RootNamespace>
8-
<AssemblyName>CodeProject.AI.Explorer</AssemblyName>
8+
<AssemblyName>AiExplorer</AssemblyName>
99
<OutputType>WinExe</OutputType>
1010
<Nullable>enable</Nullable>
1111
<UseWindowsForms>true</UseWindowsForms>

src/demos/clients/Net/AiExplorer/Properties/launchSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"profiles": {
3-
"CodeProject.AI.Explorer": {
3+
"AiExplorer": {
44
"commandName": "Project",
55
"commandLineArgs": "--MODE=high"
66
}

src/demos/clients/Net/JsonAPI/Program.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@
33
using System.Net.Http.Headers;
44
using System.Text;
55

6-
var filename = ".\\images\\study-group.jpg";
6+
// A demonstration of sending a request to CodeProject.AI Server as JSON instead
7+
// of FormData.
8+
9+
string filename = "./images/study-group.jpg";
710
using var httpClient = new HttpClient()
811
{
912
BaseAddress = new Uri("http://localhost:32168/v1/"),
10-
Timeout = TimeSpan.FromMinutes(5),
13+
Timeout = TimeSpan.FromSeconds(30),
1114
};
1215
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
16+
17+
1318
string result;
1419

1520
// Image detection
@@ -20,7 +25,7 @@
2025
Console.WriteLine(result);
2126

2227
// Sentiment Analysis
23-
Console.WriteLine($"Sending {filename} to 'vision/detection'");
28+
Console.WriteLine($"Sending {filename} to 'text/sentiment'");
2429
var sentimentPayload = new RequestPayload();
2530
string textValue = "This movie was the worst thing since 'Green Lantern'.";
2631
Console.WriteLine($"\nSending '{textValue}' to 'text/sentiment'.");
@@ -31,6 +36,13 @@
3136
Console.WriteLine("Press ENTER to exit.");
3237
Console.ReadLine();
3338

39+
/// <summary>
40+
/// Sends a JSON payload to CodeProject.AI Server and returns the result as a
41+
/// JSON string.
42+
/// </summary>
43+
/// <param name="url">The URL of the AI server endpoint</param>
44+
/// <param name="payload">The request payload</param>
45+
/// <returns>The result as a JSON string</returns>
3446
async Task<string> SendPayload( string url, RequestPayload payload)
3547
{
3648
string json = System.Text.Json.JsonSerializer.Serialize(payload);
@@ -40,5 +52,4 @@ async Task<string> SendPayload( string url, RequestPayload payload)
4052
using var response = await httpClient.PostAsync(url, content);
4153
var result = await response.Content.ReadAsStringAsync();
4254
return result;
43-
}
44-
55+
}

src/scripts/utils.sh

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -718,12 +718,21 @@ function setupDotNet () {
718718
return 6 # unable to download required asset
719719
fi
720720

721+
if [ "$architecture" = 'arm64' ]; then
722+
dotnet_path="/opt/dotnet"
723+
elif [ "$os" = "linux" ]; then
724+
dotnet_path="/usr/lib/dotnet/"
725+
else
726+
# dotnet_path="/usr/lib/dotnet/"
727+
# dotnet_path="~/.dotnet/"
728+
dotnet_path="/usr/local/share/dotnet/"
729+
fi
730+
721731
# output a warning message if no admin rights and instruct user on manual steps
722732
if [ "$architecture" = 'arm64' ]; then
723-
# installs in /opt/dotnet
724733
install_instructions="sudo bash '${installScriptsDirPath}/dotnet-install-arm.sh' $requestedNetMajorMinorVersion $requestedType"
725734
else
726-
install_instructions="sudo bash '${installScriptsDirPath}/dotnet-install.sh' --install-dir '/usr/lib/dotnet/' --channel $requestedNetMajorMinorVersion --runtime $requestedType"
735+
install_instructions="sudo bash '${installScriptsDirPath}/dotnet-install.sh' --install-dir '${dotnet_path}' --channel $requestedNetMajorMinorVersion --runtime $requestedType"
727736
fi
728737
checkForAdminAndWarn "$install_instructions"
729738

@@ -752,21 +761,21 @@ function setupDotNet () {
752761
fi
753762
else
754763
if [ $verbosity = "quiet" ]; then
755-
sudo bash "${installScriptsDirPath}/dotnet-install.sh" --install-dir "/usr/lib/dotnet/" --channel "$requestedNetMajorMinorVersion" --runtime "$requestedType" "--quiet"
764+
sudo bash "${installScriptsDirPath}/dotnet-install.sh" --install-dir "$dotnet_path" --channel "$requestedNetMajorMinorVersion" --runtime "$requestedType" "--quiet"
756765
elif [ $verbosity = "loud" ]; then
757-
sudo bash "${installScriptsDirPath}/dotnet-install.sh" --install-dir "/usr/lib/dotnet/" --channel "$requestedNetMajorMinorVersion" --runtime "$requestedType" "--verbose"
766+
sudo bash "${installScriptsDirPath}/dotnet-install.sh" --install-dir "$dotnet_path" --channel "$requestedNetMajorMinorVersion" --runtime "$requestedType" "--verbose"
758767
else
759-
sudo bash "${installScriptsDirPath}/dotnet-install.sh" --install-dir "/usr/lib/dotnet/" --channel "$requestedNetMajorMinorVersion" --runtime "$requestedType"
768+
sudo bash "${installScriptsDirPath}/dotnet-install.sh" --install-dir "$dotnet_path" --channel "$requestedNetMajorMinorVersion" --runtime "$requestedType"
760769
fi
761770
fi
762771
fi
763772
else
764773
if [ $verbosity = "quiet" ]; then
765-
sudo bash "${installScriptsDirPath}/dotnet-install.sh" --install-dir "/usr/lib/dotnet/" --channel "$requestedNetMajorMinorVersion" --runtime "$requestedType" "--quiet"
774+
sudo bash "${installScriptsDirPath}/dotnet-install.sh" --install-dir "${dotnet_path}" --channel "$requestedNetMajorMinorVersion" --runtime "$requestedType" "--quiet"
766775
elif [ $verbosity = "loud" ]; then
767-
sudo bash "${installScriptsDirPath}/dotnet-install.sh" --install-dir "/usr/lib/dotnet/" --channel "$requestedNetMajorMinorVersion" --runtime "$requestedType" "--verbose"
776+
sudo bash "${installScriptsDirPath}/dotnet-install.sh" --install-dir "${dotnet_path}" --channel "$requestedNetMajorMinorVersion" --runtime "$requestedType" "--verbose"
768777
else
769-
sudo bash "${installScriptsDirPath}/dotnet-install.sh" --install-dir "/usr/lib/dotnet/" --channel "$requestedNetMajorMinorVersion" --runtime "$requestedType"
778+
sudo bash "${installScriptsDirPath}/dotnet-install.sh" --install-dir "${dotnet_path}" --channel "$requestedNetMajorMinorVersion" --runtime "$requestedType"
770779
fi
771780
fi
772781
fi
@@ -795,17 +804,24 @@ function setupDotNet () {
795804
if [ "$os" == "macos" ]; then
796805
# The install script is for CI/CD and doesn't actually register .NET. So add
797806
# link and env variable
798-
export DOTNET_ROOT=~/.dotnet
807+
export DOTNET_ROOT=${dotnet_path}
799808
export PATH=${DOTNET_ROOT}${PATH:+:${PATH}}
800809

801810
if [ ! -e /usr/local/bin/dotnet ]; then
802-
ln -fs ~/.dotnet/dotnet /usr/local/bin/dotnet
811+
ln -fs "${dotnet_path}dotnet" "/usr/local/bin/dotnet"
803812
fi
804813

805-
if grep -q 'export DOTNET_ROOT=' ~/.bashrc; then
806-
echo 'export DOTNET_ROOT=~/.dotnet' >> ~/.bashrc
807-
echo "export PATH=${DOTNET_ROOT}${PATH:+:${PATH}}" >> ~/.bashrc
808-
fi
814+
# if [ -f ~/.bashrc ]; then
815+
if [ ! -f ~/.bashrc ] || [ $(grep -q 'export DOTNET_ROOT=' ~/.bashrc) ]; then
816+
sudo echo "export DOTNET_ROOT=${dotnet_path}" >> ~/.bashrc
817+
sudo echo "export PATH=${dotnet_path}${PATH:+:${PATH}}" >> ~/.bashrc
818+
fi
819+
# elif [ -f ~/.bash_profile ]; then
820+
# if grep -q 'export DOTNET_ROOT=' ~/.bash_profile; then
821+
# echo 'export DOTNET_ROOT=${dotnet_path}' >> ~/.bash_profile
822+
# echo "export PATH=${dotnet_path}${PATH:+:${PATH}}" >> ~/.bash_profile
823+
# fi
824+
# fi
809825
fi
810826
fi
811827

0 commit comments

Comments
 (0)