generated from NetCoreTemplates/razor-ssg
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main'
- Loading branch information
Showing
53 changed files
with
379 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,2 @@ | ||
<link rel="stylesheet" href="/css/asciinema-player.css"> | ||
<script src="/lib/js/asciinema-player.js"></script> | ||
<script> | ||
document.addEventListener("DOMContentLoaded", () => { | ||
document.querySelectorAll('[data-asciicinema]').forEach(el => { | ||
const path = el.dataset.asciicinema | ||
const options = el.dataset.options | ||
? new Function(`return (${el.dataset.options})`)() | ||
: { loop: true, poster:'npt:00:01' } | ||
AsciinemaPlayer.create(path, el, options) | ||
}) | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
```csharp | ||
var apiClient = GetLocalApiClient("https://localhost:5005"); | ||
apiClient.BearerToken = Environment.GetEnvironmentVariable("AI_SERVER_API_KEY"); | ||
var client = GetLocalApiClient(AiServerUrl); | ||
|
||
var response = await apiClient.PostAsync(new OpenAiChatCompletion { | ||
Model = "llama3:8b", | ||
Messages = new List<OpenAiMessage> | ||
{ | ||
new OpenAiMessage { Role = "system", Content = "You are a helpful AI assistant." }, | ||
new OpenAiMessage { Role = "user", Content = "How do LLMs work?" } | ||
}, | ||
var response = client.Post(new OpenAiChatCompletion { | ||
Model = "llama3.1:8b", | ||
Messages = | ||
[ | ||
new() { Role = "system", Content = "You are a helpful AI assistant." }, | ||
new() { Role = "user", Content = "How do LLMs work?" } | ||
], | ||
MaxTokens = 50 | ||
}); | ||
Console.WriteLine(response.Choices[0].Message.Content); | ||
var answer = response.Choices[0].Message.Content; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
```csharp | ||
var response = client.PostFilesWithRequest(new ConvertImage { | ||
using var fsImage = File.OpenRead("files/test_image.jpg"); | ||
var response = client.PostFileWithRequest(new ConvertImage { | ||
OutputFormat = ImageOutputFormat.Gif | ||
}, | ||
[new UploadFile("test_image.jpg", File.OpenRead("files/test_image.jpg"), "image")] | ||
); | ||
new UploadFile("test_image.jpg", fsImage, "image")); | ||
|
||
var videoUrl = response.Outputs[0].Url; | ||
videoUrl.DownloadFileTo(outputFileName); | ||
File.WriteAllBytes(saveToPath, response.Results[0].Url.GetBytesFromUrl()); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
```csharp | ||
var response = client.PostFilesWithRequest(new ConvertVideo { | ||
using var fsVideo = File.OpenRead("files/test_video.webm"); | ||
var response = client.PostFileWithRequest(new ConvertVideo { | ||
OutputFormat = ConvertVideoOutputFormat.MOV | ||
}, | ||
[new UploadFile("test_video.webm", File.OpenRead("files/test_video.webm"), "video")] | ||
); | ||
new UploadFile("test_video.webm", fsVideo, "video")); | ||
|
||
var videoUrl = response.Outputs[0].Url; | ||
videoUrl.DownloadFileTo(outputFileName); | ||
File.WriteAllBytes(saveToPath, response.Results[0].Url.GetBytesFromUrl()); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
```csharp | ||
var response = client.PostFilesWithRequest(new CropImage { | ||
using var fsImage = File.OpenRead("files/test_image.jpg"); | ||
var response = client.PostFileWithRequest(new CropImage { | ||
X = 50, | ||
Y = 50, | ||
Width = 150, | ||
Height = 150 | ||
}, | ||
[new UploadFile("test_image.jpg", File.OpenRead("files/test_image.jpg"), "image")] | ||
); | ||
new UploadFile("test_image.jpg", fsImage, "image")); | ||
|
||
var videoUrl = response.Outputs[0].Url; | ||
videoUrl.DownloadFileTo(outputFileName); | ||
var videoUrl = response.Results[0].Url; | ||
videoUrl.DownloadFileTo(saveToPath); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
```csharp | ||
var response = client.PostFilesWithRequest(new CropVideo { | ||
using var fsVideo = File.OpenRead("files/test_video.mp4"); | ||
var response = client.PostFileWithRequest(new CropVideo { | ||
X = 100, | ||
Y = 100, | ||
Width = 500, | ||
Height = 300 | ||
}, | ||
[new UploadFile("test_video.mp4", File.OpenRead("files/test_video.mp4"), "video")] | ||
); | ||
new UploadFile("test_video.mp4", fsVideo, "video")); | ||
|
||
var videoUrl = response.Outputs[0].Url; | ||
videoUrl.DownloadFileTo(outputFileName); | ||
File.WriteAllBytes(saveToPath, response.Results[0].Url.GetBytesFromUrl()); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
```csharp | ||
var response = client.PostFilesWithRequest(new ImageToImage { | ||
using var fsImage = File.OpenRead("files/comfyui_upload_test.png"); | ||
var response = client.PostFileWithRequest(new ImageToImage { | ||
PositivePrompt = "A beautiful sunset over the ocean", | ||
NegativePrompt = "A pixelated, low-quality image" | ||
}, | ||
[new UploadFile("image", File.OpenRead("files/comfyui_upload_test.png"), "image")] | ||
); | ||
response.Outputs[0].Url.DownloadFileTo(outputFileName); | ||
new UploadFile("image", fsImage, "image")); | ||
|
||
response.Results[0].Url.DownloadFileTo(outputFileName); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
```csharp | ||
var response = client.PostFilesWithRequest(new ImageToText(), | ||
[new UploadFile("image", File.OpenRead("files/test_image.jpg"), "image")] | ||
); | ||
using var fsImage = File.OpenRead("files/test_image.jpg"); | ||
var response = client.PostFileWithRequest(new ImageToText(), | ||
new UploadFile("image", fsImage, "image")); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
```csharp | ||
var response = client.PostFilesWithRequest(new ImageUpscale(), | ||
[new UploadFile("image", File.OpenRead("files/test_image.jpg"), "image")] | ||
); | ||
response.Outputs[0].Url.DownloadFileTo(outputFileName); | ||
using var fsImage = File.OpenRead("files/test_image.jpg"); | ||
var response = client.PostFileWithRequest(new ImageUpscale(), | ||
new UploadFile("image", fsImage, "image")); | ||
|
||
File.WriteAllBytes(saveToPath, response.Results[0].Url.GetBytesFromUrl()); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
```csharp | ||
using var fsImage = File.OpenRead("files/comfyui_upload_test.png"); | ||
using var fsMask = File.OpenRead("files/comfyui_upload_test_mask.png"); | ||
var response = client.PostFilesWithRequest(new ImageWithMask { | ||
PositivePrompt = "A beautiful sunset over the ocean", | ||
NegativePrompt = "A pixelated, low-quality image" | ||
}, | ||
[new UploadFile("image", File.OpenRead("files/comfyui_upload_test.png"), "image"), | ||
new UploadFile("mask", File.OpenRead("files/comfyui_upload_test_mask.png"), "mask")] | ||
); | ||
response.Outputs[0].Url.DownloadFileTo(outputFileName); | ||
}, [ | ||
new UploadFile("image", fsImage, "image"), | ||
new UploadFile("mask", fsMask, "mask") | ||
]); | ||
|
||
File.WriteAllBytes(saveToPath, response.Results[0].Url.GetBytesFromUrl()); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
```csharp | ||
var client = new JsonApiClient("https://api.openai.com/v1"); | ||
client.AddHeader("Authorization", "Bearer " + Environment.GetEnvironmentVariable("OPENAI_API_KEY")); | ||
var client = new JsonApiClient("https://api.openai.com"); | ||
client.BearerToken = Environment.GetEnvironmentVariable("OPENAI_API_KEY"); | ||
|
||
// Using AI Server DTOs with OpenAI API | ||
var response = await client.PostAsync<OpenAiChatResponse>("/chat/completions", | ||
new OpenAiChatCompletion { | ||
Model = "gpt-4-turbo", | ||
Messages = new List<OpenAiMessage> { | ||
new OpenAiMessage { Role = "system", Content = "You are a helpful AI assistant." }, | ||
new OpenAiMessage { Role = "user", Content = "How do LLMs work?" } | ||
}, | ||
MaxTokens = 50 | ||
}); | ||
var request = new OpenAiChatCompletion { | ||
Model = "gpt-4-turbo", | ||
Messages = [ | ||
new() { Role = "system", Content = "You are a helpful AI assistant." }, | ||
new() { Role = "user", Content = "What is the capital of France?" } | ||
], | ||
MaxTokens = 20 | ||
}; | ||
|
||
var response = await client.PostAsync<OpenAiChatResponse>( | ||
"/v1/chat/completions", | ||
request); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
```csharp | ||
var client = new JsonApiClient(baseUrl); | ||
client.BearerToken = apiKey; | ||
|
||
var api = await client.ApiAsync(new OpenAiChatCompletion { | ||
Model = "mixtral:8x22b", | ||
Messages = [ | ||
new() { | ||
Role = "user", | ||
Content = "What's the capital of France?" | ||
} | ||
], | ||
MaxTokens = 50 | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
```csharp | ||
var response = client.PostFilesWithRequest(new QueueConvertImage { | ||
using var fsImage = File.OpenRead("files/test_image.jpg"); | ||
var response = client.PostFileWithRequest(new QueueConvertImage { | ||
OutputFormat = ImageOutputFormat.Png | ||
}, | ||
[new UploadFile("test_image.jpg", File.OpenRead("files/test_image.jpg"), "image")] | ||
); | ||
new UploadFile("test_image.jpg", fsImage, "image")); | ||
|
||
var status = await client.GetAsync(new GetJobStatus { RefId = response.RefId }); | ||
GetArtifactGenerationStatusResponse status = new(); | ||
while (status.JobState is BackgroundJobState.Started or BackgroundJobState.Queued) | ||
{ | ||
status = await client.GetAsync(new GetArtifactGenerationStatus { RefId = response.RefId }); | ||
await Task.Delay(1000); | ||
status = await client.GetAsync(new GetJobStatus { RefId = response.RefId }); | ||
} | ||
|
||
// Download the converted video | ||
var videoUrl = status.Outputs[0].Url; | ||
videoUrl.DownloadFileTo(outputFileName); | ||
// Download the converted image | ||
File.WriteAllBytes(saveToPath, status.Results[0].Url.GetBytesFromUrl()); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,20 @@ | ||
```csharp | ||
var response = client.PostFilesWithRequest(new QueueCropImage { | ||
using var fsImage = File.OpenRead("files/test_image.jpg"); | ||
var response = client.PostFileWithRequest(new QueueCropImage { | ||
X = 50, | ||
Y = 50, | ||
Width = 150, | ||
Height = 150 | ||
}, | ||
[new UploadFile("test_image.jpg", File.OpenRead("files/test_image.jpg"), "image")] | ||
); | ||
new UploadFile("test_image.jpg", fsImage, "image")); | ||
|
||
var status = await client.GetAsync(new GetJobStatus { RefId = response.RefId }); | ||
GetArtifactGenerationStatusResponse status = new(); | ||
while (status.JobState is BackgroundJobState.Started or BackgroundJobState.Queued) | ||
{ | ||
status = await client.GetAsync(new GetArtifactGenerationStatus { RefId = response.RefId }); | ||
await Task.Delay(1000); | ||
status = await client.GetAsync(new GetJobStatus { RefId = response.RefId }); | ||
} | ||
|
||
// Download the cropped video | ||
var videoUrl = status.Outputs[0].Url; | ||
videoUrl.DownloadFileTo($"cropped-image-{status.RefId}.jpg"); | ||
// Download the cropped image | ||
File.WriteAllBytes(saveToPath, status.Results[0].Url.GetBytesFromUrl()); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
```csharp | ||
var response = client.PostFilesWithRequest(new QueueCropVideo { | ||
using var fsVideo = File.OpenRead("files/test_video.mp4"); | ||
var response = client.PostFileWithRequest(new QueueCropVideo { | ||
X = 100, | ||
Y = 100, | ||
Width = 500, | ||
Height = 300 | ||
}, | ||
[new UploadFile("test_video.mp4", File.OpenRead("files/test_video.mp4"), "video")] | ||
new UploadFile("test_video.mp4", fsVideo, "video") | ||
); | ||
|
||
var status = await client.GetAsync(new GetJobStatus { RefId = response.RefId }); | ||
GetArtifactGenerationStatusResponse status = new(); | ||
while (status.JobState is BackgroundJobState.Started or BackgroundJobState.Queued) | ||
{ | ||
status = await client.GetAsync(new GetArtifactGenerationStatus { RefId = response.RefId }); | ||
await Task.Delay(1000); | ||
status = await client.GetAsync(new GetJobStatus { RefId = response.RefId }); | ||
} | ||
|
||
// Download the cropped video | ||
var videoUrl = status.Outputs[0].Url; | ||
videoUrl.DownloadFileTo($"cropped-video-{status.RefId}.mp4"); | ||
File.WriteAllBytes(saveToPath, status.Results[0].Url.GetBytesFromUrl()); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,20 @@ | ||
```csharp | ||
var response = client.PostFilesWithRequest(new QueueImageToImage { | ||
using var fsImage = File.OpenRead("files/comfyui_upload_test.png"); | ||
var response = client.PostFileWithRequest(new QueueImageToImage { | ||
PositivePrompt = "A beautiful sunset over the ocean", | ||
NegativePrompt = "A pixelated, low-quality image" | ||
}, | ||
[new UploadFile("image", File.OpenRead("files/comfyui_upload_test.png"), "image")] | ||
); | ||
new UploadFile("image", fsImage, "image")); | ||
|
||
// Poll for Job Completion Status | ||
GetArtifactGenerationStatusResponse status = new(); | ||
while (status.JobState is BackgroundJobState.Queued or BackgroundJobState.Started) | ||
{ | ||
status = client.Get(new GetArtifactGenerationStatus { JobId = response.JobId }); | ||
Thread.Sleep(1000); | ||
} | ||
if (status.Results?.Count > 0) | ||
{ | ||
File.WriteAllBytes(saveToPath, status.Results[0].Url.GetBytesFromUrl()); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,17 @@ | ||
```csharp | ||
var response = client.PostFilesWithRequest(new QueueImageToText(), | ||
[new UploadFile("image", File.OpenRead("files/test_image.jpg"), "image")] | ||
); | ||
using var fsImage = File.OpenRead("files/test_image.jpg"); | ||
var response = client.PostFileWithRequest(new QueueImageToText(), | ||
new UploadFile("image", fsImage, "image")); | ||
|
||
// Poll for Job Completion Status | ||
GetTextGenerationStatusResponse status = new(); | ||
while (status.JobState is BackgroundJobState.Queued or BackgroundJobState.Started) | ||
{ | ||
status = client.Get(new GetTextGenerationStatus { JobId = response.JobId }); | ||
Thread.Sleep(1000); | ||
} | ||
if (status.Results?.Count > 0) | ||
{ | ||
var answer = status.Results[0].Text; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,17 @@ | ||
```csharp | ||
var response = client.PostFilesWithRequest(new QueueImageUpscale(), | ||
[new UploadFile("image", File.OpenRead("files/test_image.jpg"), "image")] | ||
); | ||
using var fsImage = File.OpenRead("files/test_image.jpg"); | ||
var response = client.PostFileWithRequest(new QueueImageUpscale(), | ||
new UploadFile("image", fsImage, "image")); | ||
|
||
// Poll for Job Completion Status | ||
GetArtifactGenerationStatusResponse status = new(); | ||
while (status.JobState is BackgroundJobState.Queued or BackgroundJobState.Started) | ||
{ | ||
status = client.Get(new GetArtifactGenerationStatus { JobId = response.JobId }); | ||
Thread.Sleep(1000); | ||
} | ||
if (status.Results?.Count > 0) | ||
{ | ||
File.WriteAllBytes(saveToPath, status.Results[0].Url.GetBytesFromUrl()); | ||
} | ||
``` |
22 changes: 18 additions & 4 deletions
22
MyApp/_includes/ai-server/cs/queue-image-with-mask-1.cs.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,23 @@ | ||
```csharp | ||
using var fsImage = File.OpenRead("files/comfyui_upload_test.png"); | ||
using var fsMask = File.OpenRead("files/comfyui_upload_test_mask.png"); | ||
var response = client.PostFilesWithRequest(new QueueImageWithMask { | ||
PositivePrompt = "A beautiful sunset over the ocean", | ||
NegativePrompt = "A pixelated, low-quality image" | ||
}, | ||
[new UploadFile("image", File.OpenRead("files/comfyui_upload_test.png"), "image"), | ||
new UploadFile("mask", File.OpenRead("files/comfyui_upload_test_mask.png"), "mask")] | ||
); | ||
}, [ | ||
new UploadFile("image", fsImage, "image"), | ||
new UploadFile("mask", fsMask, "mask") | ||
]); | ||
|
||
// Poll for Job Completion Status | ||
GetArtifactGenerationStatusResponse status = new(); | ||
while (status.JobState is BackgroundJobState.Queued or BackgroundJobState.Started) | ||
{ | ||
status = client.Get(new GetArtifactGenerationStatus { JobId = response.JobId }); | ||
Thread.Sleep(1000); | ||
} | ||
if (status.Results?.Count > 0) | ||
{ | ||
File.WriteAllBytes(saveToPath, status.Results[0].Url.GetBytesFromUrl()); | ||
} | ||
``` |
Oops, something went wrong.