Skip to content

Commit

Permalink
Improve ipc (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
SommerEngineering authored Sep 1, 2024
1 parent 47f5756 commit fc64c0b
Show file tree
Hide file tree
Showing 81 changed files with 2,413 additions and 804 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/build-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ jobs:
uses: actions/cache@v4
id: linux_arm_cache
with:
path: $RUNNER_TEMP/linux_arm_qemu_cache.img
path: ${{ runner.temp }}/linux_arm_qemu_cache.img

# When the entire key matches, Rust might just create the bundles using the current .NET build:
key: target-linux-arm64-rust-${{ env.RUST_VERSION }}-dependencies-${{ env.CARGO_LOCK_HASH }}
Expand Down Expand Up @@ -544,15 +544,15 @@ jobs:
- name: Add the built runner image to the cache
if: ${{ steps.linux_arm_cache.outputs.cache-hit != 'true' && env.SKIP != 'true' }}
run: |
mv ${{ steps.build-linux-arm-runner.outputs.image }} $RUNNER_TEMP/linux_arm_qemu_cache.img
mv ${{ steps.build-linux-arm-runner.outputs.image }} ${{ runner.temp }}/linux_arm_qemu_cache.img
- name: Build Tauri project
if: ${{ env.SKIP != 'true' }}
uses: pguyot/arm-runner-action@v2
id: build-linux-arm

with:
base_image: file://$RUNNER_TEMP/linux_arm_qemu_cache.img
base_image: file://${{ runner.temp }}/linux_arm_qemu_cache.img
cpu: cortex-a53
optimize_image: false
copy_artifact_path: runtime
Expand Down Expand Up @@ -845,8 +845,8 @@ jobs:
- name: Create release
uses: softprops/action-gh-release@v2
with:
prerelease: false
draft: false
prerelease: true
draft: true
make_latest: true
body: ${{ env.CHANGELOG }}
name: "Release ${{ env.FORMATTED_VERSION }}"
Expand Down
9 changes: 4 additions & 5 deletions app/MindWork AI Studio/Agents/AgentBase.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
using AIStudio.Chat;
using AIStudio.Provider;
using AIStudio.Settings;
using AIStudio.Tools;

// ReSharper disable MemberCanBePrivate.Global

namespace AIStudio.Agents;

public abstract class AgentBase(SettingsManager settingsManager, IJSRuntime jsRuntime, ThreadSafeRandom rng) : IAgent
public abstract class AgentBase(ILogger<AgentBase> logger, SettingsManager settingsManager, ThreadSafeRandom rng) : IAgent
{
protected SettingsManager SettingsManager { get; init; } = settingsManager;

protected IJSRuntime JsRuntime { get; init; } = jsRuntime;

protected ThreadSafeRandom RNG { get; init; } = rng;

protected ILogger<AgentBase> Logger { get; init; } = logger;

/// <summary>
/// Represents the type or category of this agent.
Expand Down Expand Up @@ -104,6 +103,6 @@ protected async Task AddAIResponseAsync(ChatThread thread, DateTimeOffset time)
// Use the selected provider to get the AI response.
// By awaiting this line, we wait for the entire
// content to be streamed.
await aiText.CreateFromProviderAsync(providerSettings.CreateProvider(), this.JsRuntime, this.SettingsManager, providerSettings.Model, thread);
await aiText.CreateFromProviderAsync(providerSettings.CreateProvider(this.Logger), this.SettingsManager, providerSettings.Model, thread);
}
}
3 changes: 1 addition & 2 deletions app/MindWork AI Studio/Agents/AgentTextContentCleaner.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using AIStudio.Chat;
using AIStudio.Settings;
using AIStudio.Tools;

namespace AIStudio.Agents;

