Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
Layoric committed Nov 26, 2024
2 parents b93f3ea + bc27043 commit a019ae5
Show file tree
Hide file tree
Showing 53 changed files with 379 additions and 223 deletions.
11 changes: 0 additions & 11 deletions MyApp/Pages/Shared/AsciiCinemaIncludes.cshtml
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>
7 changes: 7 additions & 0 deletions MyApp/Pages/Shared/DocsPage.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,13 @@ if (document.querySelector('.hide-title')) {
}
</script>

@*Only load additional deps for pages with custom .mjs*@
@if (docMjs != null)
{
@await Html.PartialAsync("MermaidIncludes")
@await Html.PartialAsync("AsciiCinemaIncludes")
}

<script type="module">
import { ref } from "vue"
import { mount } from "app.mjs"
Expand Down
19 changes: 9 additions & 10 deletions MyApp/_includes/ai-server/cs/ai-server-compatible-1.cs.md
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;
```
9 changes: 4 additions & 5 deletions MyApp/_includes/ai-server/cs/convert-image-1.cs.md
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());
```
9 changes: 4 additions & 5 deletions MyApp/_includes/ai-server/cs/convert-video-1.cs.md
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());
```
10 changes: 5 additions & 5 deletions MyApp/_includes/ai-server/cs/crop-image-1.cs.md
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);
```
9 changes: 4 additions & 5 deletions MyApp/_includes/ai-server/cs/crop-video-1.cs.md
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());
```
9 changes: 5 additions & 4 deletions MyApp/_includes/ai-server/cs/image-to-image-1.cs.md
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);
```
6 changes: 3 additions & 3 deletions MyApp/_includes/ai-server/cs/image-to-text-1.cs.md
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"));
```
9 changes: 5 additions & 4 deletions MyApp/_includes/ai-server/cs/image-upscale-1.cs.md
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());
```
13 changes: 8 additions & 5 deletions MyApp/_includes/ai-server/cs/image-with-mask-1.cs.md
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());
```
25 changes: 14 additions & 11 deletions MyApp/_includes/ai-server/cs/open-ai-requests-1.cs.md
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);
```
15 changes: 15 additions & 0 deletions MyApp/_includes/ai-server/cs/openaichatcompletion-1.cs.md
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
});
```
15 changes: 7 additions & 8 deletions MyApp/_includes/ai-server/cs/queue-convert-image-1.cs.md
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());
```
15 changes: 7 additions & 8 deletions MyApp/_includes/ai-server/cs/queue-crop-image-1.cs.md
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());
```
12 changes: 6 additions & 6 deletions MyApp/_includes/ai-server/cs/queue-crop-video-1.cs.md
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());
```
18 changes: 15 additions & 3 deletions MyApp/_includes/ai-server/cs/queue-image-to-image-1.cs.md
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());
}
```
18 changes: 15 additions & 3 deletions MyApp/_includes/ai-server/cs/queue-image-to-text-1.cs.md
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;
}
```
18 changes: 15 additions & 3 deletions MyApp/_includes/ai-server/cs/queue-image-upscale-1.cs.md
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 MyApp/_includes/ai-server/cs/queue-image-with-mask-1.cs.md
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());
}
```
Loading

0 comments on commit a019ae5

Please sign in to comment.