Skip to content

Commit 21b8de2

Browse files
author
Chris Maunder
committed
Updated JsonAPI demo client
1 parent 43947b9 commit 21b8de2

File tree

6 files changed

+69
-15
lines changed

6 files changed

+69
-15
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: 1 addition & 1 deletion
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

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+
}

0 commit comments

Comments
 (0)