public sealed class AgentTextContentCleaner(SettingsManager settingsManager, IJSRuntime jsRuntime, ThreadSafeRandom rng) : AgentBase(settingsManager, jsRuntime, rng)
public sealed class AgentTextContentCleaner(ILogger<AgentBase> logger, SettingsManager settingsManager, ThreadSafeRandom rng) : AgentBase(logger, settingsManager, rng)
{
private static readonly ContentBlock EMPTY_BLOCK = new()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Text;

using AIStudio.Chat;
using AIStudio.Tools;

namespace AIStudio.Assistants.Agenda;

Expand Down
14 changes: 9 additions & 5 deletions app/MindWork AI Studio/Assistants/AssistantBase.razor.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
using AIStudio.Chat;
using AIStudio.Provider;
using AIStudio.Settings;
using AIStudio.Tools;

using Microsoft.AspNetCore.Components;

using RustService = AIStudio.Tools.RustService;

namespace AIStudio.Assistants;

public abstract partial class AssistantBase : ComponentBase
{
[Inject]
protected SettingsManager SettingsManager { get; set; } = null!;
protected SettingsManager SettingsManager { get; init; } = null!;

[Inject]
protected IJSRuntime JsRuntime { get; init; } = null!;
Expand All @@ -22,11 +23,14 @@ public abstract partial class AssistantBase : ComponentBase
protected ISnackbar Snackbar { get; init; } = null!;

[Inject]
protected Rust Rust { get; init; } = null!;
protected RustService RustService { get; init; } = null!;

[Inject]
protected NavigationManager NavigationManager { get; init; } = null!;

[Inject]
protected ILogger<AssistantBase> Logger { get; init; } = null!;

internal const string AFTER_RESULT_DIV_ID = "afterAssistantResult";
internal const string RESULT_DIV_ID = "assistantResult";

Expand Down Expand Up @@ -151,7 +155,7 @@ protected async Task<string> AddAIResponseAsync(DateTimeOffset time)
// Use the selected provider to get the AI response.
// By awaiting this line, we wait for the entire
// content to be streamed.
await aiText.CreateFromProviderAsync(this.providerSettings.CreateProvider(), this.JsRuntime, this.SettingsManager, this.providerSettings.Model, this.chatThread);
await aiText.CreateFromProviderAsync(this.providerSettings.CreateProvider(this.Logger), this.SettingsManager, this.providerSettings.Model, this.chatThread);

this.isProcessing = false;
this.StateHasChanged();
Expand All @@ -162,7 +166,7 @@ protected async Task<string> AddAIResponseAsync(DateTimeOffset time)

protected async Task CopyToClipboard()
{
await this.Rust.CopyText2Clipboard(this.JsRuntime, this.Snackbar, this.Result2Copy());
await this.RustService.CopyText2Clipboard(this.Snackbar, this.Result2Copy());
}

private static string? GetButtonIcon(string icon)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System.Text;

using AIStudio.Tools;

namespace AIStudio.Assistants.Coding;

public partial class AssistantCoding : AssistantBaseCore
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Text;

using AIStudio.Chat;
using AIStudio.Tools;

namespace AIStudio.Assistants.EMail;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using AIStudio.Chat;
using AIStudio.Tools;

namespace AIStudio.Assistants.GrammarSpelling;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using AIStudio.Tools;

namespace AIStudio.Assistants.IconFinder;

public partial class AssistantIconFinder : AssistantBaseCore
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using AIStudio.Tools;

namespace AIStudio.Assistants.LegalCheck;

public partial class AssistantLegalCheck : AssistantBaseCore
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using AIStudio.Chat;
using AIStudio.Tools;

namespace AIStudio.Assistants.RewriteImprove;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using AIStudio.Chat;
using AIStudio.Tools;

namespace AIStudio.Assistants.TextSummarizer;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using AIStudio.Chat;
using AIStudio.Tools;

namespace AIStudio.Assistants.Translation;

Expand Down
11 changes: 4 additions & 7 deletions app/MindWork AI Studio/Chat/ContentBlockComponent.razor.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using AIStudio.Tools;

using Microsoft.AspNetCore.Components;

using RustService = AIStudio.Tools.RustService;

namespace AIStudio.Chat;

/// <summary>
Expand Down Expand Up @@ -40,10 +40,7 @@ public partial class ContentBlockComponent : ComponentBase
public string Class { get; set; } = string.Empty;

[Inject]
private Rust Rust { get; init; } = null!;

[Inject]
private IJSRuntime JsRuntime { get; init; } = null!;
private RustService RustService { get; init; } = null!;

[Inject]
private ISnackbar Snackbar { get; init; } = null!;
Expand Down Expand Up @@ -100,7 +97,7 @@ private async Task CopyToClipboard()
{
case ContentType.TEXT:
var textContent = (ContentText) this.Content;
await this.Rust.CopyText2Clipboard(this.JsRuntime, this.Snackbar, textContent.Text);
await this.RustService.CopyText2Clipboard(this.Snackbar, textContent.Text);
break;

default:
Expand Down
2 changes: 1 addition & 1 deletion app/MindWork AI Studio/Chat/ContentImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public sealed class ContentImage : IContent
public Func<Task> StreamingEvent { get; set; } = () => Task.CompletedTask;

/// <inheritdoc />
public Task CreateFromProviderAsync(IProvider provider, IJSRuntime jsRuntime, SettingsManager settings, Model chatModel, ChatThread chatChatThread, CancellationToken token = default)
public Task CreateFromProviderAsync(IProvider provider, SettingsManager settings, Model chatModel, ChatThread chatChatThread, CancellationToken token = default)
{
throw new NotImplementedException();
}
Expand Down
10 changes: 5 additions & 5 deletions app/MindWork AI Studio/Chat/ContentText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,26 @@ public sealed class ContentText : IContent
public Func<Task> StreamingEvent { get; set; } = () => Task.CompletedTask;

/// <inheritdoc />
public async Task CreateFromProviderAsync(IProvider provider, IJSRuntime jsRuntime, SettingsManager settings, Model chatModel, ChatThread? chatThread, CancellationToken token = default)
public async Task CreateFromProviderAsync(IProvider provider, SettingsManager settings, Model chatModel, ChatThread? chatThread, CancellationToken token = default)
{
if(chatThread is null)
return;

// Store the last time we got a response. We use this later,
// Store the last time we got a response. We use this ater
// to determine whether we should notify the UI about the
// new content or not. Depends on the energy saving mode
// the user chose.
var last = DateTimeOffset.Now;

// Start another thread by using a task, to uncouple
// Start another thread by using a task to uncouple
// the UI thread from the AI processing:
await Task.Run(async () =>
{
// We show the waiting animation until we get the first response:
this.InitialRemoteWait = true;

// Iterate over the responses from the AI:
await foreach (var deltaText in provider.StreamChatCompletion(jsRuntime, settings, chatModel, chatThread, token))
await foreach (var deltaText in provider.StreamChatCompletion(chatModel, chatThread, token))
{
// When the user cancels the request, we stop the loop:
if (token.IsCancellationRequested)
Expand Down Expand Up @@ -89,7 +89,7 @@ await Task.Run(async () =>
}

// Stop the waiting animation (in case the loop
// was stopped or no content was received):
// was stopped, or no content was received):
this.InitialRemoteWait = false;
this.IsStreaming = false;
}, token);
Expand Down
2 changes: 1 addition & 1 deletion app/MindWork AI Studio/Chat/IContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ public interface IContent
/// <summary>
/// Uses the provider to create the content.
/// </summary>
public Task CreateFromProviderAsync(IProvider provider, IJSRuntime jsRuntime, SettingsManager settings, Model chatModel, ChatThread chatChatThread, CancellationToken token = default);
public Task CreateFromProviderAsync(IProvider provider, SettingsManager settings, Model chatModel, ChatThread chatChatThread, CancellationToken token = default);
}
1 change: 1 addition & 0 deletions app/MindWork AI Studio/Components/Changelog.Logs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public readonly record struct Log(int Build, string Display, string Filename)

public static readonly Log[] LOGS =
[
new (175, "v0.9.0, build 175 (2024-09-01 18:04 UTC)", "v0.9.0.md"),
new (174, "v0.8.12, build 174 (2024-08-24 08:30 UTC)", "v0.8.12.md"),
new (173, "v0.8.11, build 173 (2024-08-21 07:03 UTC)", "v0.8.11.md"),
new (172, "v0.8.10, build 172 (2024-08-18 19:44 UTC)", "v0.8.10.md"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using AIStudio.Settings;
using AIStudio.Tools;

using Microsoft.AspNetCore.Components;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using AIStudio.Settings;
using AIStudio.Tools;

using Microsoft.AspNetCore.Components;

Expand Down
1 change: 0 additions & 1 deletion app/MindWork AI Studio/Components/InnerScrolling.razor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using AIStudio.Layout;
using AIStudio.Tools;

using Microsoft.AspNetCore.Components;

Expand Down
2 changes: 0 additions & 2 deletions app/MindWork AI Studio/Components/MSGComponentBase.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using AIStudio.Tools;

using Microsoft.AspNetCore.Components;

namespace AIStudio.Components;
Expand Down
2 changes: 0 additions & 2 deletions app/MindWork AI Studio/Components/ProcessComponent.razor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using AIStudio.Tools;

using Microsoft.AspNetCore.Components;

namespace AIStudio.Components;
Expand Down
1 change: 0 additions & 1 deletion app/MindWork AI Studio/Components/ReadWebContent.razor.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using AIStudio.Agents;
using AIStudio.Chat;
using AIStudio.Settings;
using AIStudio.Tools;

using Microsoft.AspNetCore.Components;

Expand Down
6 changes: 4 additions & 2 deletions app/MindWork AI Studio/Components/Workspaces.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using AIStudio.Chat;
using AIStudio.Dialogs;
using AIStudio.Settings;
using AIStudio.Tools;

using Microsoft.AspNetCore.Components;

Expand All @@ -24,6 +23,9 @@ public partial class Workspaces : ComponentBase
[Inject]
private ThreadSafeRandom RNG { get; init; } = null!;

[Inject]
private ILogger<Workspaces> Logger { get; init; } = null!;

[Parameter]
public ChatThread? CurrentChatThread { get; set; }

Expand Down Expand Up @@ -309,7 +311,7 @@ public async Task StoreChat(ChatThread chat)
}
catch (Exception e)
{
Console.WriteLine(e);
this.Logger.LogError($"Failed to load chat from '{chatPath}': {e.Message}");
}

return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
@using AIStudio.Components
@using AIStudio.Provider
@using AIStudio.Provider.SelfHosted
@using MudBlazor

<MudDialog>
<DialogContent>
Expand Down
Loading

0 comments on commit fc64c0b

Please sign in to comment.