Skip to content

Commit

Permalink
Added missing files
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusz-kierepka-hl committed Jan 11, 2025
1 parent 0a17030 commit f530180
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
Binary file added ChatAAC/Assets/Samples/communikate-20_pl.obz
Binary file not shown.
Binary file added ChatAAC/Assets/folder-arrow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions ChatAAC/Services/AiService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using ChatAAC.Models;

namespace ChatAAC.Services;

public class AiService
{
private readonly OllamaClient _ollamaClient = new();
private readonly ITtsService _ttsService = InitializeTtsService();


private static ITtsService InitializeTtsService()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
return new MacTtsService();
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
return new WindowsTtsService();
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
return new LinuxTtsService();

throw new PlatformNotSupportedException("The platform is not supported for TTS.");
}

public async Task<string> GetAiResponseAsync(string prompt, string form, string tense)
{
var chatRequest = new ChatRequest
{
Prompt = prompt,
Form = form,
Tense = tense
};

var response = await _ollamaClient.ChatAsync(chatRequest);
return await CombineResponseAsync(response);
}

public async Task SpeakResponseAsync(string response)
{
await _ttsService.SpeakAsync(response);
}

private static async Task<string> CombineResponseAsync(IAsyncEnumerable<string> responseStream)
{
var builder = new StringBuilder();
await foreach (var chunk in responseStream)
builder.Append(chunk);

return builder.ToString();
}
}

0 comments on commit f530180

Please sign in to comment.