Skip to content

Commit

Permalink
Initial import of ChatGPT core code
Browse files Browse the repository at this point in the history
Add simple repl for testing blyss chat

Move to AI folder

Remove config
  • Loading branch information
wieslawsoltes committed Jan 29, 2024
1 parent 7cdbda3 commit 296fb21
Show file tree
Hide file tree
Showing 74 changed files with 4,422 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,7 @@
<PackageVersion Include="Moq" Version="[4.18.4]" />
<PackageVersion Include="xunit" Version="2.5.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.0" />
<!-- ChatGPT. -->
<PackageVersion Include="CommunityToolkit.Mvvm" Version="8.1.0" />
</ItemGroup>
</Project>
4 changes: 4 additions & 0 deletions WalletWasabi.Fluent.Desktop/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using WalletWasabi.Daemon;
using LogLevel = WalletWasabi.Logging.LogLevel;
using System.Threading;
using WalletWasabi.Fluent.AI;

namespace WalletWasabi.Fluent.Desktop;

Expand All @@ -32,6 +33,9 @@ public class Program
// yet and stuff might break.
public static async Task<int> Main(string[] args)
{
// TDOO: For testing only
await Repl.RunAsync();

// Crash reporting must be before the "single instance checking".
Logger.InitializeDefaults(Path.Combine(Config.DataDir, "Logs.txt"), LogLevel.Info);
try
Expand Down
7 changes: 7 additions & 0 deletions WalletWasabi.Fluent.Desktop/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,7 @@
"Avalonia.Skia": "[11.0.7, )",
"Avalonia.Themes.Fluent": "[11.0.7, )",
"Avalonia.Xaml.Behaviors": "[11.0.5, )",
"CommunityToolkit.Mvvm": "[8.1.0, )",
"DynamicData": "[8.1.1, )",
"QRackers": "[1.1.0, )",
"System.Runtime": "[4.3.1, )",
Expand Down Expand Up @@ -932,6 +933,12 @@
"Avalonia.Xaml.Interactivity": "11.0.5"
}
},
"CommunityToolkit.Mvvm": {
"type": "CentralTransitive",
"requested": "[8.1.0, )",
"resolved": "8.1.0",
"contentHash": "xxOt7lu9a5kB5Fs9RfcxzVlKnhuuPe+w7AXHtmCFtS3oldrsUhEMxHfNulluXSscUUoGxZ0jh55Om12ZP6abHA=="
},
"DynamicData": {
"type": "CentralTransitive",
"requested": "[8.1.1, )",
Expand Down
21 changes: 21 additions & 0 deletions WalletWasabi.Fluent/AI/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
root = true

[*.cs]

charset = utf-8

# Use hard tabs for indentation
indent_style = tab
indent_size = 4

# Disable all .NET analyzers
dotnet_analyzer_diagnostic.severity = none

dotnet_diagnostic.CS8600.severity = none
dotnet_diagnostic.CS8601.severity = none
dotnet_diagnostic.CS8603.severity = none
dotnet_diagnostic.CS8604.severity = none
dotnet_diagnostic.CS8618.severity = none
dotnet_diagnostic.CS8625.severity = none
dotnet_diagnostic.CS8765.severity = none
dotnet_diagnostic.CS8767.severity = none
61 changes: 61 additions & 0 deletions WalletWasabi.Fluent/AI/ChatGPT.Core/Defaults.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using AI.Model.Services;
using AI.Services;
using ChatGPT.Model.Services;
using ChatGPT.Services;
using ChatGPT.ViewModels.Chat;
using ChatGPT.ViewModels.Settings;
using CommunityToolkit.Mvvm.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;

namespace ChatGPT;

public static class Defaults
{
public const string WelcomeMessage = "Hi! I'm Clippy, your Windows Assistant. Would you like to get some assistance?";

public const decimal DefaultTemperature = 0.7m;

public const decimal DefaultTopP = 1m;

public const decimal DefaultPresencePenalty = 0m;

public const decimal DefaultFrequencyPenalty = 0m;

public const int DefaultMaxTokens = 2000;

public const string DefaultModel = "gpt-3.5-turbo";

public const string DefaultDirections = "You are a helpful assistant named Clippy. Write answers in Markdown blocks. For code blocks always define used language.";

public const string DefaultMessageFormat = "Markdown";

public const string TextMessageFormat = "Text";

public const string MarkdownMessageFormat = "Markdown";

public const string HtmlMessageTextFormat = "Html";

public static Ioc Locator = Ioc.Default;

public static IServiceProvider ConfigureDefaultServices()
{
IServiceCollection serviceCollection = new ServiceCollection();

serviceCollection.AddSingleton<IChatSerializer, SystemTextJsonChatSerializer>();
serviceCollection.AddSingleton<IStorageFactory, IsolatedStorageFactory>();
serviceCollection.AddSingleton<IChatService, ChatService>();

serviceCollection.AddTransient<ChatMessageViewModel>();
serviceCollection.AddTransient<ChatSettingsViewModel>();
serviceCollection.AddTransient<ChatResultViewModel>();
serviceCollection.AddTransient<ChatViewModel>();
serviceCollection.AddTransient<PromptViewModel>();

IServiceProvider serviceProvider = serviceCollection.BuildServiceProvider();

Locator.ConfigureServices(serviceProvider);

return serviceProvider;
}
}
13 changes: 13 additions & 0 deletions WalletWasabi.Fluent/AI/ChatGPT.Core/Model/Plugins/IChatPlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Threading.Tasks;

namespace ChatGPT.Model.Plugins;

public interface IChatPlugin
{
string Id { get; }
string Name { get; }
Task StartAsync();
Task StopAsync();
Task InitializeAsync(IPluginContext context);
Task ShutdownAsync();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Collections.ObjectModel;
using ChatGPT.ViewModels.Chat;

namespace ChatGPT.Model.Plugins;

public interface IPluginContext
{
ObservableCollection<ChatViewModel> Chats { get; set; }
ChatViewModel? CurrentChat { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;

namespace ChatGPT.Model.Services;

public interface IApplicationService
{
Task OpenFileAsync(Func<Stream, Task> callback, List<string> fileTypes, string title);
Task SaveFileAsync(Func<Stream, Task> callback, List<string> fileTypes, string title, string fileName, string defaultExtension);
void ToggleTheme();
void ToggleTopmost();
Task SetClipboardTextAsync(string text);
void Exit();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace ChatGPT.Model.Services;

public interface IPluginsService
{
void DiscoverPlugins();
void InitPlugins();
void StartPlugins();
void ShutdownPlugins();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace ChatGPT.Model.Services;

public interface IStorageFactory
{
IStorageService<T> CreateStorageService<T>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Text.Json.Serialization.Metadata;
using System.Threading.Tasks;

namespace ChatGPT.Model.Services;

public interface IStorageService<T>
{
Task SaveObjectAsync(T obj, string key, JsonTypeInfo<T> typeInfo);
Task<T?> LoadObjectAsync(string key, JsonTypeInfo<T> typeInfo);
void SaveObject(T obj, string key, JsonTypeInfo<T> typeInfo);
T? LoadObject(string key, JsonTypeInfo<T> typeInfo);
}
31 changes: 31 additions & 0 deletions WalletWasabi.Fluent/AI/ChatGPT.Core/Plugins/DummyChatPlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Threading.Tasks;
using ChatGPT.Model.Plugins;

namespace ChatGPT.Plugins;

public class DummyChatPlugin : IChatPlugin
{
public string Id => "Dummy";

public string Name => "Dummy";

public async Task StartAsync()
{
await Task.Yield();
}

public async Task StopAsync()
{
await Task.Yield();
}

public async Task InitializeAsync(IPluginContext context)
{
await Task.Yield();
}

public async Task ShutdownAsync()
{
await Task.Yield();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using ChatGPT.Model.Services;

namespace ChatGPT.Services;

public class ApplicationDataStorageFactory : IStorageFactory
{
public IStorageService<T> CreateStorageService<T>() => new ApplicationDataStorageService<T>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Text.Json;
using System.Text.Json.Serialization.Metadata;
using System.Threading.Tasks;
using ChatGPT.Model.Services;

namespace ChatGPT.Services;

public class ApplicationDataStorageService<T> : IStorageService<T>
{
private const string FolderName = "ChatGPT";
private const string FileExtension = ".json";

public async Task SaveObjectAsync(T obj, string key, JsonTypeInfo<T> typeInfo)
{
var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
var appPath = Path.Combine(appDataPath, FolderName);
if (!Directory.Exists(appPath))
{
Directory.CreateDirectory(appPath);
}
var appSettingPath = Path.Combine(appPath, key + FileExtension);
#if NETFRAMEWORK
using var stream = File.Open(appSettingPath, FileMode.Create);
#else
await using var stream = File.Open(appSettingPath, FileMode.Create);
#endif
await JsonSerializer.SerializeAsync(stream, obj, typeInfo);
}

public async Task<T?> LoadObjectAsync(string key, JsonTypeInfo<T> typeInfo)
{
try
{
var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
var appSettingPath = Path.Combine(appDataPath, FolderName, key + FileExtension);
if (File.Exists(appSettingPath))
{
#if NETFRAMEWORK
using var stream = File.OpenRead(appSettingPath);
#else
await using var stream = File.OpenRead(appSettingPath);
#endif
var storedObj = await JsonSerializer.DeserializeAsync(stream, typeInfo);
return storedObj ?? default;
}
}
catch (Exception e)
{
Debug.WriteLine(e);
}

return default;
}

public void SaveObject(T obj, string key, JsonTypeInfo<T> typeInfo)
{
var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
var appPath = Path.Combine(appDataPath, FolderName);
if (!Directory.Exists(appPath))
{
Directory.CreateDirectory(appPath);
}
var appSettingPath = Path.Combine(appPath, key + FileExtension);
using var stream = File.Open(appSettingPath, FileMode.Create);
JsonSerializer.Serialize(stream, obj, typeInfo);
}

public T? LoadObject(string key, JsonTypeInfo<T> typeInfo)
{
try
{
var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
var appSettingPath = Path.Combine(appDataPath, FolderName, key + FileExtension);
if (File.Exists(appSettingPath))
{
using var stream = File.OpenRead(appSettingPath);
var storedObj = JsonSerializer.Deserialize(stream, typeInfo);
return storedObj ?? default;
}
}
catch (Exception e)
{
Debug.WriteLine(e);
}

return default;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using ChatGPT.Model.Services;

namespace ChatGPT.Services;

public class IsolatedStorageFactory : IStorageFactory
{
public IStorageService<T> CreateStorageService<T>() => new IsolatedStorageService<T>();
}

0 comments on commit 296fb21

Please sign in to comment.