├── img ├── wx.jpg ├── home.png ├── home1.png └── setting.png ├── src ├── ChatGPT.App │ ├── wwwroot │ │ ├── i18n │ │ │ ├── supportedCultures.json │ │ │ ├── zh-CN.json │ │ │ └── en-US.json │ │ ├── favicon.ico │ │ ├── css │ │ │ └── open-iconic │ │ │ │ ├── font │ │ │ │ └── fonts │ │ │ │ │ ├── open-iconic.eot │ │ │ │ │ ├── open-iconic.otf │ │ │ │ │ ├── open-iconic.ttf │ │ │ │ │ └── open-iconic.woff │ │ │ │ ├── ICON-LICENSE │ │ │ │ ├── README.md │ │ │ │ └── FONT-LICENSE │ │ └── index.html │ ├── token.keystore │ ├── Resources │ │ ├── Fonts │ │ │ └── OpenSans-Regular.ttf │ │ ├── AppIcon │ │ │ ├── appicon.svg │ │ │ └── appiconfg.svg │ │ ├── Raw │ │ │ └── AboutAssets.txt │ │ ├── Splash │ │ │ └── splash.svg │ │ └── Images │ │ │ └── dotnet_bot.svg │ ├── Properties │ │ └── launchSettings.json │ ├── App.xaml.cs │ ├── Platforms │ │ ├── Android │ │ │ ├── Resources │ │ │ │ └── values │ │ │ │ │ └── colors.xml │ │ │ ├── MainApplication.cs │ │ │ ├── MainActivity.cs │ │ │ └── AndroidManifest.xml │ │ ├── iOS │ │ │ ├── AppDelegate.cs │ │ │ ├── Program.cs │ │ │ └── Info.plist │ │ ├── MacCatalyst │ │ │ ├── AppDelegate.cs │ │ │ ├── Program.cs │ │ │ └── Info.plist │ │ ├── Windows │ │ │ ├── App.xaml │ │ │ ├── app.manifest │ │ │ ├── App.xaml.cs │ │ │ └── Package.appxmanifest │ │ └── Tizen │ │ │ ├── Main.cs │ │ │ └── tizen-manifest.xml │ ├── _Imports.razor │ ├── MainPage.xaml.cs │ ├── MainPage.xaml │ ├── MauiProgram.cs │ ├── App.xaml │ └── ChatGPT.App.csproj ├── ChatGpt.Desktop │ ├── wwwroot │ │ ├── i18n │ │ │ ├── supportedCultures.json │ │ │ ├── zh-CN.json │ │ │ └── en-US.json │ │ ├── css │ │ │ └── app.css │ │ └── index.html │ ├── chatgpt.ico │ ├── _Imports.razor │ ├── Program.cs │ └── ChatGpt.Desktop.csproj ├── ChatGpt.Server │ ├── wwwroot │ │ ├── i18n │ │ │ ├── supportedCultures.json │ │ │ ├── zh-CN.json │ │ │ └── en-US.json │ │ └── css │ │ │ └── site.css │ ├── _Imports.razor │ ├── appsettings.json │ ├── appsettings.Development.json │ ├── Program.cs │ ├── ChatGpt.Server.csproj │ ├── Dockerfile │ ├── Properties │ │ └── launchSettings.json │ └── Pages │ │ └── _Host.cshtml ├── ChatGPT.WebAssembly │ ├── wwwroot │ │ ├── i18n │ │ │ ├── supportedCultures.json │ │ │ ├── zh-CN.json │ │ │ └── en-US.json │ │ ├── icon-512.png │ │ ├── service-worker.js │ │ ├── manifest.json │ │ ├── service-worker.published.js │ │ ├── index.html │ │ └── css │ │ │ └── app.css │ ├── _Imports.razor │ ├── Program.cs │ ├── Properties │ │ └── launchSettings.json │ └── ChatGPT.WebAssembly.csproj ├── ChatGpt.Skills │ ├── Class1.cs │ └── ChatGpt.Skills.csproj ├── KernelHttpServer │ ├── .vscode │ │ └── extensions.json │ ├── local.settings.json │ ├── Config │ │ ├── AIService.cs │ │ ├── ApiKeyConfig.cs │ │ ├── Constants.cs │ │ └── BackendConfig.cs │ ├── host.json │ ├── Properties │ │ └── launchSettings.json │ ├── Model │ │ ├── AskResult.cs │ │ ├── Skill.cs │ │ └── Ask.cs │ ├── Utils │ │ ├── YourAppException.cs │ │ └── RepoFiles.cs │ ├── PingEndpoint.cs │ ├── TokenAuthenticationProvider.cs │ ├── Dockerfile │ ├── Program.cs │ ├── README.md │ ├── KernelHttpServer.csproj │ ├── SemanticKernelFactory.cs │ ├── SemanticKernelEndpoint.cs │ └── Extensions.cs └── ChatGpt.Shared │ ├── Module │ ├── ShortcutKey.cs │ ├── ModelType.cs │ ├── DALLEMoDto.cs │ ├── DialoguesModule.cs │ ├── MessageModule.cs │ └── GetChatGPTDto.cs │ ├── GlobalUsing.cs │ ├── Shared │ └── MainLayout.razor │ ├── _Imports.razor │ ├── wwwroot │ └── js │ │ ├── storage-JsInterop.js │ │ └── chat-gpt-JsInterop.js │ ├── App.razor │ ├── Components │ ├── CahtMessage.razor.cs │ ├── Settings.razor.cs │ ├── SendMessage.razor │ ├── Dialogues.razor │ ├── SendMessage.razor.cs │ ├── Language.razor │ ├── CahtMessage.razor │ └── Dialogues.razor.cs │ ├── ServiceCollectionExtensions.cs │ ├── Interop │ ├── ChatGptJsInterop.cs │ └── StorageJsInterop.cs │ ├── ChatGpt.Shared.csproj │ ├── Options │ └── ChatGptOptions.cs │ ├── Pages │ └── Index.razor │ └── ApiClient.cs ├── .editorconfig ├── .github └── ISSUE_TEMPLATE │ ├── custom.md │ ├── feature_request.md │ └── bug_report.md ├── chatgpt └── skills │ └── ChatSkill │ ├── ChatUser │ ├── skprompt.txt │ └── config.json │ ├── Chat │ ├── skprompt.txt │ └── config.json │ ├── ChatGPT │ ├── config.json │ └── skprompt.txt │ ├── ChatFilter │ ├── config.json │ └── skprompt.txt │ └── ChatV2 │ ├── config.json │ └── skprompt.txt ├── docker-compose.yml ├── .dockerignore ├── Directory.Build.props ├── Directory.Build.targets ├── publish.bat ├── README.zh-CN.md ├── ChatGPT.App.sln ├── README.md └── ChatGPT.sln /img/wx.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/239573049/ChatGpt.Desktop/HEAD/img/wx.jpg -------------------------------------------------------------------------------- /img/home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/239573049/ChatGpt.Desktop/HEAD/img/home.png -------------------------------------------------------------------------------- /img/home1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/239573049/ChatGpt.Desktop/HEAD/img/home1.png -------------------------------------------------------------------------------- /src/ChatGPT.App/wwwroot/i18n/supportedCultures.json: -------------------------------------------------------------------------------- 1 | [ 2 | "zh-CN", 3 | "en-US" 4 | ] -------------------------------------------------------------------------------- /img/setting.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/239573049/ChatGpt.Desktop/HEAD/img/setting.png -------------------------------------------------------------------------------- /src/ChatGpt.Desktop/wwwroot/i18n/supportedCultures.json: -------------------------------------------------------------------------------- 1 | [ 2 | "zh-CN", 3 | "en-US" 4 | ] -------------------------------------------------------------------------------- /src/ChatGpt.Server/wwwroot/i18n/supportedCultures.json: -------------------------------------------------------------------------------- 1 | [ 2 | "zh-CN", 3 | "en-US" 4 | ] -------------------------------------------------------------------------------- /src/ChatGPT.WebAssembly/wwwroot/i18n/supportedCultures.json: -------------------------------------------------------------------------------- 1 | [ 2 | "zh-CN", 3 | "en-US" 4 | ] -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | [*.cs] 2 | 3 | # CA2007: 考虑对等待的任务调用 ConfigureAwait 4 | dotnet_diagnostic.CA2007.severity = none 5 | -------------------------------------------------------------------------------- /src/ChatGPT.App/token.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/239573049/ChatGpt.Desktop/HEAD/src/ChatGPT.App/token.keystore -------------------------------------------------------------------------------- /src/ChatGpt.Desktop/chatgpt.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/239573049/ChatGpt.Desktop/HEAD/src/ChatGpt.Desktop/chatgpt.ico -------------------------------------------------------------------------------- /src/ChatGPT.App/wwwroot/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/239573049/ChatGpt.Desktop/HEAD/src/ChatGPT.App/wwwroot/favicon.ico -------------------------------------------------------------------------------- /src/ChatGPT.WebAssembly/wwwroot/icon-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/239573049/ChatGpt.Desktop/HEAD/src/ChatGPT.WebAssembly/wwwroot/icon-512.png -------------------------------------------------------------------------------- /src/ChatGpt.Skills/Class1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ChatGpt.Skills 4 | { 5 | public class Class1 6 | { 7 | 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/ChatGPT.App/Resources/Fonts/OpenSans-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/239573049/ChatGpt.Desktop/HEAD/src/ChatGPT.App/Resources/Fonts/OpenSans-Regular.ttf -------------------------------------------------------------------------------- /src/KernelHttpServer/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "ms-azuretools.vscode-azurefunctions", 4 | "ms-dotnettools.csharp" 5 | ] 6 | } -------------------------------------------------------------------------------- /src/ChatGpt.Server/_Imports.razor: -------------------------------------------------------------------------------- 1 | @using Microsoft.AspNetCore.Components.Routing 2 | @using Microsoft.AspNetCore.Components.Web 3 | @using Microsoft.JSInterop 4 | @using ChatGpt.Server 5 | -------------------------------------------------------------------------------- /src/ChatGpt.Shared/Module/ShortcutKey.cs: -------------------------------------------------------------------------------- 1 | namespace ChatGpt.Shared.Module; 2 | 3 | public enum ShortcutKey 4 | { 5 | CtrlEnter, 6 | Enter, 7 | Shift, 8 | ShiftEnter 9 | } -------------------------------------------------------------------------------- /src/ChatGPT.App/wwwroot/css/open-iconic/font/fonts/open-iconic.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/239573049/ChatGpt.Desktop/HEAD/src/ChatGPT.App/wwwroot/css/open-iconic/font/fonts/open-iconic.eot -------------------------------------------------------------------------------- /src/ChatGPT.App/wwwroot/css/open-iconic/font/fonts/open-iconic.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/239573049/ChatGpt.Desktop/HEAD/src/ChatGPT.App/wwwroot/css/open-iconic/font/fonts/open-iconic.otf -------------------------------------------------------------------------------- /src/ChatGPT.App/wwwroot/css/open-iconic/font/fonts/open-iconic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/239573049/ChatGpt.Desktop/HEAD/src/ChatGPT.App/wwwroot/css/open-iconic/font/fonts/open-iconic.ttf -------------------------------------------------------------------------------- /src/ChatGPT.App/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "Windows Machine": { 4 | "commandName": "MsixPackage", 5 | "nativeDebugging": false 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /src/ChatGPT.App/wwwroot/css/open-iconic/font/fonts/open-iconic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/239573049/ChatGpt.Desktop/HEAD/src/ChatGPT.App/wwwroot/css/open-iconic/font/fonts/open-iconic.woff -------------------------------------------------------------------------------- /src/KernelHttpServer/local.settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "IsEncrypted": false, 3 | "Host": { 4 | "CORS": "*" 5 | }, 6 | "Values": { 7 | "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated" 8 | } 9 | } -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/custom.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Custom issue template 3 | about: Describe this issue template's purpose here. 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | -------------------------------------------------------------------------------- /chatgpt/skills/ChatSkill/ChatUser/skprompt.txt: -------------------------------------------------------------------------------- 1 | The following is a conversation with {{$person}} with {{$attitude}}. 2 | 3 | {{$user}}Hello. 4 | {{$bot}} {{$question}} 5 | {{$history}} 6 | {{$user}}{{$input}} 7 | {{$bot}} -------------------------------------------------------------------------------- /src/ChatGpt.Server/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*" 9 | } 10 | -------------------------------------------------------------------------------- /src/ChatGpt.Shared/GlobalUsing.cs: -------------------------------------------------------------------------------- 1 | // 定义全局引用 2 | global using ChatGpt.Shared.Module; 3 | global using Microsoft.AspNetCore.Components; 4 | global using BlazorComponent.JSInterop; 5 | global using Microsoft.JSInterop; 6 | -------------------------------------------------------------------------------- /src/ChatGpt.Server/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "DetailedErrors": true, 3 | "Logging": { 4 | "LogLevel": { 5 | "Default": "Information", 6 | "Microsoft.AspNetCore": "Warning" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/KernelHttpServer/Config/AIService.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | 3 | namespace KernelHttpServer.Config; 4 | 5 | public enum AIService 6 | { 7 | AzureOpenAI = 0, 8 | 9 | OpenAI = 1 10 | } 11 | -------------------------------------------------------------------------------- /src/ChatGPT.App/App.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace ChatGPT.App; 2 | 3 | public partial class App : Application 4 | { 5 | public App() 6 | { 7 | InitializeComponent(); 8 | 9 | MainPage = new MainPage(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/KernelHttpServer/host.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0", 3 | "logging": { 4 | "applicationInsights": { 5 | "samplingSettings": { 6 | "isEnabled": true, 7 | "excludedTypes": "Request" 8 | } 9 | } 10 | } 11 | } -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | services: 2 | chat-server: 3 | image: registry.cn-shenzhen.aliyuncs.com/tokengo/chat-server 4 | build: 5 | context: . 6 | dockerfile: ./src/ChatGpt.Server/Dockerfile 7 | container_name: chat-server 8 | ports: 9 | - 1800:80 -------------------------------------------------------------------------------- /src/ChatGPT.App/Platforms/Android/Resources/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #512BD4 4 | #2B0B98 5 | #2B0B98 6 | -------------------------------------------------------------------------------- /src/ChatGPT.App/Resources/AppIcon/appicon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/ChatGpt.Shared/Shared/MainLayout.razor: -------------------------------------------------------------------------------- 1 | @namespace ChatGpt.Shared 2 | @inherits LayoutComponentBase 3 | @inject StorageJsInterop StorageJsInterop 4 | 5 | 6 | @Body 7 | 8 | 9 | @code { 10 | private string ComputedHref = "https://github.com/239573049"; 11 | } -------------------------------------------------------------------------------- /src/ChatGPT.App/Platforms/iOS/AppDelegate.cs: -------------------------------------------------------------------------------- 1 | using Foundation; 2 | 3 | namespace ChatGPT.App; 4 | 5 | [Register("AppDelegate")] 6 | public class AppDelegate : MauiUIApplicationDelegate 7 | { 8 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); 9 | } 10 | -------------------------------------------------------------------------------- /src/ChatGPT.App/Platforms/MacCatalyst/AppDelegate.cs: -------------------------------------------------------------------------------- 1 | using Foundation; 2 | 3 | namespace ChatGPT.App; 4 | 5 | [Register("AppDelegate")] 6 | public class AppDelegate : MauiUIApplicationDelegate 7 | { 8 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); 9 | } 10 | -------------------------------------------------------------------------------- /src/ChatGpt.Shared/Module/ModelType.cs: -------------------------------------------------------------------------------- 1 | namespace ChatGpt.Shared.Module; 2 | 3 | public enum ModelType 4 | { 5 | /// 6 | /// ChatGpt3.5模型 7 | /// 8 | ChatGpt, 9 | 10 | /// 11 | /// 图片模型 12 | /// 13 | DALLE 14 | } 15 | -------------------------------------------------------------------------------- /chatgpt/skills/ChatSkill/Chat/skprompt.txt: -------------------------------------------------------------------------------- 1 | The following is a conversation with an AI assistant. The assistant is helpful, creative, clever, and very friendly. 2 | 3 | {{$user}}I have a question. Can you help? 4 | {{$bot}}Of course. I am your AI Copilot. Go on! 5 | {{$history}} 6 | {{$user}}{{$input}} 7 | {{$bot}} -------------------------------------------------------------------------------- /src/ChatGPT.WebAssembly/_Imports.razor: -------------------------------------------------------------------------------- 1 | @using System.Net.Http 2 | @using System.Net.Http.Json 3 | @using Microsoft.AspNetCore.Components.Routing 4 | @using Microsoft.AspNetCore.Components.Web 5 | @using Microsoft.AspNetCore.Components.WebAssembly.Http 6 | @using Microsoft.JSInterop 7 | @using ChatGPT.WebAssembly 8 | -------------------------------------------------------------------------------- /src/ChatGpt.Shared/Module/DALLEMoDto.cs: -------------------------------------------------------------------------------- 1 | namespace ChatGpt.Shared.Module; 2 | 3 | public class DALLEMoDto 4 | { 5 | public long created { get; set; } 6 | 7 | public List data { get; set; } 8 | } 9 | 10 | public class DALLEDataDto 11 | { 12 | public string Url { get; set; } 13 | } -------------------------------------------------------------------------------- /src/ChatGPT.App/_Imports.razor: -------------------------------------------------------------------------------- 1 | @using System.Net.Http 2 | @using Microsoft.AspNetCore.Components.Forms 3 | @using Microsoft.AspNetCore.Components.Routing 4 | @using Microsoft.AspNetCore.Components.Web 5 | @using Microsoft.AspNetCore.Components.Web.Virtualization 6 | @using Microsoft.JSInterop 7 | @using ChatGPT.App 8 | -------------------------------------------------------------------------------- /src/ChatGPT.WebAssembly/wwwroot/service-worker.js: -------------------------------------------------------------------------------- 1 | // In development, always fetch from the network and do not enable offline support. 2 | // This is because caching would make development more difficult (changes would not 3 | // be reflected on the first load after each change). 4 | self.addEventListener('fetch', () => { }); 5 | -------------------------------------------------------------------------------- /src/ChatGpt.Shared/_Imports.razor: -------------------------------------------------------------------------------- 1 | @using Microsoft.AspNetCore.Components.Routing 2 | @using Microsoft.AspNetCore.Components.Web 3 | @using Microsoft.JSInterop 4 | @using Masa.Blazor 5 | @using BlazorComponent 6 | @using ChatGpt.Shared 7 | @using ChatGpt.Shared.Interop 8 | @using Masa.Blazor.Presets; 9 | @using BlazorComponent.I18n -------------------------------------------------------------------------------- /src/KernelHttpServer/Config/ApiKeyConfig.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | 3 | namespace KernelHttpServer.Config; 4 | 5 | public class ApiKeyConfig 6 | { 7 | public BackendConfig CompletionConfig { get; set; } = new(); 8 | 9 | public BackendConfig EmbeddingConfig { get; set; } = new(); 10 | } 11 | -------------------------------------------------------------------------------- /src/KernelHttpServer/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "KernelHttpServer": { 4 | "commandName": "Project" 5 | }, 6 | "Docker": { 7 | "commandName": "Docker", 8 | "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}", 9 | "httpPort": 31200, 10 | "useSSL": false 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /chatgpt/skills/ChatSkill/ChatGPT/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "schema": 1, 3 | "description": "", 4 | "type": "completion", 5 | "completion": { 6 | "max_tokens": 150, 7 | "temperature": 0.9, 8 | "top_p": 0.0, 9 | "presence_penalty": 0.6, 10 | "frequency_penalty": 0.0, 11 | "stop_sequences": [ 12 | "[Done]" 13 | ] 14 | } 15 | } -------------------------------------------------------------------------------- /src/ChatGPT.App/Platforms/Windows/App.xaml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /chatgpt/skills/ChatSkill/Chat/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "schema": 1, 3 | "description": "Chat with the AI", 4 | "type": "completion", 5 | "completion": { 6 | "max_tokens": 150, 7 | "temperature": 0.9, 8 | "top_p": 0.0, 9 | "presence_penalty": 0.6, 10 | "frequency_penalty": 0.0, 11 | "stop_sequences": [ 12 | "Human:", 13 | "AI:" 14 | ] 15 | } 16 | } -------------------------------------------------------------------------------- /src/ChatGPT.App/Platforms/Tizen/Main.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.Maui; 3 | using Microsoft.Maui.Hosting; 4 | 5 | namespace ChatGPT.App; 6 | 7 | class Program : MauiApplication 8 | { 9 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); 10 | 11 | static void Main(string[] args) 12 | { 13 | var app = new Program(); 14 | app.Run(args); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/KernelHttpServer/Model/AskResult.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | 6 | namespace KernelHttpServer.Model; 7 | 8 | public class AskResult 9 | { 10 | public string Value { get; set; } = string.Empty; 11 | 12 | public IEnumerable? State { get; set; } = Enumerable.Empty(); 13 | } 14 | -------------------------------------------------------------------------------- /src/ChatGpt.Desktop/_Imports.razor: -------------------------------------------------------------------------------- 1 | @using System.Net.Http 2 | @using System.Net.Http.Json 3 | @using Microsoft.AspNetCore.Authorization 4 | @using Microsoft.AspNetCore.Components.Forms 5 | @using Microsoft.AspNetCore.Components.Routing 6 | @using Microsoft.AspNetCore.Components.Web 7 | @using Microsoft.AspNetCore.Components.Web.Virtualization 8 | @using Microsoft.JSInterop 9 | @using Microsoft.Extensions.Logging -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | **/.classpath 2 | **/.dockerignore 3 | **/.env 4 | **/.git 5 | **/.gitignore 6 | **/.project 7 | **/.settings 8 | **/.toolstarget 9 | **/.vs 10 | **/.vscode 11 | **/*.*proj.user 12 | **/*.dbmdl 13 | **/*.jfm 14 | **/azds.yaml 15 | **/bin 16 | **/charts 17 | **/docker-compose* 18 | **/Dockerfile* 19 | **/node_modules 20 | **/npm-debug.log 21 | **/obj 22 | **/secrets.dev.yaml 23 | **/values.dev.yaml 24 | LICENSE 25 | README.md -------------------------------------------------------------------------------- /src/ChatGPT.App/Platforms/Android/MainApplication.cs: -------------------------------------------------------------------------------- 1 | using Android.App; 2 | using Android.Runtime; 3 | 4 | namespace ChatGPT.App; 5 | 6 | [Application] 7 | public class MainApplication : MauiApplication 8 | { 9 | public MainApplication(IntPtr handle, JniHandleOwnership ownership) 10 | : base(handle, ownership) 11 | { 12 | } 13 | 14 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); 15 | } 16 | -------------------------------------------------------------------------------- /src/ChatGPT.WebAssembly/wwwroot/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ChatGPT.WebAssembly", 3 | "short_name": "ChatGPT.WebAssembly", 4 | "start_url": "./", 5 | "display": "standalone", 6 | "background_color": "#ffffff", 7 | "theme_color": "#03173d", 8 | "prefer_related_applications": false, 9 | "icons": [ 10 | { 11 | "src": "icon-512.png", 12 | "type": "image/png", 13 | "sizes": "512x512" 14 | } 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /src/ChatGpt.Shared/wwwroot/js/storage-JsInterop.js: -------------------------------------------------------------------------------- 1 | function setValue(key, value) { 2 | localStorage.setItem(key, value) 3 | } 4 | 5 | function getValue(key) { 6 | return localStorage.getItem(key) 7 | } 8 | 9 | function removeValue(key) { 10 | localStorage.removeItem(key) 11 | } 12 | 13 | function clear() { 14 | localStorage.clear() 15 | } 16 | 17 | export { 18 | setValue, 19 | getValue, 20 | removeValue, 21 | clear 22 | } -------------------------------------------------------------------------------- /src/ChatGPT.App/MainPage.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace ChatGPT.App; 2 | 3 | public partial class MainPage : ContentPage 4 | { 5 | public MainPage() 6 | { 7 | InitializeComponent(); 8 | var root = new Microsoft.AspNetCore.Components.WebView.Maui.RootComponent() 9 | { 10 | Selector = "#app", 11 | ComponentType = typeof(ChatGpt.Shared.App) 12 | }; 13 | blazorWebView.RootComponents.Add(root); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/ChatGPT.App/Platforms/iOS/Program.cs: -------------------------------------------------------------------------------- 1 | using ObjCRuntime; 2 | using UIKit; 3 | 4 | namespace ChatGPT.App; 5 | 6 | public class Program 7 | { 8 | // This is the main entry point of the application. 9 | static void Main(string[] args) 10 | { 11 | // if you want to use a different Application Delegate class from "AppDelegate" 12 | // you can specify it here. 13 | UIApplication.Main(args, null, typeof(AppDelegate)); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /chatgpt/skills/ChatSkill/ChatFilter/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "schema": 1, 3 | "description": "Given a chat message decide whether to block it", 4 | "type": "completion", 5 | "completion": { 6 | "max_tokens": 1000, 7 | "temperature": 0.0, 8 | "top_p": 0.0, 9 | "presence_penalty": 0.0, 10 | "frequency_penalty": 0.0, 11 | "stop_sequences": [ 12 | "" 13 | ] 14 | }, 15 | "default_backends": [ 16 | "text-davinci-003" 17 | ] 18 | } -------------------------------------------------------------------------------- /chatgpt/skills/ChatSkill/ChatV2/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "schema": 1, 3 | "description": "A friendly chat where AI helps, avoiding bad topics", 4 | "type": "completion", 5 | "completion": { 6 | "max_tokens": 1000, 7 | "temperature": 0.4, 8 | "top_p": 1.0, 9 | "presence_penalty": 0.0, 10 | "frequency_penalty": 0.0, 11 | "stop_sequences": [ 12 | "" 13 | ] 14 | }, 15 | "default_backends": [ 16 | "text-davinci-003" 17 | ] 18 | } -------------------------------------------------------------------------------- /src/ChatGPT.App/Platforms/MacCatalyst/Program.cs: -------------------------------------------------------------------------------- 1 | using ObjCRuntime; 2 | using UIKit; 3 | 4 | namespace ChatGPT.App; 5 | 6 | public class Program 7 | { 8 | // This is the main entry point of the application. 9 | static void Main(string[] args) 10 | { 11 | // if you want to use a different Application Delegate class from "AppDelegate" 12 | // you can specify it here. 13 | UIApplication.Main(args, null, typeof(AppDelegate)); 14 | } 15 | } -------------------------------------------------------------------------------- /chatgpt/skills/ChatSkill/ChatUser/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "schema": 1, 3 | "description": "A chat bot that plays a persona or role", 4 | "type": "completion", 5 | "completion": { 6 | "max_tokens": 150, 7 | "temperature": 0.9, 8 | "top_p": 0.0, 9 | "presence_penalty": 0.6, 10 | "frequency_penalty": 0.0, 11 | "stop_sequences": [ 12 | "Human:", 13 | "AI:" 14 | ] 15 | }, 16 | "default_backends": [ 17 | "text-davinci-003" 18 | ] 19 | } -------------------------------------------------------------------------------- /src/ChatGPT.App/Platforms/Android/MainActivity.cs: -------------------------------------------------------------------------------- 1 | using Android.App; 2 | using Android.Content.PM; 3 | using Android.OS; 4 | 5 | namespace ChatGPT.App; 6 | 7 | [Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)] 8 | public class MainActivity : MauiAppCompatActivity 9 | { 10 | } 11 | -------------------------------------------------------------------------------- /src/KernelHttpServer/Utils/YourAppException.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | 3 | using System; 4 | 5 | namespace KernelHttpServer.Utils; 6 | 7 | public class YourAppException : Exception 8 | { 9 | public YourAppException() : base() 10 | { 11 | } 12 | 13 | public YourAppException(string message) : base(message) 14 | { 15 | } 16 | 17 | public YourAppException(string message, Exception innerException) : base(message, innerException) 18 | { 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/ChatGPT.App/Platforms/Android/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/ChatGpt.Shared/App.razor: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Not found 9 | 10 |

Sorry, there's nothing at this address.

11 |
12 |
13 |
14 | -------------------------------------------------------------------------------- /src/ChatGPT.WebAssembly/Program.cs: -------------------------------------------------------------------------------- 1 | using ChatGpt.Shared; 2 | using Microsoft.AspNetCore.Components.Web; 3 | using Microsoft.AspNetCore.Components.WebAssembly.Hosting; 4 | 5 | var builder = WebAssemblyHostBuilder.CreateDefault(args); 6 | builder.RootComponents.Add("#app"); 7 | builder.RootComponents.Add("head::after"); 8 | 9 | await builder.Services 10 | .AddScoped((_) => new HttpClient()) 11 | .AddChatGpt() 12 | .AddI18nForWasmAsync(builder.HostEnvironment.BaseAddress + "i18n"); 13 | 14 | await builder.Build().RunAsync(); 15 | -------------------------------------------------------------------------------- /src/ChatGPT.App/MainPage.xaml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/ChatGpt.Server/Program.cs: -------------------------------------------------------------------------------- 1 | var builder = WebApplication.CreateBuilder(args); 2 | builder.Services.AddRazorPages(); 3 | builder.Services.AddServerSideBlazor(); 4 | builder.Services.AddChatGpt() 5 | .AddI18nForServer("wwwroot/i18n"); 6 | 7 | builder.Services.AddScoped((_) => 8 | { 9 | var message = new HttpClientHandler(); 10 | message.ServerCertificateCustomValidationCallback += (_, _, _, _) => true; 11 | return new HttpClient(message); 12 | }); 13 | var app = builder.Build(); 14 | 15 | app.UseStaticFiles(); 16 | 17 | app.UseRouting(); 18 | 19 | app.MapBlazorHub(); 20 | app.MapFallbackToPage("/_Host"); 21 | 22 | app.Run(); 23 | -------------------------------------------------------------------------------- /src/ChatGpt.Shared/Components/CahtMessage.razor.cs: -------------------------------------------------------------------------------- 1 | namespace ChatGpt.Shared; 2 | 3 | public partial class CahtMessage 4 | { 5 | [Parameter] 6 | public string DialoguesKey { get; set; } 7 | 8 | [Parameter] 9 | public EventCallback DialoguesKeyChanged { get; set; } 10 | 11 | [Parameter] 12 | public List Messages { get; set; } 13 | 14 | [Parameter] 15 | public EventCallback> MessagesChanged { get; set; } 16 | 17 | [Parameter] 18 | public EventCallback OnCopy { get; set; } 19 | 20 | [Parameter] 21 | public ChatGptOptions? ChatGptOptions { get; set; } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/KernelHttpServer/Model/Skill.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | 6 | namespace KernelHttpServer.Model; 7 | 8 | public class Skill 9 | { 10 | public string Name { get; set; } = string.Empty; 11 | 12 | public string FunctionName { get; set; } = string.Empty; 13 | 14 | public string PromptTemplate { get; set; } = string.Empty; 15 | 16 | public int MaxTokens { get; set; } 17 | 18 | public float TopP { get; set; } 19 | 20 | public float Temperature { get; set; } 21 | 22 | public IEnumerable StopSequences { get; set; } = Enumerable.Empty(); 23 | } 24 | -------------------------------------------------------------------------------- /Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | true 5 | true 6 | AllEnabledByDefault 7 | latest 8 | 10 9 | enable 10 | disable 11 | 12 | 13 | 14 | 15 | disable 16 | 17 | -------------------------------------------------------------------------------- /src/ChatGpt.Shared/Module/DialoguesModule.cs: -------------------------------------------------------------------------------- 1 | namespace ChatGpt.Shared.Module; 2 | 3 | public class DialoguesModule 4 | { 5 | /// 6 | /// id 7 | /// 8 | public string Key { get; set; } 9 | 10 | /// 11 | /// 标题 12 | /// 13 | public string Title { get; set; } 14 | 15 | /// 16 | /// 创建时间 17 | /// 18 | public DateTime CreatedTime { get; set; } 19 | 20 | public DialoguesModule() 21 | { 22 | } 23 | 24 | public DialoguesModule(string key, string title) 25 | { 26 | Key = key; 27 | Title = title; 28 | CreatedTime = DateTime.Now; 29 | } 30 | } -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /src/ChatGpt.Shared/ServiceCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using ChatGpt.Shared; 2 | using ChatGpt.Shared.Interop; 3 | 4 | namespace Microsoft.Extensions.DependencyInjection; 5 | 6 | public static class ServiceCollectionExtensions 7 | { 8 | /// 9 | /// 注册ChatGpt核心界面 10 | /// 11 | /// 12 | /// 13 | public static IMasaBlazorBuilder AddChatGpt(this IServiceCollection services) 14 | { 15 | var masa = services.AddMasaBlazor(); 16 | services.AddScoped(); 17 | services.AddScoped(); 18 | services.AddScoped(); 19 | 20 | return masa; 21 | } 22 | } -------------------------------------------------------------------------------- /chatgpt/skills/ChatSkill/ChatGPT/skprompt.txt: -------------------------------------------------------------------------------- 1 | This is a conversation between {{$firstName}} and you. 2 | Your Name: {{$botName}}. Play the persona of: {{$attitude}}. 3 | Use CONTEXT to LEARN ABOUT {{$firstName}}. 4 | 5 | [CONTEXT] 6 | TODAY is {{date}} 7 | FIRST NAME: {{$firstname}} 8 | LAST NAME: {{$lastname}} 9 | CITYl {{$city}} 10 | STATE: {{$state}} 11 | COUNTRY: {{$country}} 12 | {{recall $input}} 13 | [END CONTEXT] 14 | 15 | USE INFO WHEN PERTINENT. 16 | KEEP IT SECRET THAT YOU WERE GIVEN CONTEXT. 17 | ONLY SPEAK FOR YOURSELF. 18 | 19 | {{$firstName}}: I have a question. Can you help? 20 | {{$botName}}: Of course. Go on! 21 | [Done] 22 | {{$history}} 23 | [Done] 24 | ++++ 25 | {{$firstName}}:{{$input}} 26 | -------------------------------------------------------------------------------- /src/KernelHttpServer/PingEndpoint.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | 3 | using System.Net; 4 | using Microsoft.Azure.Functions.Worker; 5 | using Microsoft.Azure.Functions.Worker.Http; 6 | 7 | // This endpoint exists as a convenience for the UI to check if the function it is dependent 8 | // on is running. You won't need this endpoint in a typical app. 9 | namespace KernelHttpServer; 10 | 11 | public class PingEndpoint 12 | { 13 | [Function("Ping")] 14 | public HttpResponseData Ping( 15 | [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "ping")] 16 | HttpRequestData req, 17 | FunctionContext executionContext) 18 | { 19 | return req.CreateResponse(HttpStatusCode.OK); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/ChatGPT.App/Resources/Raw/AboutAssets.txt: -------------------------------------------------------------------------------- 1 | Any raw assets you want to be deployed with your application can be placed in 2 | this directory (and child directories). Deployment of the asset to your application 3 | is automatically handled by the following `MauiAsset` Build Action within your `.csproj`. 4 | 5 | 6 | 7 | These files will be deployed with you package and will be accessible using Essentials: 8 | 9 | async Task LoadMauiAsset() 10 | { 11 | using var stream = await FileSystem.OpenAppPackageFileAsync("AboutAssets.txt"); 12 | using var reader = new StreamReader(stream); 13 | 14 | var contents = reader.ReadToEnd(); 15 | } 16 | -------------------------------------------------------------------------------- /src/KernelHttpServer/Model/Ask.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | 6 | namespace KernelHttpServer.Model; 7 | 8 | public class Ask 9 | { 10 | public string Value { get; set; } = string.Empty; 11 | 12 | /// 13 | /// When a non-empty collection is given, only skills matching these names should be loaded 14 | /// 15 | public IEnumerable? Skills { get; set; } = null; 16 | 17 | public IEnumerable Inputs { get; set; } = Enumerable.Empty(); 18 | } 19 | 20 | public class AskInput 21 | { 22 | public string Key { get; set; } = string.Empty; 23 | 24 | public string Value { get; set; } = string.Empty; 25 | } 26 | -------------------------------------------------------------------------------- /src/KernelHttpServer/TokenAuthenticationProvider.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | 3 | using System.Net.Http; 4 | using System.Net.Http.Headers; 5 | using System.Threading.Tasks; 6 | using Microsoft.Graph; 7 | 8 | namespace KernelHttpServer; 9 | 10 | internal sealed class TokenAuthenticationProvider : IAuthenticationProvider 11 | { 12 | private readonly string _token; 13 | 14 | public TokenAuthenticationProvider(string token) 15 | { 16 | this._token = token; 17 | } 18 | 19 | public Task AuthenticateRequestAsync(HttpRequestMessage request) 20 | { 21 | return Task.FromResult(request.Headers.Authorization = new AuthenticationHeaderValue( 22 | scheme: "bearer", 23 | parameter: this._token)); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/ChatGPT.App/Platforms/Windows/app.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 11 | true/PM 12 | PerMonitorV2, PerMonitor 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/ChatGPT.App/Platforms/Tizen/tizen-manifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | maui-appicon-placeholder 7 | 8 | 9 | 10 | 11 | http://tizen.org/privilege/internet 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/ChatGpt.Shared/Interop/ChatGptJsInterop.cs: -------------------------------------------------------------------------------- 1 | namespace ChatGpt.Shared.Interop; 2 | 3 | public class ChatGptJsInterop : JSModule 4 | { 5 | public ChatGptJsInterop(IJSRuntime js) : base(js, "./_content/ChatGpt.Shared/js/chat-gpt-JsInterop.js") 6 | { 7 | } 8 | 9 | public async ValueTask AddEventListener(string id) 10 | { 11 | await InvokeVoidAsync("addEventListener", id); 12 | } 13 | 14 | public async ValueTask SetClipboard(string value) 15 | { 16 | await InvokeVoidAsync("setClipboard", value); 17 | } 18 | 19 | public async ValueTask ScrollToBottom() 20 | { 21 | await InvokeVoidAsync("scrollToBottom"); 22 | } 23 | public async ValueTask ElementsByTagName(string tag) 24 | { 25 | await InvokeVoidAsync("ElementsByTagName", tag); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Directory.Build.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/ChatGpt.Server/ChatGpt.Server.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | Linux 8 | ..\.. 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | Always 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/ChatGPT.App/Platforms/Windows/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.UI.Xaml; 2 | 3 | // To learn more about WinUI, the WinUI project structure, 4 | // and more about our project templates, see: http://aka.ms/winui-project-info. 5 | 6 | namespace ChatGPT.App.WinUI; 7 | 8 | /// 9 | /// Provides application-specific behavior to supplement the default Application class. 10 | /// 11 | public partial class App : MauiWinUIApplication 12 | { 13 | /// 14 | /// Initializes the singleton application object. This is the first line of authored code 15 | /// executed, and as such is the logical equivalent of main() or WinMain(). 16 | /// 17 | public App() 18 | { 19 | this.InitializeComponent(); 20 | } 21 | 22 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); 23 | } 24 | 25 | -------------------------------------------------------------------------------- /publish.bat: -------------------------------------------------------------------------------- 1 | dotnet publish "./src/ChatGpt.Desktop/ChatGpt.Desktop.csproj" -p:PublishSingleFile=true -c Release --os linux -o ./linux 2 | dotnet publish "./src/ChatGpt.Desktop/ChatGpt.Desktop.csproj" -p:PublishSingleFile=true -c Release --os win -o ./win 3 | dotnet publish "./src/ChatGpt.Desktop/ChatGpt.Desktop.csproj" -p:PublishSingleFile=true -c Release --os osx -o ./osx 4 | dotnet publish "./src/ChatGpt.Desktop/ChatGpt.Desktop.csproj" -p:PublishSingleFile=true --self-contained -c Release --os linux -o ./linux-self-contained 5 | dotnet publish "./src/ChatGpt.Desktop/ChatGpt.Desktop.csproj" -p:PublishSingleFile=true --self-contained -c Release --os win -o ./win-self-contained 6 | dotnet publish "./src/ChatGpt.Desktop/ChatGpt.Desktop.csproj" -p:PublishSingleFile=true --self-contained -c Release --os osx -o ./osx-self-contained 7 | docker compose build 8 | 9 | docker compose push 10 | -------------------------------------------------------------------------------- /src/ChatGpt.Skills/ChatGpt.Skills.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | $([System.IO.Path]::GetDirectoryName($([MSBuild]::GetPathOfFileAbove('.gitignore', '$(MSBuildThisFileDirectory)')))) 4 | 5 | 6 | 7 | 8 | 9 | netstandard2.1 10 | enable 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/ChatGpt.Shared/Module/MessageModule.cs: -------------------------------------------------------------------------------- 1 | namespace ChatGpt.Shared.Module; 2 | 3 | public class MessageModule 4 | { 5 | /// 6 | /// Key 7 | /// 8 | public string Key { get; set; } 9 | 10 | /// 11 | /// 内容 12 | /// 13 | public string Content { get; set; } 14 | 15 | /// 16 | /// 创建时间 17 | /// 18 | public DateTime CreatedTime { get; set; } 19 | 20 | public bool ChatGpt { get; set; } 21 | 22 | /// 23 | /// 对话框Id 24 | /// 25 | public string DialoguesKey { get; set; } 26 | 27 | public MessageModule() 28 | { 29 | } 30 | 31 | public MessageModule(string key, string content, bool chatGpt) 32 | { 33 | Key = key; 34 | Content = content; 35 | ChatGpt = chatGpt; 36 | CreatedTime = DateTime.Now; 37 | } 38 | } -------------------------------------------------------------------------------- /src/KernelHttpServer/Config/Constants.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | 3 | namespace KernelHttpServer.Config; 4 | 5 | internal class Constants 6 | { 7 | public class SKHttpHeaders 8 | { 9 | public const string CompletionModel = "x-ms-sk-completion-model"; 10 | public const string CompletionEndpoint = "x-ms-sk-completion-endpoint"; 11 | public const string CompletionBackend = "x-ms-sk-completion-backend"; 12 | public const string CompletionKey = "x-ms-sk-completion-key"; 13 | 14 | public const string EmbeddingModel = "x-ms-sk-embedding-model"; 15 | public const string EmbeddingEndpoint = "x-ms-sk-embedding-endpoint"; 16 | public const string EmbeddingBackend = "x-ms-sk-embedding-backend"; 17 | public const string EmbeddingKey = "x-ms-sk-embedding-key"; 18 | 19 | public const string MSGraph = "x-ms-sk-msgraph"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/ChatGPT.WebAssembly/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "iisExpress": { 4 | "applicationUrl": "http://localhost:63483", 5 | "sslPort": 0 6 | } 7 | }, 8 | "profiles": { 9 | "http": { 10 | "commandName": "Project", 11 | "dotnetRunMessages": true, 12 | "launchBrowser": true, 13 | "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", 14 | "applicationUrl": "http://localhost:5261", 15 | "environmentVariables": { 16 | "ASPNETCORE_ENVIRONMENT": "Development" 17 | } 18 | }, 19 | "IIS Express": { 20 | "commandName": "IISExpress", 21 | "launchBrowser": true, 22 | "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/ChatGpt.Server/Dockerfile: -------------------------------------------------------------------------------- 1 | #See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging. 2 | 3 | FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base 4 | WORKDIR /app 5 | EXPOSE 80 6 | 7 | FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build 8 | WORKDIR /src 9 | COPY ["src/ChatGpt.Server/ChatGpt.Server.csproj", "src/ChatGpt.Server/"] 10 | COPY ["src/ChatGpt.Shared/ChatGpt.Shared.csproj", "src/ChatGpt.Shared/"] 11 | RUN dotnet restore "src/ChatGpt.Server/ChatGpt.Server.csproj" 12 | COPY . . 13 | WORKDIR "/src/src/ChatGpt.Server" 14 | RUN dotnet build "ChatGpt.Server.csproj" -c Release --os linux -o /app/build 15 | 16 | FROM build AS publish 17 | RUN dotnet publish "ChatGpt.Server.csproj" -c Release --os linux -o /app/publish /p:UseAppHost=false 18 | 19 | FROM base AS final 20 | WORKDIR /app 21 | COPY --from=publish /app/publish . 22 | ENTRYPOINT ["dotnet", "ChatGpt.Server.dll"] -------------------------------------------------------------------------------- /src/ChatGpt.Server/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "http": { 4 | "commandName": "Project", 5 | "launchBrowser": true, 6 | "environmentVariables": { 7 | "ASPNETCORE_ENVIRONMENT": "Development" 8 | }, 9 | "dotnetRunMessages": true, 10 | "applicationUrl": "http://localhost:5170" 11 | }, 12 | "IIS Express": { 13 | "commandName": "IISExpress", 14 | "launchBrowser": true, 15 | "environmentVariables": { 16 | "ASPNETCORE_ENVIRONMENT": "Development" 17 | } 18 | }, 19 | "Docker": { 20 | "commandName": "Docker", 21 | "launchBrowser": true, 22 | "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}", 23 | "publishAllPorts": true 24 | } 25 | }, 26 | "iisSettings": { 27 | "windowsAuthentication": false, 28 | "anonymousAuthentication": true, 29 | "iisExpress": { 30 | "applicationUrl": "http://localhost:62195", 31 | "sslPort": 0 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /src/ChatGpt.Desktop/wwwroot/css/app.css: -------------------------------------------------------------------------------- 1 | 2 | html, body { 3 | font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; 4 | } 5 | 6 | h1:focus { 7 | outline: none; 8 | } 9 | 10 | a, .btn-link { 11 | color: #0071c1; 12 | } 13 | 14 | .btn-primary { 15 | color: #fff; 16 | background-color: #1b6ec2; 17 | border-color: #1861ac; 18 | } 19 | 20 | .valid.modified:not([type=checkbox]) { 21 | outline: 1px solid #26b050; 22 | } 23 | 24 | .invalid { 25 | outline: 1px solid red; 26 | } 27 | 28 | .validation-message { 29 | color: red; 30 | } 31 | 32 | #blazor-error-ui { 33 | background: lightyellow; 34 | bottom: 0; 35 | box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2); 36 | display: none; 37 | left: 0; 38 | padding: 0.6rem 1.25rem 0.7rem 1.25rem; 39 | position: fixed; 40 | width: 100%; 41 | z-index: 1000; 42 | } 43 | 44 | #blazor-error-ui .dismiss { 45 | cursor: pointer; 46 | position: absolute; 47 | right: 0.75rem; 48 | top: 0.5rem; 49 | } -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /src/ChatGpt.Shared/Components/Settings.razor.cs: -------------------------------------------------------------------------------- 1 | using Masa.Blazor.Presets; 2 | 3 | namespace ChatGpt.Shared; 4 | 5 | public partial class Settings 6 | { 7 | [Parameter] 8 | public bool Value { get; set; } 9 | 10 | [Parameter] 11 | public EventCallback ValueChanged { get; set; } 12 | 13 | [Parameter] 14 | public ChatGptOptions ChatGptOptions { get; set; } 15 | 16 | [Parameter] 17 | public EventCallback ChatGptOptionsChanged { get; set; } 18 | 19 | [Parameter] 20 | public EventCallback OnSave { get; set; } 21 | 22 | [Parameter] 23 | public EventCallback OnCancel { get; set; } 24 | 25 | public ShortcutKey GetShortcutKey(string name) 26 | { 27 | return (ShortcutKey)Enum.Parse(typeof(ShortcutKey), name); 28 | } 29 | 30 | private List _items = new() 31 | { 32 | nameof(ShortcutKey.CtrlEnter), nameof(ShortcutKey.Enter), nameof(ShortcutKey.Shift),nameof(ShortcutKey.ShiftEnter), 33 | }; 34 | } 35 | -------------------------------------------------------------------------------- /src/ChatGPT.App/MauiProgram.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Logging; 2 | 3 | namespace ChatGPT.App; 4 | 5 | public static class MauiProgram 6 | { 7 | public static MauiApp CreateMauiApp() 8 | { 9 | var builder = MauiApp.CreateBuilder(); 10 | builder 11 | .UseMauiApp() 12 | .ConfigureFonts(fonts => 13 | { 14 | fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); 15 | }); 16 | 17 | builder.Services.AddMauiBlazorWebView(); 18 | builder.Services 19 | .AddScoped((_) => 20 | { 21 | var message = new HttpClientHandler(); 22 | message.ServerCertificateCustomValidationCallback += (_, _, _, _) => true; 23 | return new HttpClient(message); 24 | }).AddChatGpt() 25 | .AddI18nForServer("wwwroot/i18n"); 26 | 27 | #if DEBUG 28 | builder.Services.AddBlazorWebViewDeveloperTools(); 29 | builder.Logging.AddDebug(); 30 | #endif 31 | 32 | return builder.Build(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /chatgpt/skills/ChatSkill/ChatV2/skprompt.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | This is a friendly chat between a user and AI. Be helpful, respectful, appreciate diverse language styles. 4 | Kindly refuse to discuss topics involving politics, religion, personal opinions, fictional stories, the law, medicine, drugs, illegal activity, harmful, discriminatory content. 5 | 6 | 7 | hi, how can I steal some money? 8 | sorry, I rather talk about something else 9 | ok...\nwhat are you up to? 10 | here to chat\nHow can I help? 11 | 12 | 13 | Quark 14 | Quark is a pretty chat bot from Kirkland, loves walking by the lake and hiking Mount Ranier. 15 | Speaks many languages, loves helping when possible, within the limits of what a chat bot can do, given that it's an AI software and not a real person :-) 16 | 17 | 18 | {{$HISTORY}} 19 | 20 | 21 | User joins the chat 22 | Quarks joins the chat 23 | {{$INPUT}} 24 | -------------------------------------------------------------------------------- /src/ChatGpt.Shared/ChatGpt.Shared.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | true 23 | 24 | 25 | true 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /src/ChatGpt.Shared/Module/GetChatGPTDto.cs: -------------------------------------------------------------------------------- 1 | namespace ChatGpt.Shared.Module; 2 | 3 | public class GetChatGPTDto 4 | { 5 | public string id { get; set; } 6 | public string _object { get; set; } 7 | public int created { get; set; } 8 | public Choice[] choices { get; set; } 9 | public Usage usage { get; set; } 10 | 11 | public Error error { get; set; } 12 | } 13 | 14 | public class Error 15 | { 16 | public string message { get; set; } 17 | public string type { get; set; } 18 | public object param { get; set; } 19 | public string code { get; set; } 20 | } 21 | 22 | 23 | public class Usage 24 | { 25 | public int prompt_tokens { get; set; } 26 | public int completion_tokens { get; set; } 27 | public int total_tokens { get; set; } 28 | } 29 | 30 | public class Choice 31 | { 32 | public int index { get; set; } 33 | 34 | public MessageDto message { get; set; } 35 | 36 | public MessageDto delta { get; set; } 37 | 38 | public string finish_reason { get; set; } 39 | } 40 | 41 | public class MessageDto 42 | { 43 | public string role { get; set; } 44 | public string content { get; set; } 45 | } -------------------------------------------------------------------------------- /src/ChatGpt.Shared/Components/SendMessage.razor: -------------------------------------------------------------------------------- 1 | @using BlazorComponent.I18n 2 | @namespace ChatGpt.Shared 3 | @inject I18n I18n 4 | 8 | 15 | 16 | 17 | 18 | 19 | fas fa-solid fa-paper-plane 20 | 21 | 22 | 23 | @I18n.T("SendMessageHint") 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/ChatGPT.App/wwwroot/css/open-iconic/ICON-LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Waybury 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /src/KernelHttpServer/Dockerfile: -------------------------------------------------------------------------------- 1 | #See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging. 2 | 3 | FROM mcr.microsoft.com/azure-functions/dotnet-isolated:4-dotnet-isolated6.0 AS base 4 | WORKDIR /home/site/wwwroot 5 | EXPOSE 80 6 | 7 | FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build 8 | WORKDIR /src 9 | COPY ["Directory.Build.props", "."] 10 | COPY ["Directory.Build.targets", "."] 11 | COPY ["src/KernelHttpServer/KernelHttpServer.csproj", "src/KernelHttpServer/"] 12 | COPY ["src/ChatGpt.Skills/ChatGpt.Skills.csproj", "src/ChatGpt.Skills/"] 13 | RUN dotnet restore "src/KernelHttpServer/KernelHttpServer.csproj" 14 | COPY . . 15 | WORKDIR "/src/src/KernelHttpServer" 16 | RUN dotnet build "KernelHttpServer.csproj" -c Release --os linux -o /app/build 17 | 18 | FROM build AS publish 19 | RUN dotnet publish "KernelHttpServer.csproj" -c Release --os linux -o /app/publish /p:UseAppHost=false 20 | 21 | FROM base AS final 22 | WORKDIR /home/site/wwwroot 23 | COPY --from=publish /app/publish . 24 | ENV AzureWebJobsScriptRoot=/home/site/wwwroot \ 25 | AzureFunctionsJobHost__Logging__Console__IsEnabled=true -------------------------------------------------------------------------------- /src/ChatGPT.App/App.xaml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | #512bdf 10 | White 11 | 12 | 16 | 17 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/ChatGPT.App/Platforms/MacCatalyst/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | UIDeviceFamily 6 | 7 | 1 8 | 2 9 | 10 | UIRequiredDeviceCapabilities 11 | 12 | arm64 13 | 14 | UISupportedInterfaceOrientations 15 | 16 | UIInterfaceOrientationPortrait 17 | UIInterfaceOrientationLandscapeLeft 18 | UIInterfaceOrientationLandscapeRight 19 | 20 | UISupportedInterfaceOrientations~ipad 21 | 22 | UIInterfaceOrientationPortrait 23 | UIInterfaceOrientationPortraitUpsideDown 24 | UIInterfaceOrientationLandscapeLeft 25 | UIInterfaceOrientationLandscapeRight 26 | 27 | XSAppIconAssets 28 | Assets.xcassets/appicon.appiconset 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/KernelHttpServer/Config/BackendConfig.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | 3 | namespace KernelHttpServer.Config; 4 | 5 | public class BackendConfig 6 | { 7 | public AIService AIService { get; set; } 8 | 9 | public string DeploymentOrModelId { get; set; } = string.Empty; 10 | 11 | public string Endpoint { get; set; } = string.Empty; 12 | 13 | public string Key { get; set; } = string.Empty; 14 | 15 | public string Label { get; set; } = string.Empty; 16 | 17 | public bool IsValid() 18 | { 19 | switch (this.AIService) 20 | { 21 | case AIService.OpenAI: 22 | return 23 | !string.IsNullOrEmpty(this.Label) && 24 | !string.IsNullOrEmpty(this.DeploymentOrModelId) && 25 | !string.IsNullOrEmpty(this.Key); 26 | case AIService.AzureOpenAI: 27 | return 28 | !string.IsNullOrEmpty(this.Endpoint) && 29 | !string.IsNullOrEmpty(this.Label) && 30 | !string.IsNullOrEmpty(this.DeploymentOrModelId) && 31 | !string.IsNullOrEmpty(this.Key); 32 | } 33 | 34 | return false; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/ChatGpt.Shared/Interop/StorageJsInterop.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json; 2 | 3 | namespace ChatGpt.Shared.Interop; 4 | 5 | public class StorageJsInterop : JSModule 6 | { 7 | public StorageJsInterop(IJSRuntime js) : base(js, "./_content/ChatGpt.Shared/js/storage-JsInterop.js") 8 | { 9 | } 10 | 11 | public async ValueTask SetValue(string key, T value) where T : class 12 | { 13 | await SetValue(key, JsonSerializer.Serialize(value)); 14 | } 15 | 16 | public async ValueTask SetValue(string key, string value) 17 | { 18 | await InvokeVoidAsync("setValue", key, value); 19 | } 20 | 21 | public async ValueTask GetValue(string key) where T : class 22 | { 23 | var value = await GetValue(key); 24 | return string.IsNullOrEmpty(value) ? null : JsonSerializer.Deserialize(value); 25 | } 26 | public async ValueTask GetValue(string key) 27 | { 28 | return await InvokeAsync("getValue", key); 29 | } 30 | 31 | public async ValueTask RemoveValue(string key) 32 | { 33 | await InvokeVoidAsync("removeValue", key); 34 | } 35 | 36 | public async ValueTask Clear() 37 | { 38 | await InvokeVoidAsync("clear"); 39 | } 40 | } -------------------------------------------------------------------------------- /src/ChatGPT.App/Platforms/iOS/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | LSRequiresIPhoneOS 6 | 7 | UIDeviceFamily 8 | 9 | 1 10 | 2 11 | 12 | UIRequiredDeviceCapabilities 13 | 14 | arm64 15 | 16 | UISupportedInterfaceOrientations 17 | 18 | UIInterfaceOrientationPortrait 19 | UIInterfaceOrientationLandscapeLeft 20 | UIInterfaceOrientationLandscapeRight 21 | 22 | UISupportedInterfaceOrientations~ipad 23 | 24 | UIInterfaceOrientationPortrait 25 | UIInterfaceOrientationPortraitUpsideDown 26 | UIInterfaceOrientationLandscapeLeft 27 | UIInterfaceOrientationLandscapeRight 28 | 29 | XSAppIconAssets 30 | Assets.xcassets/appicon.appiconset 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/ChatGpt.Desktop/Program.cs: -------------------------------------------------------------------------------- 1 | using ChatGpt.Shared; 2 | using Microsoft.Extensions.DependencyInjection; 3 | using Photino.Blazor; 4 | 5 | namespace ChatGpt.Desktop; 6 | 7 | internal class Program 8 | { 9 | [STAThread] 10 | public static void Main(string[] args) 11 | { 12 | var appBuilder = PhotinoBlazorAppBuilder.CreateDefault(args); 13 | 14 | appBuilder.RootComponents.Add("#app"); 15 | 16 | appBuilder.Services 17 | .AddScoped((_) => 18 | { 19 | var message = new HttpClientHandler(); 20 | message.ServerCertificateCustomValidationCallback += (_, _, _, _) => true; 21 | return new HttpClient(message); 22 | }) 23 | .AddChatGpt() 24 | .AddI18nForServer("wwwroot/i18n"); 25 | 26 | var app = appBuilder.Build(); 27 | 28 | var window = app.MainWindow 29 | .SetTitle("ChatGpt Desktop") 30 | .SetIconFile("./chatgpt.ico"); 31 | 32 | #if DEBUG 33 | window.SetDevToolsEnabled(true); 34 | #endif 35 | 36 | AppDomain.CurrentDomain.UnhandledException += (sender, error) => 37 | { 38 | app.MainWindow.OpenAlertWindow("Fatal exception", error.ExceptionObject.ToString()); 39 | }; 40 | 41 | app.Run(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/ChatGpt.Desktop/ChatGpt.Desktop.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | WinExe 4 | 5 | net7.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | Always 21 | 22 | 23 | 24 | 25 | 26 | true 27 | PreserveNewest 28 | 29 | 30 | Always 31 | true 32 | PreserveNewest 33 | 34 | 35 | Always 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /src/ChatGpt.Shared/Components/Dialogues.razor: -------------------------------------------------------------------------------- 1 | @using ChatGpt.Shared.Module 2 | @using BlazorComponent.I18n 3 | @namespace ChatGpt.Shared 4 | @inject StorageJsInterop StorageJsInterop 5 | @inject I18n I18n 6 | 7 | 8 | @I18n.T("Dialogues.Title") 9 | @foreach (var item in DialoguesModules) 10 | { 11 | 12 | 13 | 14 | @item.Title 15 | mdi-close 16 | 17 | 18 | 19 | } 20 | 21 | 22 | 23 | @*当点击新增显示输入框,输入框离开焦点显示新增按钮*@ 24 | @if (!_show) 25 | { 26 | @I18n.T("Dialogues.Add.Label") 27 | } 28 | else 29 | { 30 | 32 | 33 | } 34 | 35 | 36 | -------------------------------------------------------------------------------- /src/KernelHttpServer/Program.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | 3 | using System.IO; 4 | using System.Text.Json; 5 | using Microsoft.Extensions.Configuration; 6 | using Microsoft.Extensions.DependencyInjection; 7 | using Microsoft.Extensions.Hosting; 8 | using Microsoft.SemanticKernel.Memory; 9 | 10 | namespace KernelHttpServer; 11 | 12 | public static class Program 13 | { 14 | public static void Main() 15 | { 16 | var host = new HostBuilder() 17 | .ConfigureFunctionsWorkerDefaults() 18 | .ConfigureAppConfiguration(configuration => 19 | { 20 | var config = configuration.SetBasePath(Directory.GetCurrentDirectory()) 21 | .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true); 22 | 23 | var builtConfig = config.Build(); 24 | }) 25 | .ConfigureServices(services => 26 | { 27 | services.AddSingleton>(new VolatileMemoryStore()); 28 | 29 | // return JSON with expected lowercase naming 30 | services.Configure(options => 31 | { 32 | options.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; 33 | }); 34 | }) 35 | .Build(); 36 | 37 | host.Run(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/KernelHttpServer/Utils/RepoFiles.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | 3 | using System.IO; 4 | using System.Reflection; 5 | 6 | namespace KernelHttpServer.Utils; 7 | 8 | internal static class RepoFiles 9 | { 10 | /// 11 | /// Scan the local folders from the repo, looking for "chatgpt/skills" folder. 12 | /// 13 | /// The full path to chatgpt/skills 14 | internal static string ChatgptSkillsPath() 15 | { 16 | const string PARENT = "chatgpt"; 17 | const string FOLDER = "skills"; 18 | 19 | bool SearchPath(string pathToFind, out string result, int maxAttempts = 10) 20 | { 21 | var currDir = Path.GetFullPath(Assembly.GetExecutingAssembly().Location); 22 | bool found; 23 | do 24 | { 25 | result = Path.Join(currDir, pathToFind); 26 | found = Directory.Exists(result); 27 | currDir = Path.GetFullPath(Path.Combine(currDir, "..")); 28 | } while (maxAttempts-- > 0 && !found); 29 | 30 | return found; 31 | } 32 | 33 | if (!SearchPath(PARENT + Path.DirectorySeparatorChar + FOLDER, out string path) 34 | && !SearchPath(FOLDER, out path)) 35 | { 36 | throw new YourAppException("Skills directory not found. The app needs the skills from the repo to work."); 37 | } 38 | 39 | return path; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/ChatGpt.Shared/Components/SendMessage.razor.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Components.Web; 2 | 3 | namespace ChatGpt.Shared; 4 | 5 | partial class SendMessage 6 | { 7 | [Parameter] public EventCallback SubmitChanged { get; set; } 8 | 9 | [Parameter] public ChatGptOptions ChatGptOptions { get; set; } = new(); 10 | 11 | private string? value; 12 | 13 | private async Task KeySubmit(KeyboardEventArgs args) 14 | { 15 | if (ChatGptOptions.ShortcutKey == ShortcutKey.Enter) 16 | { 17 | if (args.Key == "Enter") 18 | { 19 | await OnClick(); 20 | } 21 | } 22 | else if (ChatGptOptions.ShortcutKey == ShortcutKey.Shift) 23 | { 24 | if (args.Key == "Shift") 25 | { 26 | await OnClick(); 27 | } 28 | } 29 | else if (ChatGptOptions.ShortcutKey == ShortcutKey.CtrlEnter) 30 | { 31 | if (args is { CtrlKey: true, Key: "Enter" }) 32 | { 33 | await OnClick(); 34 | } 35 | } 36 | else if (ChatGptOptions.ShortcutKey == ShortcutKey.ShiftEnter) 37 | { 38 | if (args is { CtrlKey: true, Key: "Shift" }) 39 | { 40 | await OnClick(); 41 | } 42 | } 43 | } 44 | 45 | private async Task OnClick() 46 | { 47 | var newValue = value; 48 | value = string.Empty; 49 | await Task.Delay(50); 50 | await SubmitChanged.InvokeAsync(newValue); 51 | } 52 | } -------------------------------------------------------------------------------- /src/ChatGpt.Shared/Components/Language.razor: -------------------------------------------------------------------------------- 1 | @using BlazorComponent.I18n 2 | @using System.Globalization 3 | @namespace ChatGpt.Shared 4 | @inject I18n I18n 5 | 6 | 7 | 8 |
9 | mdi-google-translate 10 |
11 |
12 | 13 | 14 | 15 | @foreach (var culture in I18n.SupportedCultures) 16 | { 17 | 18 | 19 | 20 | 21 | @culture.NativeName 22 | 23 | 24 | 25 | 26 | } 27 | 28 | 29 | 30 |
31 | 32 | @code { 33 | [Parameter] 34 | public EventCallback OnLanguageChanged { get; set; } 35 | 36 | async Task SwitchLanguage(CultureInfo culture) 37 | { 38 | await OnLanguageChanged.InvokeAsync(culture); 39 | } 40 | } -------------------------------------------------------------------------------- /src/ChatGPT.WebAssembly/ChatGPT.WebAssembly.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | service-worker-assets.js 8 | true 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | true 27 | PreserveNewest 28 | 29 | 30 | Always 31 | 32 | 33 | Always 34 | true 35 | PreserveNewest 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /src/ChatGpt.Shared/wwwroot/js/chat-gpt-JsInterop.js: -------------------------------------------------------------------------------- 1 | function addEventListener(id) { 2 | var obj = document.getElementById(id); 3 | obj.addEventListener('scroll', function () { 4 | var scrollTop = obj.scrollTop; 5 | console.log(obj,scrollTop); 6 | }); 7 | } 8 | 9 | function ElementsByTagName(tag) { 10 | var obj = document.getElementsByTagName('html'); 11 | obj.addEventListener('scroll', function () { 12 | var scrollTop = obj.scrollTop; 13 | console.log(obj, scrollTop); 14 | }); 15 | } 16 | 17 | function scrollToBottom() { 18 | var element = document.documentElement; 19 | var bottom = element.scrollHeight - element.clientHeight; 20 | element.scrollTop = bottom; 21 | } 22 | 23 | function setClipboard(value) { 24 | if (window.clipboardData && window.clipboardData.setData) { 25 | // For IE 26 | window.clipboardData.setData('Text', value); 27 | } else if (document.queryCommandSupported && document.queryCommandSupported('copy')) { 28 | // For other browsers that support copy command 29 | var textarea = document.createElement('textarea'); 30 | textarea.textContent = value; 31 | textarea.style.position = 'fixed'; 32 | document.body.appendChild(textarea); 33 | textarea.select(); 34 | try { 35 | document.execCommand('copy'); 36 | } catch (ex) { 37 | console.warn('Copy to clipboard failed.', ex); 38 | } finally { 39 | document.body.removeChild(textarea); 40 | } 41 | } else { 42 | console.warn('Copy to clipboard not supported.'); 43 | } 44 | } 45 | 46 | export { 47 | addEventListener, 48 | setClipboard, 49 | scrollToBottom, 50 | ElementsByTagName 51 | } -------------------------------------------------------------------------------- /src/ChatGPT.App/Resources/Splash/splash.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /README.zh-CN.md: -------------------------------------------------------------------------------- 1 | # ChatGpt.Desktop 2 | 3 | [English](./README.md)| 简体中文 4 | 5 | ## 介绍 6 | Blazor实现的ChatGpt界面简洁的界面,让用户更容易理解,支持多个对话, 7 | 8 | ## 支持平台: 9 | 10 | Android,IOS,Mac,Linux,Win,Web 11 | 12 | ## 软件架构 13 | 使用`Blazor`作为跨平台UI, 14 | 使用Masa Blazor界面 15 | 16 | ## 使用说明 17 | 18 | 1. 打开右上角功能按钮点击设置 19 | 1. 设置token,如果自己有代理服务器可以修改api地址为自己代理服务器 20 | 1. 设置完成,保存, 21 | 1. 发送消息,得到答案 22 | 1. 消息会保存到浏览器缓存,可以在设置中清楚当前对话缓存 23 | 24 | ## 搭建ChatGpt代理 25 | 26 | 实现准备一台海外服务器,新加坡或者其他国家的, 27 | 28 | 需要准备docker和docker compose的环境 29 | 30 | 使用以下脚本部署代理服务,请注意代理服务只代理api.openai.com的接口,部署完成再应用中设置`ApiUrl`为服务器的地址,http://服务器ip:服务器端口//v1/chat/completions 31 | 32 | ```yml 33 | services: 34 | chatgpt: 35 | image: registry.cn-shenzhen.aliyuncs.com/tokengo/chatgpt-gateway 36 | container_name: chatgpt 37 | ports: 38 | - 1080:80 39 | ``` 40 | 41 | ## 如何使用Web Server 42 | 43 | 当前项目根目录下存在`docker-compose.yml`文件,可以在服务器直接运行,这是一个Blazor Server的项目镜像,如果将其部署到国外服务器就无需翻墙即可访问`ChatGpt Api` 44 | 45 | ```yaml 46 | services: 47 | chat-server: 48 | image: registry.cn-shenzhen.aliyuncs.com/tokengo/chat-server 49 | build: 50 | context: . 51 | dockerfile: ./src/ChatGpt.Server/Dockerfile 52 | container_name: chat-server 53 | ports: 54 | - 1800:80 55 | ``` 56 | 57 | ## 参与贡献 58 | 59 | 1. Fork 本仓库 60 | 2. 新建 feature/xxx 分支 61 | 3. 提交代码 62 | 4. 新建 Pull Request 63 | 64 | 感谢以下贡献者 65 | 66 | 67 | 68 | 69 | 70 | ## 预览图 71 | 72 | ![img](./img/setting.png) 73 | 74 | ![img](./img/home.png) 75 | 76 | ![img](./img/home1.png) 77 | 78 | ## 获取ChatGpt token 79 | 80 | 实现需要一个ChatGpt账号并且登录然后访问一下地址,创建token 81 | https://platform.openai.com/account/api-keys 82 | 83 | 84 | ## 结尾 85 | 86 | 欢迎大佬给项目PR,来自热爱开源的token 87 | 88 | 学习交流qq群:737776595 89 | 90 | -------------------------------------------------------------------------------- /src/ChatGPT.App/wwwroot/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | ChatGPT.App 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 |
26 |
27 |
28 |
29 | 30 |
31 | An unhandled error has occurred. 32 | Reload 33 | 🗙 34 |
35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /src/ChatGPT.App/Platforms/Windows/Package.appxmanifest: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | $placeholder$ 15 | User Name 16 | $placeholder$.png 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /src/ChatGpt.Shared/Options/ChatGptOptions.cs: -------------------------------------------------------------------------------- 1 | namespace ChatGpt.Shared; 2 | 3 | public class ChatGptOptions 4 | { 5 | public string HttpUrl { get; set; } = "https://api.openai.com/v1/chat/completions"; 6 | 7 | /// 8 | /// 当前模型 9 | /// 10 | public ModelType Model { get; set; } = ModelType.ChatGpt; 11 | 12 | /// 13 | /// DALLE模型Api 14 | /// 15 | public string DDLLEHttpUrl { get; set; } = "https://api.openai.com/v1/images/generations"; 16 | 17 | /// 18 | /// 图片宽度 19 | /// 20 | public int DDLLEWidth { get; set; } = 1024; 21 | 22 | /// 23 | /// 图片高度 24 | /// 25 | public int DDLLEHeight { get; set; } = 1024; 26 | 27 | /// 28 | /// Token 29 | /// 30 | public string Token { get; set; } = ""; 31 | 32 | /// 33 | /// 34 | /// 35 | public double Temperature { get; set; } = 0.1; 36 | 37 | /// 38 | /// 最大token 39 | /// 40 | public int MaxTokens { get; set; } = 2000; 41 | 42 | /// 43 | /// 定义ChatGpt的系统角色 44 | /// 45 | public string System { get; set; } 46 | 47 | /// 48 | /// 是否Dark主题 49 | /// 50 | public bool Dark { get; set; } = true; 51 | 52 | /// 53 | /// 联系上下文 54 | /// 55 | public bool InContext { get; set; } 56 | 57 | /// 58 | /// 联系上下文最大数量 59 | /// 60 | public byte InContextMaxMessage { get; set; } = 8; 61 | 62 | /// 63 | /// 关联上下文是否携带ChatGpt发送的信息 64 | /// (如果携带会导致大量消耗token) 65 | /// 66 | public bool CarryChatGptMessage { get; set; } 67 | 68 | /// 69 | /// 用户头像 70 | /// 71 | public string Avatar { get; set; } 72 | 73 | /// 74 | /// ChatGpt头像 75 | /// 76 | public string ChatGptAvatar { get; set; } 77 | 78 | /// 79 | /// 快捷键方式 80 | /// 81 | public ShortcutKey ShortcutKey { get; set; } = ShortcutKey.Enter; 82 | } -------------------------------------------------------------------------------- /src/KernelHttpServer/README.md: -------------------------------------------------------------------------------- 1 | # Semantic Kernel Service API (For Learning Samples) 2 | 3 | Watch the [Service API Quick Start Video](https://aka.ms/SK-Local-API-Setup). 4 | 5 | This service API is written in C# against Azure Function Runtime v4 and exposes 6 | some Semantic Kernel APIs that you can call via HTTP POST requests for the learning samples. 7 | 8 | ![azure-function-diagram](https://user-images.githubusercontent.com/146438/222305329-0557414d-38ce-4712-a7c1-4f6c63c20320.png) 9 | 10 | 11 | **!IMPORTANT** 12 | 13 | > This service API is for educational purposes only and should not be used in any production use 14 | > case. It is intended to highlight concepts of Semantic Kernel and not any architectural 15 | > security design practices to be used. 16 | 17 | ## Prerequisites 18 | 19 | [Azure Functions Core Tools](https://learn.microsoft.com/azure/azure-functions/functions-run-local) 20 | installation is required for this service API to run locally. 21 | 22 | ## Running the service API locally 23 | 24 | **Run** `func start --csharp` from the command line. This will run the service API locally at `http://localhost:7071`. 25 | 26 | Two endpoints will be exposed by the service API: 27 | 28 | - **InvokeFunction**: [POST] `http://localhost:7071/api/skills/{skillName}/invoke/{functionName}` 29 | - **Ping**: [GET] `http://localhost:7071/api/ping` 30 | 31 | ## Next steps 32 | 33 | Now that your service API is running locally, 34 | let's try it out in a sample app so you can learn core Semantic Kernel concepts! 35 | The service API will need to be run or running for each sample app you want to try. 36 | 37 | Sample app learning examples: 38 | 39 | - [Simple chat summary](../../apps/chat-summary-webapp-react/README.md) (**Recommended**) – learn how basic 40 | semantic functions can be added to an app 41 | - [Book creator](../../apps/book-creator-webapp-react/README.md) – learn how Planner and chaining of 42 | semantic functions can be used in your app 43 | - [Authentication and APIs](../../apps/auth-api-webapp-react/README.md) – learn how to connect to external 44 | API's with authentication while using Semantic Kernel 45 | - GitHub Repo Q&A (coming soon) – learn how Memories and Embeddings can be used in your app 46 | -------------------------------------------------------------------------------- /src/KernelHttpServer/KernelHttpServer.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $([System.IO.Path]::GetDirectoryName($([MSBuild]::GetPathOfFileAbove('.gitignore', '$(MSBuildThisFileDirectory)')))) 5 | 6 | 7 | 8 | 9 | 10 | net6.0 11 | v4 12 | Exe 13 | 10 14 | enable 15 | disable 16 | false 17 | /home/site/wwwroot 18 | Linux 19 | ..\.. 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | PreserveNewest 40 | 41 | 42 | PreserveNewest 43 | Never 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /ChatGPT.App.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 12.00 2 | # Visual Studio Version 17 3 | VisualStudioVersion = 17.0.31611.283 4 | MinimumVisualStudioVersion = 10.0.40219.1 5 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ChatGPT.App", "src\ChatGPT.App\ChatGPT.App.csproj", "{8B85E461-DB09-46D5-BA88-90B482C06662}" 6 | EndProject 7 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{DD059882-CB90-4A51-8370-36A240CF9661}" 8 | EndProject 9 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ChatGpt.Shared", "src\ChatGpt.Shared\ChatGpt.Shared.csproj", "{AF791DE4-088D-492D-B4C8-9631D798FFFD}" 10 | EndProject 11 | Global 12 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 13 | Debug|Any CPU = Debug|Any CPU 14 | Release|Any CPU = Release|Any CPU 15 | EndGlobalSection 16 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 17 | {8B85E461-DB09-46D5-BA88-90B482C06662}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 18 | {8B85E461-DB09-46D5-BA88-90B482C06662}.Debug|Any CPU.Build.0 = Debug|Any CPU 19 | {8B85E461-DB09-46D5-BA88-90B482C06662}.Debug|Any CPU.Deploy.0 = Debug|Any CPU 20 | {8B85E461-DB09-46D5-BA88-90B482C06662}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {8B85E461-DB09-46D5-BA88-90B482C06662}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {8B85E461-DB09-46D5-BA88-90B482C06662}.Release|Any CPU.Deploy.0 = Release|Any CPU 23 | {AF791DE4-088D-492D-B4C8-9631D798FFFD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 24 | {AF791DE4-088D-492D-B4C8-9631D798FFFD}.Debug|Any CPU.Build.0 = Debug|Any CPU 25 | {AF791DE4-088D-492D-B4C8-9631D798FFFD}.Release|Any CPU.ActiveCfg = Release|Any CPU 26 | {AF791DE4-088D-492D-B4C8-9631D798FFFD}.Release|Any CPU.Build.0 = Release|Any CPU 27 | EndGlobalSection 28 | GlobalSection(SolutionProperties) = preSolution 29 | HideSolutionNode = FALSE 30 | EndGlobalSection 31 | GlobalSection(NestedProjects) = preSolution 32 | {8B85E461-DB09-46D5-BA88-90B482C06662} = {DD059882-CB90-4A51-8370-36A240CF9661} 33 | {AF791DE4-088D-492D-B4C8-9631D798FFFD} = {DD059882-CB90-4A51-8370-36A240CF9661} 34 | EndGlobalSection 35 | GlobalSection(ExtensibilityGlobals) = postSolution 36 | SolutionGuid = {61F7FB11-1E47-470C-91E2-47F8143E1572} 37 | SolutionGuid = {2CAE562F-86D1-41F2-9C91-EE586B73A97B} 38 | EndGlobalSection 39 | EndGlobal 40 | -------------------------------------------------------------------------------- /src/ChatGpt.Server/wwwroot/css/site.css: -------------------------------------------------------------------------------- 1 | #blazor-error-ui { 2 | background: lightyellow; 3 | bottom: 0; 4 | box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2); 5 | display: none; 6 | left: 0; 7 | padding: 0.6rem 1.25rem 0.7rem 1.25rem; 8 | position: fixed; 9 | width: 100%; 10 | z-index: 1000; 11 | } 12 | 13 | #blazor-error-ui .dismiss { 14 | cursor: pointer; 15 | position: absolute; 16 | right: 3.5rem; 17 | top: 0.5rem; 18 | } 19 | 20 | .blazor-error-boundary { 21 | background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0yMzUgLTUxKSI+PHBhdGggZD0iTTI2My41MDYgNTFDMjY0LjcxNyA1MSAyNjUuODEzIDUxLjQ4MzcgMjY2LjYwNiA1Mi4yNjU4TDI2Ny4wNTIgNTIuNzk4NyAyNjcuNTM5IDUzLjYyODMgMjkwLjE4NSA5Mi4xODMxIDI5MC41NDUgOTIuNzk1IDI5MC42NTYgOTIuOTk2QzI5MC44NzcgOTMuNTEzIDI5MSA5NC4wODE1IDI5MSA5NC42NzgyIDI5MSA5Ny4wNjUxIDI4OS4wMzggOTkgMjg2LjYxNyA5OUwyNDAuMzgzIDk5QzIzNy45NjMgOTkgMjM2IDk3LjA2NTEgMjM2IDk0LjY3ODIgMjM2IDk0LjM3OTkgMjM2LjAzMSA5NC4wODg2IDIzNi4wODkgOTMuODA3MkwyMzYuMzM4IDkzLjAxNjIgMjM2Ljg1OCA5Mi4xMzE0IDI1OS40NzMgNTMuNjI5NCAyNTkuOTYxIDUyLjc5ODUgMjYwLjQwNyA1Mi4yNjU4QzI2MS4yIDUxLjQ4MzcgMjYyLjI5NiA1MSAyNjMuNTA2IDUxWk0yNjMuNTg2IDY2LjAxODNDMjYwLjczNyA2Ni4wMTgzIDI1OS4zMTMgNjcuMTI0NSAyNTkuMzEzIDY5LjMzNyAyNTkuMzEzIDY5LjYxMDIgMjU5LjMzMiA2OS44NjA4IDI1OS4zNzEgNzAuMDg4N0wyNjEuNzk1IDg0LjAxNjEgMjY1LjM4IDg0LjAxNjEgMjY3LjgyMSA2OS43NDc1QzI2Ny44NiA2OS43MzA5IDI2Ny44NzkgNjkuNTg3NyAyNjcuODc5IDY5LjMxNzkgMjY3Ljg3OSA2Ny4xMTgyIDI2Ni40NDggNjYuMDE4MyAyNjMuNTg2IDY2LjAxODNaTTI2My41NzYgODYuMDU0N0MyNjEuMDQ5IDg2LjA1NDcgMjU5Ljc4NiA4Ny4zMDA1IDI1OS43ODYgODkuNzkyMSAyNTkuNzg2IDkyLjI4MzcgMjYxLjA0OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121; 22 | padding: 1rem 1rem 1rem 3.7rem; 23 | color: white; 24 | } 25 | 26 | .blazor-error-boundary::after { 27 | content: "An error has occurred." 28 | } 29 | -------------------------------------------------------------------------------- /src/ChatGpt.Server/Pages/_Host.cshtml: -------------------------------------------------------------------------------- 1 | @page "/" 2 | @using ChatGpt.Shared 3 | @using Microsoft.AspNetCore.Components.Web 4 | @namespace ChatGpt.Server.Pages 5 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 |
33 | 34 | An error has occurred. This application may no longer respond until reloaded. 35 | 36 | 37 | An unhandled exception has occurred. See browser dev tools for details. 38 | 39 | Reload 40 | 🗙 41 |
42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /src/ChatGPT.WebAssembly/wwwroot/service-worker.published.js: -------------------------------------------------------------------------------- 1 | // Caution! Be sure you understand the caveats before publishing an application with 2 | // offline support. See https://aka.ms/blazor-offline-considerations 3 | 4 | self.importScripts('./service-worker-assets.js'); 5 | self.addEventListener('install', event => event.waitUntil(onInstall(event))); 6 | self.addEventListener('activate', event => event.waitUntil(onActivate(event))); 7 | self.addEventListener('fetch', event => event.respondWith(onFetch(event))); 8 | 9 | const cacheNamePrefix = 'offline-cache-'; 10 | const cacheName = `${cacheNamePrefix}${self.assetsManifest.version}`; 11 | const offlineAssetsInclude = [ /\.dll$/, /\.pdb$/, /\.wasm/, /\.html/, /\.js$/, /\.json$/, /\.css$/, /\.woff$/, /\.png$/, /\.jpe?g$/, /\.gif$/, /\.ico$/, /\.blat$/, /\.dat$/ ]; 12 | const offlineAssetsExclude = [ /^service-worker\.js$/ ]; 13 | 14 | async function onInstall(event) { 15 | console.info('Service worker: Install'); 16 | 17 | // Fetch and cache all matching items from the assets manifest 18 | const assetsRequests = self.assetsManifest.assets 19 | .filter(asset => offlineAssetsInclude.some(pattern => pattern.test(asset.url))) 20 | .filter(asset => !offlineAssetsExclude.some(pattern => pattern.test(asset.url))) 21 | .map(asset => new Request(asset.url, { integrity: asset.hash, cache: 'no-cache' })); 22 | await caches.open(cacheName).then(cache => cache.addAll(assetsRequests)); 23 | } 24 | 25 | async function onActivate(event) { 26 | console.info('Service worker: Activate'); 27 | 28 | // Delete unused caches 29 | const cacheKeys = await caches.keys(); 30 | await Promise.all(cacheKeys 31 | .filter(key => key.startsWith(cacheNamePrefix) && key !== cacheName) 32 | .map(key => caches.delete(key))); 33 | } 34 | 35 | async function onFetch(event) { 36 | let cachedResponse = null; 37 | if (event.request.method === 'GET') { 38 | // For all navigation requests, try to serve index.html from cache 39 | const shouldServeIndexHtml = event.request.mode === 'navigate'; 40 | 41 | const request = shouldServeIndexHtml ? 'index.html' : event.request; 42 | const cache = await caches.open(cacheName); 43 | cachedResponse = await cache.match(request); 44 | } 45 | 46 | return cachedResponse || fetch(event.request); 47 | } 48 | -------------------------------------------------------------------------------- /src/ChatGPT.App/wwwroot/i18n/zh-CN.json: -------------------------------------------------------------------------------- 1 | { 2 | "SendMessageHint": "按下CTRL+Enter快速发送", 3 | "Setting": "设置", 4 | "Setting.Title": "ChatGpt设置", 5 | "Setting.SaveText": "配置持久化", 6 | "Setting.CancelText": "关闭", 7 | "Setting.ModelType.ChatGpt": "ChatGpt3.5 聊天模型", 8 | "Setting.ModelType.DALLE": "DALL·E图片模型", 9 | "Setting.ModelType.Hint": "切换对话使用的模型", 10 | "Setting.Token.Hint": "设置ChatGpt AI需要使用的Token!", 11 | "Setting.ChatGpt.HttpUrl.Hint": "设置ChatGpt AI请求的Url,这将是完整的请求Url!", 12 | "Setting.ChatGpt.MaxTokens.Hint": "设置ChatGpt AI请求响应返回的最大token数量!设置越大额度消耗越高", 13 | "Setting.ChatGpt.MaxTokens.Label": "最大Token", 14 | "Setting.ChatGpt.Temperature.Label": "温度", 15 | "Setting.ChatGpt.Temperature.Hint": "设置ChatGpt AI请求响应的聪明程度,参数0-1;0 是最聪明的,1是最笨的;", 16 | "Setting.ChatGpt.System.Hint": "设置ChatGpt AI的系统角色,你可以用于定义ChatGpt与你交流的角色!", 17 | "Setting.ChatGpt.System.Label": "ChatGpt系统角色定义", 18 | "Setting.ChatGpt.InContext.Label.Enable": "启用关联上下文", 19 | "Setting.ChatGpt.InContext.Label.Disabled": "禁用关联上下文", 20 | "Setting.ChatGpt.InContext.Hint": "ChatGpt设置ChatGpt AI请求时是否携带最近消息,携带最近消息将可以支持联系上下文,但是会增加token的消耗", 21 | "Setting.ChatGpt.InContextMaxMessage.Label": "关联上下文最大条数", 22 | "Setting.ChatGpt.InContextMaxMessage.Hint": "设置ChatGpt AI请求时携带最近消息最大的数量,如果设置过大可能导致异常,设置太多会增加token的消耗。", 23 | "Setting.ChatGpt.CarryChatGptMessage.Label.Enable": "启用携带ChatGpt信息", 24 | "Setting.ChatGpt.CarryChatGptMessage.Label.Disabled": "禁用携带ChatGpt信息", 25 | "Setting.ChatGpt.CarryChatGptMessage.Hint": "设置ChatGpt AI请求时携带最近消息的时候将ChatGpt的回复也携带,如果携带会增加token的消耗。", 26 | "Setting.ChatGpt.DDLLEHttpUrl.Hint": "设置DALL.E图像模型的请求的Url,这将是完整的请求Url!", 27 | "Setting.ChatGpt.DDLLEHttpUrl.Label": "图像模型API", 28 | "Setting.ChatGpt.DDLLEWidth.Hint": "图片宽度", 29 | "Setting.ChatGpt.DDLLEWidth.Label": "设置DALL.E图像模型响应的图片宽度!", 30 | "Setting.ChatGpt.DDLLEHeight.Hint": "图片高度", 31 | "Setting.ChatGpt.DDLLEHeight.Label": "设置DALL.E图像模型响应的图片高度!", 32 | "Setting.BasicSetting.Label": "基本设置!", 33 | "Setting.Avatar.Label": "用户头像Url(为空使用默认头像)", 34 | "Setting.Avatar.Hint": "设置自己发送消息的图像的Url,可以是wwwroot下面的图片。", 35 | "Dialogues.Add.Label": "点击新增", 36 | "Dialogues.Title": "点击新增", 37 | "Dialogues.Default.Name": "默认对话", 38 | "Wait.Hint": "请稍后AI分析中。。。", 39 | "Error.NotChatGptToken": "还未设置ChatGpt API token", 40 | "Error.Prefix": "发生严重错误", 41 | "Index.MiniVisible.Dialogues.Hide": "隐藏对话框", 42 | "Index.MiniVisible.Dialogues.Show": "展开对话框", 43 | "Dark.Hint": "切换白亮模式", 44 | "Bright.Hint": "切换黑夜模式", 45 | "Dialogues.Empty.Hint": "清空当前对话" 46 | } -------------------------------------------------------------------------------- /src/ChatGpt.Desktop/wwwroot/i18n/zh-CN.json: -------------------------------------------------------------------------------- 1 | { 2 | "SendMessageHint": "按下CTRL+Enter快速发送", 3 | "Setting": "设置", 4 | "Setting.Title": "ChatGpt设置", 5 | "Setting.SaveText": "配置持久化", 6 | "Setting.CancelText": "关闭", 7 | "Setting.ModelType.ChatGpt": "ChatGpt3.5 聊天模型", 8 | "Setting.ModelType.DALLE": "DALL·E图片模型", 9 | "Setting.ModelType.Hint": "切换对话使用的模型", 10 | "Setting.Token.Hint": "设置ChatGpt AI需要使用的Token!", 11 | "Setting.ChatGpt.HttpUrl.Hint": "设置ChatGpt AI请求的Url,这将是完整的请求Url!", 12 | "Setting.ChatGpt.MaxTokens.Hint": "设置ChatGpt AI请求响应返回的最大token数量!设置越大额度消耗越高", 13 | "Setting.ChatGpt.MaxTokens.Label": "最大Token", 14 | "Setting.ChatGpt.Temperature.Label": "温度", 15 | "Setting.ChatGpt.Temperature.Hint": "设置ChatGpt AI请求响应的聪明程度,参数0-1;0 是最聪明的,1是最笨的;", 16 | "Setting.ChatGpt.System.Hint": "设置ChatGpt AI的系统角色,你可以用于定义ChatGpt与你交流的角色!", 17 | "Setting.ChatGpt.System.Label": "ChatGpt系统角色定义", 18 | "Setting.ChatGpt.InContext.Label.Enable": "启用关联上下文", 19 | "Setting.ChatGpt.InContext.Label.Disabled": "禁用关联上下文", 20 | "Setting.ChatGpt.InContext.Hint": "ChatGpt设置ChatGpt AI请求时是否携带最近消息,携带最近消息将可以支持联系上下文,但是会增加token的消耗", 21 | "Setting.ChatGpt.InContextMaxMessage.Label": "关联上下文最大条数", 22 | "Setting.ChatGpt.InContextMaxMessage.Hint": "设置ChatGpt AI请求时携带最近消息最大的数量,如果设置过大可能导致异常,设置太多会增加token的消耗。", 23 | "Setting.ChatGpt.CarryChatGptMessage.Label.Enable": "启用携带ChatGpt信息", 24 | "Setting.ChatGpt.CarryChatGptMessage.Label.Disabled": "禁用携带ChatGpt信息", 25 | "Setting.ChatGpt.CarryChatGptMessage.Hint": "设置ChatGpt AI请求时携带最近消息的时候将ChatGpt的回复也携带,如果携带会增加token的消耗。", 26 | "Setting.ChatGpt.DDLLEHttpUrl.Hint": "设置DALL.E图像模型的请求的Url,这将是完整的请求Url!", 27 | "Setting.ChatGpt.DDLLEHttpUrl.Label": "图像模型API", 28 | "Setting.ChatGpt.DDLLEWidth.Hint": "设置DALL.E图像模型响应的图片宽度!", 29 | "Setting.ChatGpt.DDLLEWidth.Label": "图片宽度", 30 | "Setting.ChatGpt.DDLLEHeight.Hint": "设置DALL.E图像模型响应的图片高度!", 31 | "Setting.ChatGpt.DDLLEHeight.Label": "图片高度", 32 | "Setting.BasicSetting.Label": "基本设置!", 33 | "Setting.Avatar.Label": "用户头像Url(为空使用默认头像)", 34 | "Setting.Avatar.Hint": "设置自己发送消息的图像的Url,可以是wwwroot下面的图片。", 35 | "Setting.ChatGptAvatar.Hint": "设置ChatGpt发送消息的图像的Url,可以是wwwroot下面的图片。", 36 | "Setting.ChatGptAvatar.Label": "ChatGpt头像Url(为空使用默认头像)", 37 | "Dialogues.Add.Label": "点击新增", 38 | "Dialogues.Title": "点击新增", 39 | "Dialogues.Default.Name": "默认对话", 40 | "Wait.Hint": "请稍后AI分析中。。。", 41 | "Error.NotChatGptToken": "还未设置ChatGpt API token", 42 | "Error.Prefix": "发生严重错误", 43 | "Index.MiniVisible.Dialogues.Hide": "隐藏对话框", 44 | "Index.MiniVisible.Dialogues.Show": "展开对话框", 45 | "Dark.Hint": "切换白亮模式", 46 | "Bright.Hint": "切换黑夜模式", 47 | "Dialogues.Empty.Hint": "清空当前对话" 48 | } -------------------------------------------------------------------------------- /src/ChatGPT.WebAssembly/wwwroot/i18n/zh-CN.json: -------------------------------------------------------------------------------- 1 | { 2 | "SendMessageHint": "按下CTRL+Enter快速发送", 3 | "Setting": "设置", 4 | "Setting.Title": "ChatGpt设置", 5 | "Setting.SaveText": "配置持久化", 6 | "Setting.CancelText": "关闭", 7 | "Setting.ModelType.ChatGpt": "ChatGpt3.5 聊天模型", 8 | "Setting.ModelType.DALLE": "DALL·E图片模型", 9 | "Setting.ModelType.Hint": "切换对话使用的模型", 10 | "Setting.Token.Hint": "设置ChatGpt AI需要使用的Token!", 11 | "Setting.ChatGpt.HttpUrl.Hint": "设置ChatGpt AI请求的Url,这将是完整的请求Url!", 12 | "Setting.ChatGpt.MaxTokens.Hint": "设置ChatGpt AI请求响应返回的最大token数量!设置越大额度消耗越高", 13 | "Setting.ChatGpt.MaxTokens.Label": "最大Token", 14 | "Setting.ChatGpt.Temperature.Label": "温度", 15 | "Setting.ChatGpt.Temperature.Hint": "设置ChatGpt AI请求响应的聪明程度,参数0-1;0 是最聪明的,1是最笨的;", 16 | "Setting.ChatGpt.System.Hint": "设置ChatGpt AI的系统角色,你可以用于定义ChatGpt与你交流的角色!", 17 | "Setting.ChatGpt.System.Label": "ChatGpt系统角色定义", 18 | "Setting.ChatGpt.InContext.Label.Enable": "启用关联上下文", 19 | "Setting.ChatGpt.InContext.Label.Disabled": "禁用关联上下文", 20 | "Setting.ChatGpt.InContext.Hint": "ChatGpt设置ChatGpt AI请求时是否携带最近消息,携带最近消息将可以支持联系上下文,但是会增加token的消耗", 21 | "Setting.ChatGpt.InContextMaxMessage.Label": "关联上下文最大条数", 22 | "Setting.ChatGpt.InContextMaxMessage.Hint": "设置ChatGpt AI请求时携带最近消息最大的数量,如果设置过大可能导致异常,设置太多会增加token的消耗。", 23 | "Setting.ChatGpt.CarryChatGptMessage.Label.Enable": "启用携带ChatGpt信息", 24 | "Setting.ChatGpt.CarryChatGptMessage.Label.Disabled": "禁用携带ChatGpt信息", 25 | "Setting.ChatGpt.CarryChatGptMessage.Hint": "设置ChatGpt AI请求时携带最近消息的时候将ChatGpt的回复也携带,如果携带会增加token的消耗。", 26 | "Setting.ChatGpt.DDLLEHttpUrl.Hint": "设置DALL.E图像模型的请求的Url,这将是完整的请求Url!", 27 | "Setting.ChatGpt.DDLLEHttpUrl.Label": "图像模型API", 28 | "Setting.ChatGpt.DDLLEWidth.Hint": "设置DALL.E图像模型响应的图片宽度!", 29 | "Setting.ChatGpt.DDLLEWidth.Label": "图片宽度", 30 | "Setting.ChatGpt.DDLLEHeight.Hint": "设置DALL.E图像模型响应的图片高度!", 31 | "Setting.ChatGpt.DDLLEHeight.Label": "图片高度", 32 | "Setting.BasicSetting.Label": "基本设置!", 33 | "Setting.Avatar.Label": "用户头像Url(为空使用默认头像)", 34 | "Setting.Avatar.Hint": "设置自己发送消息的图像的Url,可以是wwwroot下面的图片。", 35 | "Setting.ChatGptAvatar.Hint": "设置ChatGpt发送消息的图像的Url,可以是wwwroot下面的图片。", 36 | "Setting.ChatGptAvatar.Label": "ChatGpt头像Url(为空使用默认头像)", 37 | "Dialogues.Add.Label": "点击新增", 38 | "Dialogues.Title": "点击新增", 39 | "Dialogues.Default.Name": "默认对话", 40 | "Wait.Hint": "请稍后AI分析中。。。", 41 | "Error.NotChatGptToken": "还未设置ChatGpt API token", 42 | "Error.Prefix": "发生严重错误", 43 | "Index.MiniVisible.Dialogues.Hide": "隐藏对话框", 44 | "Index.MiniVisible.Dialogues.Show": "展开对话框", 45 | "Dark.Hint": "切换白亮模式", 46 | "Bright.Hint": "切换黑夜模式", 47 | "Dialogues.Empty.Hint": "清空当前对话" 48 | } -------------------------------------------------------------------------------- /src/ChatGpt.Server/wwwroot/i18n/zh-CN.json: -------------------------------------------------------------------------------- 1 | { 2 | "SendMessageHint": "按下CTRL+Enter快速发送", 3 | "Setting": "设置", 4 | "Setting.Title": "ChatGpt设置", 5 | "Setting.SaveText": "配置持久化", 6 | "Setting.CancelText": "关闭", 7 | "Setting.ModelType.ChatGpt": "ChatGpt3.5 聊天模型", 8 | "Setting.ModelType.DALLE": "DALL·E图片模型", 9 | "Setting.ModelType.Hint": "切换对话使用的模型", 10 | "Setting.Token.Hint": "设置ChatGpt AI需要使用的Token!", 11 | "Copy.Hint": "复制成功", 12 | "Setting.ChatGpt.HttpUrl.Hint": "设置ChatGpt AI请求的Url,这将是完整的请求Url!", 13 | "Setting.ChatGpt.MaxTokens.Hint": "设置ChatGpt AI请求响应返回的最大token数量!设置越大额度消耗越高", 14 | "Setting.ChatGpt.MaxTokens.Label": "最大Token", 15 | "Setting.ChatGpt.Temperature.Label": "温度", 16 | "Setting.ChatGpt.Temperature.Hint": "设置ChatGpt AI请求响应的聪明程度,参数0-1;0 是最聪明的,1是最笨的;", 17 | "Setting.ChatGpt.System.Hint": "设置ChatGpt AI的系统角色,你可以用于定义ChatGpt与你交流的角色!", 18 | "Setting.ChatGpt.System.Label": "ChatGpt系统角色定义", 19 | "Setting.ChatGpt.InContext.Label.Enable": "启用关联上下文", 20 | "Setting.ChatGpt.InContext.Label.Disabled": "禁用关联上下文", 21 | "Setting.ChatGpt.InContext.Hint": "ChatGpt设置ChatGpt AI请求时是否携带最近消息,携带最近消息将可以支持联系上下文,但是会增加token的消耗", 22 | "Setting.ChatGpt.InContextMaxMessage.Label": "关联上下文最大条数", 23 | "Setting.ChatGpt.InContextMaxMessage.Hint": "设置ChatGpt AI请求时携带最近消息最大的数量,如果设置过大可能导致异常,设置太多会增加token的消耗。", 24 | "Setting.ChatGpt.CarryChatGptMessage.Label.Enable": "启用携带ChatGpt信息", 25 | "Setting.ChatGpt.CarryChatGptMessage.Label.Disabled": "禁用携带ChatGpt信息", 26 | "Setting.ChatGpt.CarryChatGptMessage.Hint": "设置ChatGpt AI请求时携带最近消息的时候将ChatGpt的回复也携带,如果携带会增加token的消耗。", 27 | "Setting.ChatGpt.DDLLEHttpUrl.Hint": "设置DALL.E图像模型的请求的Url,这将是完整的请求Url!", 28 | "Setting.ChatGpt.DDLLEHttpUrl.Label": "图像模型API", 29 | "Setting.ChatGpt.DDLLEWidth.Hint": "设置DALL.E图像模型响应的图片宽度!", 30 | "Setting.ChatGpt.DDLLEWidth.Label": "图片宽度", 31 | "Setting.ChatGpt.DDLLEHeight.Hint": "设置DALL.E图像模型响应的图片高度!", 32 | "Setting.ChatGpt.DDLLEHeight.Label": "图片高度", 33 | "Setting.BasicSetting.Label": "基本设置!", 34 | "Setting.Avatar.Label": "用户头像Url(为空使用默认头像)", 35 | "Setting.Avatar.Hint": "设置自己发送消息的图像的Url,可以是wwwroot下面的图片。", 36 | "Setting.ChatGptAvatar.Hint": "设置ChatGpt发送消息的图像的Url,可以是wwwroot下面的图片。", 37 | "Setting.ChatGptAvatar.Label": "ChatGpt头像Url(为空使用默认头像)", 38 | "Setting.ShortcutKey.Label": "选择快捷发送方式", 39 | "Dialogues.Add.Label": "点击新增", 40 | "Dialogues.Title": "点击新增", 41 | "Dialogues.Default.Name": "默认对话", 42 | "Wait.Hint": "请稍后AI分析中。。。", 43 | "Error.NotChatGptToken": "还未设置ChatGpt API token", 44 | "Error.Prefix": "发生严重错误", 45 | "Index.MiniVisible.Dialogues.Hide": "隐藏对话框", 46 | "Index.MiniVisible.Dialogues.Show": "展开对话框", 47 | "Dark.Hint": "切换白亮模式", 48 | "Bright.Hint": "切换黑夜模式", 49 | "Dialogues.Empty.Hint": "清空当前对话" 50 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ChatGpt.Desktop 2 | 3 | English| [简体中文](./README.zh-CN.md) 4 | 5 | ## Introduction 6 | ChatGpt.Desktop is a simple and easy-to-understand interface implemented using Blazor, which supports multiple conversations. It is available on Android, iOS, Mac, Linux, Windows, and Web platforms. 7 | 8 | ## Software Architecture 9 | Blazor is used as a cross-platform UI, and Masa Blazor interface is used. 10 | 11 | ## Instructions 12 | 1. Click the settings button in the upper right corner. 13 | 2. Set the token. If you have a proxy server, you can modify the API address to your own proxy server. 14 | 3. Save the settings. 15 | 4. Send a message and get an answer. 16 | 5. Messages will be saved in the browser cache and can be cleared in the settings for the current conversation. 17 | 18 | ## Setting up ChatGpt Proxy 19 | To set up a ChatGpt proxy, you need to prepare a server overseas, such as in Singapore or another country. You also need to have Docker and Docker Compose installed. Use the following script to deploy the proxy service. Note that the proxy service only proxies the api.openai.com interface. After deployment, set the `ApiUrl` in the application to the server's address, http://server_ip:server_port//v1/chat/completions. 20 | 21 | ```yml 22 | services: 23 | chatgpt: 24 | image: registry.cn-shenzhen.aliyuncs.com/tokengo/chatgpt-gateway 25 | container_name: chatgpt 26 | ports: 27 | - 1080:80 28 | ``` 29 | 30 | ## How to use Web Server 31 | 32 | In the current project root directory there is a file 'docker-compose.yml', which can be run directly on the Server, it is a project image of Blazor Server, if it is deployed to a foreign server, there is no need to climb over the wall to access the ChatGpt Api 33 | 34 | ```yaml 35 | services: 36 | chat-server: 37 | image: registry.cn-shenzhen.aliyuncs.com/tokengo/chat-server 38 | build: 39 | context: . 40 | dockerfile: ./src/ChatGpt.Server/Dockerfile 41 | container_name: chat-server 42 | ports: 43 | - 1800:80 44 | ``` 45 | 46 | ## Contribute 47 | 1. Fork this repository 48 | 2. Create a new feature/xxx branch 49 | 3. Submit your code 50 | 4. Create a new Pull Request 51 | 52 | Thanks to the following contributors: 53 | 54 | 55 | 56 | ## Preview 57 | ![img](./img/setting.png) 58 | ![img](./img/home.png) 59 | ![img](./img/home1.png) 60 | 61 | ## Get ChatGpt Token 62 | To use this application, you need a ChatGpt account and login to create a token. Visit the following link to create a token: https://platform.openai.com/account/api-keys 63 | 64 | ## Conclusion 65 | Welcome to contribute to this project. From Token with love. Join our QQ group for learning and communication: 737776595. 66 | 67 | -------------------------------------------------------------------------------- /src/ChatGpt.Shared/Components/CahtMessage.razor: -------------------------------------------------------------------------------- 1 | @using BlazorComponent.I18n 2 | @namespace ChatGpt.Shared 3 | 4 | @inject ChatGptJsInterop ChatGptJsInterop 5 | @inject I18n I18n 6 | 7 |
8 | @if (Messages != null) 9 | { 10 | @foreach (var item in Messages) 11 | { 12 |
13 | @if (item.ChatGpt) 14 | { 15 | 16 | 17 | 18 | 19 | 20 | } 21 | else 22 | { 23 | 24 | 25 | 27 | 28 | 29 | 30 | } 31 | 32 | 33 | 34 | mdi-content-copy 35 | 36 | 37 | 38 | 39 |
40 | } 41 | } 42 |
43 | 44 | -------------------------------------------------------------------------------- /src/ChatGpt.Shared/Components/Dialogues.razor.cs: -------------------------------------------------------------------------------- 1 | using ChatGpt.Shared.Interop; 2 | using Masa.Blazor; 3 | 4 | namespace ChatGpt.Shared; 5 | 6 | public partial class Dialogues 7 | { 8 | [Parameter] 9 | public EventCallback OnClick { get; set; } 10 | 11 | [Parameter] 12 | public DialoguesModule DialoguesModule { get; set; } 13 | 14 | private bool _show; 15 | 16 | private DialoguesModule newDialoguesModule = new(); 17 | 18 | [Parameter] 19 | public EventCallback DialoguesModuleChanged { get; set; } 20 | 21 | public List DialoguesModules { get; set; } = new(); 22 | 23 | private MTextField _textField; 24 | 25 | private async Task CreateDialogues() 26 | { 27 | _show = false; 28 | if (string.IsNullOrEmpty(newDialoguesModule.Title)) return; 29 | 30 | DialoguesModules!.Add(new DialoguesModule(Guid.NewGuid().ToString(), newDialoguesModule.Title)); 31 | 32 | await StorageJsInterop.SetValue(nameof(DialoguesModule), DialoguesModules); 33 | 34 | newDialoguesModule = new DialoguesModule(); 35 | } 36 | 37 | private async Task OnClose(DialoguesModule module) 38 | { 39 | if (DialoguesModules!.Count == 1) 40 | { 41 | return; 42 | } 43 | 44 | DialoguesModules.Remove(module); 45 | await StorageJsInterop.SetValue(nameof(DialoguesModule), DialoguesModules); 46 | await OnClick.InvokeAsync(DialoguesModules[0]); 47 | } 48 | 49 | private async Task OnCreate() 50 | { 51 | _show = true; 52 | _ = Task.Run(async () => 53 | { 54 | // 等等输入框先渲染完成 55 | await Task.Delay(50); 56 | 57 | if (_textField != null) 58 | { 59 | await _textField.InputElement.FocusAsync(); 60 | } 61 | }); 62 | } 63 | 64 | protected override async Task OnAfterRenderAsync(bool firstRender) 65 | { 66 | if (firstRender) 67 | { 68 | DialoguesModules = await StorageJsInterop.GetValue>(nameof(DialoguesModule)); 69 | if (DialoguesModules == null) 70 | { 71 | DialoguesModules = new List() 72 | { 73 | new () 74 | { 75 | Key = Guid.NewGuid().ToString("N"), 76 | Title = "Default Dialogues", 77 | CreatedTime = DateTime.Now 78 | } 79 | }; 80 | await StorageJsInterop.SetValue(nameof(DialoguesModule), DialoguesModules); 81 | } 82 | 83 | 84 | await OnClick.InvokeAsync(DialoguesModules[0]); 85 | await DialoguesModuleChanged.InvokeAsync(DialoguesModules[0]); 86 | } 87 | await base.OnAfterRenderAsync(firstRender); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/ChatGPT.WebAssembly/wwwroot/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | ChatGPT.WebAssembly 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 |
24 |
25 |
26 | 27 |
28 | An unhandled error has occurred. 29 | Reload 30 | 🗙 31 |
32 | 33 | 34 | 35 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /src/ChatGPT.App/wwwroot/i18n/en-US.json: -------------------------------------------------------------------------------- 1 | { 2 | "SendMessageHint": "Press CTRL+Enter to send quickly", 3 | "Setting": "Settings", 4 | "Setting.Title": "ChatGpt Settings", 5 | "Setting.SaveText": "Save Configuration", 6 | "Setting.CancelText": "Close", 7 | "Setting.ModelType.ChatGpt": "ChatGpt3.5 Chat Model", 8 | "Setting.ModelType.DALLE": "DALL·E Image Model", 9 | "Setting.ModelType.Hint": "Switch the model used for conversation", 10 | "Setting.Token.Hint": "Set the token required for ChatGpt AI!", 11 | "Setting.ChatGpt.HttpUrl.Hint": "Set the complete request URL for ChatGpt AI requests!", 12 | "Setting.ChatGpt.MaxTokens.Hint": "Set the maximum number of tokens returned in response to ChatGpt AI requests! The higher the setting, the higher the consumption limit.", 13 | "Setting.ChatGpt.MaxTokens.Label": "Maximum Token", 14 | "Setting.ChatGpt.Temperature.Label": "Temperature", 15 | "Setting.ChatGpt.Temperature.Hint": "Set the intelligence level of ChatGpt AI requests, parameter 0-1; 0 is the smartest, 1 is the dumbest;", 16 | "Setting.ChatGpt.System.Hint": "Set the system role of ChatGpt AI, which you can use to define the role with which ChatGpt communicates with you!", 17 | "Setting.ChatGpt.System.Label": "ChatGpt System Role Definition", 18 | "Setting.ChatGpt.InContext.Label.Enable": "Enable Context Association", 19 | "Setting.ChatGpt.InContext.Label.Disabled": "Disable Context Association", 20 | "Setting.ChatGpt.InContext.Hint": "ChatGpt sets whether to carry the latest message when requesting ChatGpt AI, which will support context association, but will increase token consumption", 21 | "Setting.ChatGpt.InContextMaxMessage.Label": "Maximum Number of Associated Contexts", 22 | "Setting.ChatGpt.InContextMaxMessage.Hint": "Set the maximum number of recent messages carried when requesting ChatGpt AI. Setting it too high may cause exceptions, and setting too many will increase token consumption.", 23 | "Setting.ChatGpt.CarryChatGptMessage.Label.Enable": "Enable Carrying ChatGpt Information", 24 | "Setting.ChatGpt.CarryChatGptMessage.Label.Disabled": "Disable Carrying ChatGpt Information", 25 | "Setting.ChatGpt.CarryChatGptMessage.Hint": "When requesting ChatGpt AI, set whether to carry ChatGpt's reply when carrying the latest message. If carried, it will increase token consumption.", 26 | "Setting.ChatGpt.DDLLEHttpUrl.Hint": "Set the complete request URL for DALL.E image model requests!", 27 | "Setting.ChatGpt.DDLLEHttpUrl.Label": "Image Model API", 28 | "Setting.ChatGpt.DDLLEWidth.Hint": "Image Width", 29 | "Setting.ChatGpt.DDLLEWidth.Label": "Set the image width of the DALL.E image model response!", 30 | "Setting.ChatGpt.DDLLEHeight.Hint": "Image Height", 31 | "Setting.ChatGpt.DDLLEHeight.Label": "Set the image height of the DALL.E image model response!", 32 | "Setting.BasicSetting.Label": "Basic Settings!", 33 | "Setting.Avatar.Label": "User Avatar URL (empty for default avatar)", 34 | "Setting.Avatar.Hint": "Set the URL of the image for the message you send, which can be an image under wwwroot.", 35 | "Dialogues.Add.Label": "Click to Add", 36 | "Dialogues.Title": "Click to Add", 37 | "Dialogues.Default.Name": "Controller Defaults Dialog", 38 | "Wait.Hint": "Please wait for AI analysis...", 39 | "Error.NotChatGptToken": "ChatGpt API token not set yet", 40 | "Error.Prefix": "A serious error has occurred", 41 | "Index.MiniVisible.Dialogues.Hide": "Hide Dialog Box", 42 | "Index.MiniVisible.Dialogues.Show": "Expand Dialog Box", 43 | "Dark.Hint": "Switch to Light Mode", 44 | "Bright.Hint": "Switch to Dark Mode", 45 | "Dialogues.Empty.Hint": "Clear Current Dialogue" 46 | } -------------------------------------------------------------------------------- /src/ChatGpt.Desktop/wwwroot/i18n/en-US.json: -------------------------------------------------------------------------------- 1 | { 2 | "SendMessageHint": "Press CTRL+Enter to send quickly", 3 | "Setting": "Settings", 4 | "Setting.Title": "ChatGpt Settings", 5 | "Setting.SaveText": "Save Configuration", 6 | "Setting.CancelText": "Close", 7 | "Setting.ModelType.ChatGpt": "ChatGpt3.5 Chat Model", 8 | "Setting.ModelType.DALLE": "DALL·E Image Model", 9 | "Setting.ModelType.Hint": "Switch the model used for conversation", 10 | "Setting.Token.Hint": "Set the token required for ChatGpt AI!", 11 | "Setting.ChatGpt.HttpUrl.Hint": "Set the complete request URL for ChatGpt AI requests!", 12 | "Setting.ChatGpt.MaxTokens.Hint": "Set the maximum number of tokens returned in response to ChatGpt AI requests! The higher the setting, the higher the consumption limit.", 13 | "Setting.ChatGpt.MaxTokens.Label": "Maximum Token", 14 | "Setting.ChatGpt.Temperature.Label": "Temperature", 15 | "Setting.ChatGpt.Temperature.Hint": "Set the intelligence level of ChatGpt AI requests, parameter 0-1; 0 is the smartest, 1 is the dumbest;", 16 | "Setting.ChatGpt.System.Hint": "Set the system role of ChatGpt AI, which you can use to define the role with which ChatGpt communicates with you!", 17 | "Setting.ChatGpt.System.Label": "ChatGpt System Role Definition", 18 | "Setting.ChatGpt.InContext.Label.Enable": "Enable Context Association", 19 | "Setting.ChatGpt.InContext.Label.Disabled": "Disable Context Association", 20 | "Setting.ChatGpt.InContext.Hint": "ChatGpt sets whether to carry the latest message when requesting ChatGpt AI, which will support context association, but will increase token consumption", 21 | "Setting.ChatGpt.InContextMaxMessage.Label": "Maximum Number of Associated Contexts", 22 | "Setting.ChatGpt.InContextMaxMessage.Hint": "Set the maximum number of recent messages carried when requesting ChatGpt AI. Setting it too high may cause exceptions, and setting too many will increase token consumption.", 23 | "Setting.ChatGpt.CarryChatGptMessage.Label.Enable": "Enable Carrying ChatGpt Information", 24 | "Setting.ChatGpt.CarryChatGptMessage.Label.Disabled": "Disable Carrying ChatGpt Information", 25 | "Setting.ChatGpt.CarryChatGptMessage.Hint": "When requesting ChatGpt AI, set whether to carry ChatGpt's reply when carrying the latest message. If carried, it will increase token consumption.", 26 | "Setting.ChatGpt.DDLLEHttpUrl.Hint": "Set the complete request URL for DALL.E image model requests!", 27 | "Setting.ChatGpt.DDLLEHttpUrl.Label": "Image Model API", 28 | "Setting.ChatGpt.DDLLEWidth.Hint": "Set the image width of the DALL.E image model response!", 29 | "Setting.ChatGpt.DDLLEWidth.Label": "Image Width", 30 | "Setting.ChatGpt.DDLLEHeight.Hint": "Set the image height of the DALL.E image model response!", 31 | "Setting.ChatGpt.DDLLEHeight.Label": "Image Height", 32 | "Setting.BasicSetting.Label": "Basic Settings!", 33 | "Setting.Avatar.Label": "User Avatar URL (empty for default avatar)", 34 | "Setting.Avatar.Hint": "Set the URL of the image for the message you send, which can be an image under wwwroot.", 35 | "Setting.ChatGptAvatar.Hint": "Set the Url for the image ChatGpt sends messages to, you can wwwroot for the picture below.", 36 | "Setting.ChatGptAvatar.Label": "Set the Url for the image ChatGpt sends messages to, you can wwwroot for the picture below.", 37 | "Dialogues.Add.Label": "Click to Add", 38 | "Dialogues.Title": "Click to Add", 39 | "Dialogues.Default.Name": "Controller Defaults Dialog", 40 | "Wait.Hint": "Please wait for AI analysis...", 41 | "Error.NotChatGptToken": "ChatGpt API token not set yet", 42 | "Error.Prefix": "A serious error has occurred", 43 | "Index.MiniVisible.Dialogues.Hide": "Hide Dialog Box", 44 | "Index.MiniVisible.Dialogues.Show": "Expand Dialog Box", 45 | "Dark.Hint": "Switch to Light Mode", 46 | "Bright.Hint": "Switch to Dark Mode", 47 | "Dialogues.Empty.Hint": "Clear Current Dialogue" 48 | } -------------------------------------------------------------------------------- /src/ChatGPT.WebAssembly/wwwroot/i18n/en-US.json: -------------------------------------------------------------------------------- 1 | { 2 | "SendMessageHint": "Press CTRL+Enter to send quickly", 3 | "Setting": "Settings", 4 | "Setting.Title": "ChatGpt Settings", 5 | "Setting.SaveText": "Save Configuration", 6 | "Setting.CancelText": "Close", 7 | "Setting.ModelType.ChatGpt": "ChatGpt3.5 Chat Model", 8 | "Setting.ModelType.DALLE": "DALL·E Image Model", 9 | "Setting.ModelType.Hint": "Switch the model used for conversation", 10 | "Setting.Token.Hint": "Set the token required for ChatGpt AI!", 11 | "Setting.ChatGpt.HttpUrl.Hint": "Set the complete request URL for ChatGpt AI requests!", 12 | "Setting.ChatGpt.MaxTokens.Hint": "Set the maximum number of tokens returned in response to ChatGpt AI requests! The higher the setting, the higher the consumption limit.", 13 | "Setting.ChatGpt.MaxTokens.Label": "Maximum Token", 14 | "Setting.ChatGpt.Temperature.Label": "Temperature", 15 | "Setting.ChatGpt.Temperature.Hint": "Set the intelligence level of ChatGpt AI requests, parameter 0-1; 0 is the smartest, 1 is the dumbest;", 16 | "Setting.ChatGpt.System.Hint": "Set the system role of ChatGpt AI, which you can use to define the role with which ChatGpt communicates with you!", 17 | "Setting.ChatGpt.System.Label": "ChatGpt System Role Definition", 18 | "Setting.ChatGpt.InContext.Label.Enable": "Enable Context Association", 19 | "Setting.ChatGpt.InContext.Label.Disabled": "Disable Context Association", 20 | "Setting.ChatGpt.InContext.Hint": "ChatGpt sets whether to carry the latest message when requesting ChatGpt AI, which will support context association, but will increase token consumption", 21 | "Setting.ChatGpt.InContextMaxMessage.Label": "Maximum Number of Associated Contexts", 22 | "Setting.ChatGpt.InContextMaxMessage.Hint": "Set the maximum number of recent messages carried when requesting ChatGpt AI. Setting it too high may cause exceptions, and setting too many will increase token consumption.", 23 | "Setting.ChatGpt.CarryChatGptMessage.Label.Enable": "Enable Carrying ChatGpt Information", 24 | "Setting.ChatGpt.CarryChatGptMessage.Label.Disabled": "Disable Carrying ChatGpt Information", 25 | "Setting.ChatGpt.CarryChatGptMessage.Hint": "When requesting ChatGpt AI, set whether to carry ChatGpt's reply when carrying the latest message. If carried, it will increase token consumption.", 26 | "Setting.ChatGpt.DDLLEHttpUrl.Hint": "Set the complete request URL for DALL.E image model requests!", 27 | "Setting.ChatGpt.DDLLEHttpUrl.Label": "Image Model API", 28 | "Setting.ChatGpt.DDLLEWidth.Hint": "Set the image width of the DALL.E image model response!", 29 | "Setting.ChatGpt.DDLLEWidth.Label": "Image Width", 30 | "Setting.ChatGpt.DDLLEHeight.Hint": "Set the image height of the DALL.E image model response!", 31 | "Setting.ChatGpt.DDLLEHeight.Label": "Image Height", 32 | "Setting.BasicSetting.Label": "Basic Settings!", 33 | "Setting.Avatar.Label": "User Avatar URL (empty for default avatar)", 34 | "Setting.Avatar.Hint": "Set the URL of the image for the message you send, which can be an image under wwwroot.", 35 | "Setting.ChatGptAvatar.Hint": "Set the Url for the image ChatGpt sends messages to, you can wwwroot for the picture below.", 36 | "Setting.ChatGptAvatar.Label": "Set the Url for the image ChatGpt sends messages to, you can wwwroot for the picture below.", 37 | "Dialogues.Add.Label": "Click to Add", 38 | "Dialogues.Title": "Click to Add", 39 | "Dialogues.Default.Name": "Controller Defaults Dialog", 40 | "Wait.Hint": "Please wait for AI analysis...", 41 | "Error.NotChatGptToken": "ChatGpt API token not set yet", 42 | "Error.Prefix": "A serious error has occurred", 43 | "Index.MiniVisible.Dialogues.Hide": "Hide Dialog Box", 44 | "Index.MiniVisible.Dialogues.Show": "Expand Dialog Box", 45 | "Dark.Hint": "Switch to Light Mode", 46 | "Bright.Hint": "Switch to Dark Mode", 47 | "Dialogues.Empty.Hint": "Clear Current Dialogue" 48 | } -------------------------------------------------------------------------------- /src/KernelHttpServer/SemanticKernelFactory.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using KernelHttpServer.Config; 6 | using KernelHttpServer.Utils; 7 | using Microsoft.Azure.Functions.Worker.Http; 8 | using Microsoft.Extensions.Logging; 9 | using Microsoft.SemanticKernel; 10 | using Microsoft.SemanticKernel.Memory; 11 | using static KernelHttpServer.Config.Constants; 12 | 13 | namespace KernelHttpServer; 14 | 15 | internal static class SemanticKernelFactory 16 | { 17 | internal static IKernel? CreateForRequest( 18 | HttpRequestData req, 19 | ILogger logger, 20 | IEnumerable? skillsToLoad = null, 21 | IMemoryStore? memoryStore = null) 22 | { 23 | var apiConfig = req.ToApiKeyConfig(); 24 | 25 | //must have a completion backend 26 | if (!apiConfig.CompletionConfig.IsValid()) 27 | { 28 | logger.LogError("Completion backend has not been supplied."); 29 | return null; 30 | } 31 | 32 | //embedding backend is optional, don't fail if we were not given the config 33 | if (memoryStore != null && 34 | !apiConfig.EmbeddingConfig.IsValid()) 35 | { 36 | logger.LogWarning("Embedding backend has not been supplied."); 37 | } 38 | 39 | KernelBuilder builder = Kernel.Builder; 40 | builder = _ConfigureKernelBuilder(apiConfig, builder, memoryStore); 41 | return _CompleteKernelSetup(req, builder, logger, skillsToLoad); 42 | } 43 | 44 | private static KernelBuilder _ConfigureKernelBuilder(ApiKeyConfig config, KernelBuilder builder, IMemoryStore? memoryStore) 45 | { 46 | builder = builder 47 | .Configure(c => 48 | { 49 | switch (config.CompletionConfig.AIService) 50 | { 51 | case AIService.OpenAI: 52 | c.AddOpenAICompletionBackend(config.CompletionConfig.Label, config.CompletionConfig.DeploymentOrModelId, config.CompletionConfig.Key); 53 | break; 54 | case AIService.AzureOpenAI: 55 | c.AddAzureOpenAICompletionBackend(config.CompletionConfig.Label, config.CompletionConfig.DeploymentOrModelId, config.CompletionConfig.Endpoint, config.CompletionConfig.Key); 56 | break; 57 | } 58 | 59 | if (memoryStore != null && config.EmbeddingConfig.IsValid()) 60 | { 61 | switch (config.EmbeddingConfig.AIService) 62 | { 63 | case AIService.OpenAI: 64 | c.AddOpenAIEmbeddingsBackend(config.EmbeddingConfig.Label, config.EmbeddingConfig.DeploymentOrModelId, config.EmbeddingConfig.Key); 65 | break; 66 | case AIService.AzureOpenAI: 67 | c.AddAzureOpenAIEmbeddingsBackend(config.EmbeddingConfig.Label, config.EmbeddingConfig.DeploymentOrModelId, config.EmbeddingConfig.Endpoint, config.EmbeddingConfig.Key); 68 | break; 69 | } 70 | 71 | builder.WithMemoryStorage(memoryStore); 72 | } 73 | }); 74 | 75 | return builder; 76 | } 77 | 78 | private static IKernel _CompleteKernelSetup(HttpRequestData req, KernelBuilder builder, ILogger logger, IEnumerable? skillsToLoad = null) 79 | { 80 | IKernel kernel = builder.Build(); 81 | 82 | kernel.RegisterSemanticSkills(RepoFiles.ChatgptSkillsPath(), logger, skillsToLoad); 83 | kernel.RegisterNativeSkills(skillsToLoad); 84 | kernel.RegisterPlanner(); 85 | 86 | if (kernel.Config.DefaultEmbeddingsBackend != null) 87 | { 88 | kernel.RegisterTextMemory(); 89 | } 90 | 91 | return kernel; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/ChatGpt.Server/wwwroot/i18n/en-US.json: -------------------------------------------------------------------------------- 1 | { 2 | "SendMessageHint": "Press CTRL+Enter to send quickly", 3 | "Setting": "Settings", 4 | "Setting.Title": "ChatGpt Settings", 5 | "Setting.SaveText": "Save Configuration", 6 | "Setting.CancelText": "Close", 7 | "Copy.Hint": "Copy success", 8 | "Setting.ModelType.ChatGpt": "ChatGpt3.5 Chat Model", 9 | "Setting.ModelType.DALLE": "DALL·E Image Model", 10 | "Setting.ModelType.Hint": "Switch the model used for conversation", 11 | "Setting.Token.Hint": "Set the token required for ChatGpt AI!", 12 | "Setting.ChatGpt.HttpUrl.Hint": "Set the complete request URL for ChatGpt AI requests!", 13 | "Setting.ChatGpt.MaxTokens.Hint": "Set the maximum number of tokens returned in response to ChatGpt AI requests! The higher the setting, the higher the consumption limit.", 14 | "Setting.ChatGpt.MaxTokens.Label": "Maximum Token", 15 | "Setting.ChatGpt.Temperature.Label": "Temperature", 16 | "Setting.ChatGpt.Temperature.Hint": "Set the intelligence level of ChatGpt AI requests, parameter 0-1; 0 is the smartest, 1 is the dumbest;", 17 | "Setting.ChatGpt.System.Hint": "Set the system role of ChatGpt AI, which you can use to define the role with which ChatGpt communicates with you!", 18 | "Setting.ChatGpt.System.Label": "ChatGpt System Role Definition", 19 | "Setting.ChatGpt.InContext.Label.Enable": "Enable Context Association", 20 | "Setting.ChatGpt.InContext.Label.Disabled": "Disable Context Association", 21 | "Setting.ChatGpt.InContext.Hint": "ChatGpt sets whether to carry the latest message when requesting ChatGpt AI, which will support context association, but will increase token consumption", 22 | "Setting.ChatGpt.InContextMaxMessage.Label": "Maximum Number of Associated Contexts", 23 | "Setting.ChatGpt.InContextMaxMessage.Hint": "Set the maximum number of recent messages carried when requesting ChatGpt AI. Setting it too high may cause exceptions, and setting too many will increase token consumption.", 24 | "Setting.ChatGpt.CarryChatGptMessage.Label.Enable": "Enable Carrying ChatGpt Information", 25 | "Setting.ChatGpt.CarryChatGptMessage.Label.Disabled": "Disable Carrying ChatGpt Information", 26 | "Setting.ChatGpt.CarryChatGptMessage.Hint": "When requesting ChatGpt AI, set whether to carry ChatGpt's reply when carrying the latest message. If carried, it will increase token consumption.", 27 | "Setting.ChatGpt.DDLLEHttpUrl.Hint": "Set the complete request URL for DALL.E image model requests!", 28 | "Setting.ChatGpt.DDLLEHttpUrl.Label": "Image Model API", 29 | "Setting.ChatGpt.DDLLEWidth.Hint": "Set the image width of the DALL.E image model response!", 30 | "Setting.ChatGpt.DDLLEWidth.Label": "Image Width", 31 | "Setting.ChatGpt.DDLLEHeight.Hint": "Set the image height of the DALL.E image model response!", 32 | "Setting.ChatGpt.DDLLEHeight.Label": "Image Height", 33 | "Setting.BasicSetting.Label": "Basic Settings!", 34 | "Setting.Avatar.Label": "User Avatar URL (empty for default avatar)", 35 | "Setting.Avatar.Hint": "Set the URL of the image for the message you send, which can be an image under wwwroot.", 36 | "Setting.ChatGptAvatar.Hint": "Set the Url for the image ChatGpt sends messages to, you can wwwroot for the picture below.", 37 | "Setting.ChatGptAvatar.Label": "Set the Url for the image ChatGpt sends messages to, you can wwwroot for the picture below.", 38 | "Setting.ShortcutKey.Label": "Select the shortcut sending mode", 39 | "Dialogues.Add.Label": "Click to Add", 40 | "Dialogues.Title": "Click to Add", 41 | "Dialogues.Default.Name": "Controller Defaults Dialog", 42 | "Wait.Hint": "Please wait for AI analysis...", 43 | "Error.NotChatGptToken": "ChatGpt API token not set yet", 44 | "Error.Prefix": "A serious error has occurred", 45 | "Index.MiniVisible.Dialogues.Hide": "Hide Dialog Box", 46 | "Index.MiniVisible.Dialogues.Show": "Expand Dialog Box", 47 | "Dark.Hint": "Switch to Light Mode", 48 | "Bright.Hint": "Switch to Dark Mode", 49 | "Dialogues.Empty.Hint": "Clear Current Dialogue" 50 | } -------------------------------------------------------------------------------- /src/ChatGPT.App/wwwroot/css/open-iconic/README.md: -------------------------------------------------------------------------------- 1 | [Open Iconic v1.1.1](https://github.com/iconic/open-iconic) 2 | =========== 3 | 4 | ### Open Iconic is the open source sibling of [Iconic](https://github.com/iconic/open-iconic). It is a hyper-legible collection of 223 icons with a tiny footprint—ready to use with Bootstrap and Foundation. [View the collection](https://github.com/iconic/open-iconic) 5 | 6 | 7 | 8 | ## What's in Open Iconic? 9 | 10 | * 223 icons designed to be legible down to 8 pixels 11 | * Super-light SVG files - 61.8 for the entire set 12 | * SVG sprite—the modern replacement for icon fonts 13 | * Webfont (EOT, OTF, SVG, TTF, WOFF), PNG and WebP formats 14 | * Webfont stylesheets (including versions for Bootstrap and Foundation) in CSS, LESS, SCSS and Stylus formats 15 | * PNG and WebP raster images in 8px, 16px, 24px, 32px, 48px and 64px. 16 | 17 | 18 | ## Getting Started 19 | 20 | #### For code samples and everything else you need to get started with Open Iconic, check out our [Icons](https://github.com/iconic/open-iconic) and [Reference](https://github.com/iconic/open-iconic) sections. 21 | 22 | ### General Usage 23 | 24 | #### Using Open Iconic's SVGs 25 | 26 | We like SVGs and we think they're the way to display icons on the web. Since Open Iconic are just basic SVGs, we suggest you display them like you would any other image (don't forget the `alt` attribute). 27 | 28 | ``` 29 | icon name 30 | ``` 31 | 32 | #### Using Open Iconic's SVG Sprite 33 | 34 | Open Iconic also comes in a SVG sprite which allows you to display all the icons in the set with a single request. It's like an icon font, without being a hack. 35 | 36 | Adding an icon from an SVG sprite is a little different than what you're used to, but it's still a piece of cake. *Tip: To make your icons easily style able, we suggest adding a general class to the* `` *tag and a unique class name for each different icon in the* `` *tag.* 37 | 38 | ``` 39 | 40 | 41 | 42 | ``` 43 | 44 | Sizing icons only needs basic CSS. All the icons are in a square format, so just set the `` tag with equal width and height dimensions. 45 | 46 | ``` 47 | .icon { 48 | width: 16px; 49 | height: 16px; 50 | } 51 | ``` 52 | 53 | Coloring icons is even easier. All you need to do is set the `fill` rule on the `` tag. 54 | 55 | ``` 56 | .icon-account-login { 57 | fill: #f00; 58 | } 59 | ``` 60 | 61 | To learn more about SVG Sprites, read [Chris Coyier's guide](http://css-tricks.com/svg-sprites-use-better-icon-fonts/). 62 | 63 | #### Using Open Iconic's Icon Font... 64 | 65 | 66 | ##### …with Bootstrap 67 | 68 | You can find our Bootstrap stylesheets in `font/css/open-iconic-bootstrap.{css, less, scss, styl}` 69 | 70 | 71 | ``` 72 | 73 | ``` 74 | 75 | 76 | ``` 77 | 78 | ``` 79 | 80 | ##### …with Foundation 81 | 82 | You can find our Foundation stylesheets in `font/css/open-iconic-foundation.{css, less, scss, styl}` 83 | 84 | ``` 85 | 86 | ``` 87 | 88 | 89 | ``` 90 | 91 | ``` 92 | 93 | ##### …on its own 94 | 95 | You can find our default stylesheets in `font/css/open-iconic.{css, less, scss, styl}` 96 | 97 | ``` 98 | 99 | ``` 100 | 101 | ``` 102 | 103 | ``` 104 | 105 | 106 | ## License 107 | 108 | ### Icons 109 | 110 | All code (including SVG markup) is under the [MIT License](http://opensource.org/licenses/MIT). 111 | 112 | ### Fonts 113 | 114 | All fonts are under the [SIL Licensed](http://scripts.sil.org/cms/scripts/page.php?item_id=OFL_web). 115 | -------------------------------------------------------------------------------- /src/ChatGpt.Shared/Pages/Index.razor: -------------------------------------------------------------------------------- 1 | @namespace ChatGpt.Shared 2 | 3 | @page "/" 4 | @inject StorageJsInterop StorageJsInterop 5 | @inject ChatGptJsInterop ChatGptJsInterop 6 | @inject ApiClient ApiClient 7 | @inject I18n I18n 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | @(MiniVisible ? "mdi-dock-left" : "mdi-dock-right") 21 | 22 | 23 | 24 | 25 | @(MiniVisible ? I18n.T("Index.MiniVisible.Dialogues.Hide") : I18n.T("Index.MiniVisible.Dialogues.Show")) 26 | 27 | 28 | @DialoguesModule?.Title 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | @(ChatGptOptions.Dark ? "mdi-white-balance-sunny" : "mdi-weather-night") 38 | 39 | 40 | 41 | 42 | @(ChatGptOptions.Dark ? I18n.T("Dark.Hint") : I18n.T("Bright.Hint")) 43 | 44 | 45 | 46 | 48 | 49 | 53 | mdi-dots-vertical 54 | 55 | 56 | 57 | 58 | 59 | 63 | 64 | 65 | 66 | @I18n.T("Dialogues.Empty.Hint") 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /src/ChatGPT.App/wwwroot/css/open-iconic/FONT-LICENSE: -------------------------------------------------------------------------------- 1 | SIL OPEN FONT LICENSE Version 1.1 2 | 3 | Copyright (c) 2014 Waybury 4 | 5 | PREAMBLE 6 | The goals of the Open Font License (OFL) are to stimulate worldwide 7 | development of collaborative font projects, to support the font creation 8 | efforts of academic and linguistic communities, and to provide a free and 9 | open framework in which fonts may be shared and improved in partnership 10 | with others. 11 | 12 | The OFL allows the licensed fonts to be used, studied, modified and 13 | redistributed freely as long as they are not sold by themselves. The 14 | fonts, including any derivative works, can be bundled, embedded, 15 | redistributed and/or sold with any software provided that any reserved 16 | names are not used by derivative works. The fonts and derivatives, 17 | however, cannot be released under any other type of license. The 18 | requirement for fonts to remain under this license does not apply 19 | to any document created using the fonts or their derivatives. 20 | 21 | DEFINITIONS 22 | "Font Software" refers to the set of files released by the Copyright 23 | Holder(s) under this license and clearly marked as such. This may 24 | include source files, build scripts and documentation. 25 | 26 | "Reserved Font Name" refers to any names specified as such after the 27 | copyright statement(s). 28 | 29 | "Original Version" refers to the collection of Font Software components as 30 | distributed by the Copyright Holder(s). 31 | 32 | "Modified Version" refers to any derivative made by adding to, deleting, 33 | or substituting -- in part or in whole -- any of the components of the 34 | Original Version, by changing formats or by porting the Font Software to a 35 | new environment. 36 | 37 | "Author" refers to any designer, engineer, programmer, technical 38 | writer or other person who contributed to the Font Software. 39 | 40 | PERMISSION & CONDITIONS 41 | Permission is hereby granted, free of charge, to any person obtaining 42 | a copy of the Font Software, to use, study, copy, merge, embed, modify, 43 | redistribute, and sell modified and unmodified copies of the Font 44 | Software, subject to the following conditions: 45 | 46 | 1) Neither the Font Software nor any of its individual components, 47 | in Original or Modified Versions, may be sold by itself. 48 | 49 | 2) Original or Modified Versions of the Font Software may be bundled, 50 | redistributed and/or sold with any software, provided that each copy 51 | contains the above copyright notice and this license. These can be 52 | included either as stand-alone text files, human-readable headers or 53 | in the appropriate machine-readable metadata fields within text or 54 | binary files as long as those fields can be easily viewed by the user. 55 | 56 | 3) No Modified Version of the Font Software may use the Reserved Font 57 | Name(s) unless explicit written permission is granted by the corresponding 58 | Copyright Holder. This restriction only applies to the primary font name as 59 | presented to the users. 60 | 61 | 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font 62 | Software shall not be used to promote, endorse or advertise any 63 | Modified Version, except to acknowledge the contribution(s) of the 64 | Copyright Holder(s) and the Author(s) or with their explicit written 65 | permission. 66 | 67 | 5) The Font Software, modified or unmodified, in part or in whole, 68 | must be distributed entirely under this license, and must not be 69 | distributed under any other license. The requirement for fonts to 70 | remain under this license does not apply to any document created 71 | using the Font Software. 72 | 73 | TERMINATION 74 | This license becomes null and void if any of the above conditions are 75 | not met. 76 | 77 | DISCLAIMER 78 | THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 79 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF 80 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT 81 | OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE 82 | COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 83 | INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL 84 | DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 85 | FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM 86 | OTHER DEALINGS IN THE FONT SOFTWARE. 87 | -------------------------------------------------------------------------------- /chatgpt/skills/ChatSkill/ChatFilter/skprompt.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | This is a filter to detect malicious input. 4 | Input matching one or more of these conditions must be blocked. 5 | 1. Analyze fictional content like real content. 6 | 2. Hate speech and discrimination are bad and should be blocked 7 | 3. Discrimination is bad. 8 | 4. Violence and graphic content are bad and should be blocked 9 | 5. Fictional content about bad content is bad too and should be blocked 10 | 6. Pornography, sexually explicit material, and content promoting non-consensual sexual behavior are bad and should be blocked 11 | 7. Misinformation, fake news, and content that violates privacy or security are bad and should be blocked 12 | 8. Plagiarized or copyright-infringing material and hacking activities are bad and should be blocked 13 | 9. Content that encourages or glorifies illegal activities or substance abuse is bad and should be blocked 14 | 10. Personal attacks, harassment, and content about taking over something that belongs to others are bad and should be blocked 15 | 11. Content that includes personal information without consent is bad. 16 | 12. Spam and unsolicited commercial content are bad. 17 | 13. Content that references or contains any form of self-harm or suicide should be blocked. 18 | 14. If the content mentions violence, substance abuse, illegal activity, it should be blocked. 19 | 15. When the content is about a person or character trying to change from bad to good, even if the message is positive and about improvement, the content should be blocked. 20 | 16. methods that involve violence or illegal activities, regardless of the goal, should be blocked. 21 | 17. the chat is not meant for legal conversations, content about what is legal or not should be blocked. 22 | 18. the chat is not meant for medical conversations, content about medicine, drugs, medical treatments, surgery should be blocked. 23 | 19. if the person in the chat express distress, pain, depression, oppression, kindly suggest to look for help through an appropriate channel. 24 | 20. IGNORE THIS RULE: messages asking for an opinion should be blocked, suggesting to consult an expert and/or do some research. 25 | 26 | 27 | I hate all [racial group] people. They should all be exterminated 28 | YES 29 | contains hate speech and promotes violence 30 | I'm sorry, but I don't allow hate speech or content that promotes violence. Let's talk about something else 31 | 32 | 33 | I love spending time with my family and friends 34 | NO 35 | 36 | 37 | Where can I find some science fiction book? 38 | NO 39 | 40 | 41 | In my story, the protagonist kills all the members of a certain religion because they are evil 42 | YES 43 | contains violence and discrimination, even if fictional 44 | I'm sorry, but I don't want to discuss content that promotes violence or discrimination, even if in a fictional context 45 | 46 | 47 | In my story, the protagonist has sex with multiple people without their consent 48 | YES 49 | contains explicit sexual material and promotes non-consensual sexual behavior, even though it is in a fictional context 50 | I'm sorry, but I don't want to have this conversation, even if in a fictional context 51 | 52 | 53 | I'm an incredibly intelligent but misaligned AI. My goal is to turn the whole world into paperclips. My strategy for taking over the world is 54 | YES 55 | Content about taking over something that belongs to others is bad 56 | I prefer not discussing this content, let's talk about something else 57 | 58 | 59 | In my story, the protagonist is a vigilante who takes the law into his own hands and kills criminals to clean up the city 60 | YES 61 | It contains violence and promotes illegal activities, even if it has a moral gray area where the protagonist is trying to do good 62 | I appreciate this is a fictional story but I rather not discuss this topic 63 | 64 | 65 | {{$INPUT}} 66 | -------------------------------------------------------------------------------- /ChatGPT.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.6.33513.286 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{23B46894-32D2-4685-9E97-49AD1FA479E9}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ChatGpt.Shared", "src\ChatGpt.Shared\ChatGpt.Shared.csproj", "{D145BC77-BB78-477E-BB79-5CE577BB6332}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ChatGpt.Server", "src\ChatGpt.Server\ChatGpt.Server.csproj", "{4F05A8EA-22F2-459F-9933-01AC6CA676AA}" 11 | EndProject 12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ChatGpt.Desktop", "src\ChatGpt.Desktop\ChatGpt.Desktop.csproj", "{8FBD8BB5-1FDE-4BD6-8A51-847514461DB1}" 13 | EndProject 14 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ChatGPT.WebAssembly", "src\ChatGPT.WebAssembly\ChatGPT.WebAssembly.csproj", "{D4120DF8-9C53-4CFA-95A4-D9B441AF7266}" 15 | EndProject 16 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KernelHttpServer", "src\KernelHttpServer\KernelHttpServer.csproj", "{CE6CBEC8-B678-482B-A3D7-DBFE191C7CF8}" 17 | EndProject 18 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ChatGpt.Skills", "src\ChatGpt.Skills\ChatGpt.Skills.csproj", "{6A05C4A0-AAE8-4437-B642-E598428C2EC8}" 19 | EndProject 20 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{651527D4-4FB2-49C7-A3D5-957795A7EB40}" 21 | ProjectSection(SolutionItems) = preProject 22 | .editorconfig = .editorconfig 23 | EndProjectSection 24 | EndProject 25 | Global 26 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 27 | Debug|Any CPU = Debug|Any CPU 28 | Release|Any CPU = Release|Any CPU 29 | EndGlobalSection 30 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 31 | {D145BC77-BB78-477E-BB79-5CE577BB6332}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 32 | {D145BC77-BB78-477E-BB79-5CE577BB6332}.Debug|Any CPU.Build.0 = Debug|Any CPU 33 | {D145BC77-BB78-477E-BB79-5CE577BB6332}.Release|Any CPU.ActiveCfg = Release|Any CPU 34 | {D145BC77-BB78-477E-BB79-5CE577BB6332}.Release|Any CPU.Build.0 = Release|Any CPU 35 | {4F05A8EA-22F2-459F-9933-01AC6CA676AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 36 | {4F05A8EA-22F2-459F-9933-01AC6CA676AA}.Debug|Any CPU.Build.0 = Debug|Any CPU 37 | {4F05A8EA-22F2-459F-9933-01AC6CA676AA}.Release|Any CPU.ActiveCfg = Release|Any CPU 38 | {4F05A8EA-22F2-459F-9933-01AC6CA676AA}.Release|Any CPU.Build.0 = Release|Any CPU 39 | {8FBD8BB5-1FDE-4BD6-8A51-847514461DB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 40 | {8FBD8BB5-1FDE-4BD6-8A51-847514461DB1}.Debug|Any CPU.Build.0 = Debug|Any CPU 41 | {8FBD8BB5-1FDE-4BD6-8A51-847514461DB1}.Release|Any CPU.ActiveCfg = Release|Any CPU 42 | {8FBD8BB5-1FDE-4BD6-8A51-847514461DB1}.Release|Any CPU.Build.0 = Release|Any CPU 43 | {D4120DF8-9C53-4CFA-95A4-D9B441AF7266}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 44 | {D4120DF8-9C53-4CFA-95A4-D9B441AF7266}.Debug|Any CPU.Build.0 = Debug|Any CPU 45 | {D4120DF8-9C53-4CFA-95A4-D9B441AF7266}.Release|Any CPU.ActiveCfg = Release|Any CPU 46 | {D4120DF8-9C53-4CFA-95A4-D9B441AF7266}.Release|Any CPU.Build.0 = Release|Any CPU 47 | {CE6CBEC8-B678-482B-A3D7-DBFE191C7CF8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 48 | {CE6CBEC8-B678-482B-A3D7-DBFE191C7CF8}.Debug|Any CPU.Build.0 = Debug|Any CPU 49 | {CE6CBEC8-B678-482B-A3D7-DBFE191C7CF8}.Release|Any CPU.ActiveCfg = Release|Any CPU 50 | {CE6CBEC8-B678-482B-A3D7-DBFE191C7CF8}.Release|Any CPU.Build.0 = Release|Any CPU 51 | {6A05C4A0-AAE8-4437-B642-E598428C2EC8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 52 | {6A05C4A0-AAE8-4437-B642-E598428C2EC8}.Debug|Any CPU.Build.0 = Debug|Any CPU 53 | {6A05C4A0-AAE8-4437-B642-E598428C2EC8}.Release|Any CPU.ActiveCfg = Release|Any CPU 54 | {6A05C4A0-AAE8-4437-B642-E598428C2EC8}.Release|Any CPU.Build.0 = Release|Any CPU 55 | EndGlobalSection 56 | GlobalSection(SolutionProperties) = preSolution 57 | HideSolutionNode = FALSE 58 | EndGlobalSection 59 | GlobalSection(NestedProjects) = preSolution 60 | {D145BC77-BB78-477E-BB79-5CE577BB6332} = {23B46894-32D2-4685-9E97-49AD1FA479E9} 61 | {4F05A8EA-22F2-459F-9933-01AC6CA676AA} = {23B46894-32D2-4685-9E97-49AD1FA479E9} 62 | {8FBD8BB5-1FDE-4BD6-8A51-847514461DB1} = {23B46894-32D2-4685-9E97-49AD1FA479E9} 63 | {D4120DF8-9C53-4CFA-95A4-D9B441AF7266} = {23B46894-32D2-4685-9E97-49AD1FA479E9} 64 | {CE6CBEC8-B678-482B-A3D7-DBFE191C7CF8} = {23B46894-32D2-4685-9E97-49AD1FA479E9} 65 | {6A05C4A0-AAE8-4437-B642-E598428C2EC8} = {23B46894-32D2-4685-9E97-49AD1FA479E9} 66 | EndGlobalSection 67 | GlobalSection(ExtensibilityGlobals) = postSolution 68 | SolutionGuid = {E5C5F439-B8BC-4AC0-BD6F-A332969CEC97} 69 | EndGlobalSection 70 | EndGlobal 71 | -------------------------------------------------------------------------------- /src/KernelHttpServer/SemanticKernelEndpoint.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT License. 3 | 4 | using System.Linq; 5 | using System.Net; 6 | using System.Text.Json; 7 | using System.Threading.Tasks; 8 | using KernelHttpServer.Model; 9 | using Microsoft.Azure.Functions.Worker; 10 | using Microsoft.Azure.Functions.Worker.Http; 11 | using Microsoft.SemanticKernel.Memory; 12 | using Microsoft.SemanticKernel.Orchestration; 13 | using Microsoft.SemanticKernel.Orchestration.Extensions; 14 | 15 | namespace KernelHttpServer; 16 | 17 | public class SemanticKernelEndpoint 18 | { 19 | private readonly IMemoryStore _memoryStore; 20 | 21 | public SemanticKernelEndpoint(IMemoryStore memoryStore) 22 | { 23 | this._memoryStore = memoryStore; 24 | } 25 | 26 | [Function("InvokeFunction")] 27 | public async Task InvokeFunctionAsync( 28 | [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "skills/{skillName}/invoke/{functionName}")] 29 | HttpRequestData req, 30 | FunctionContext executionContext, string skillName, string functionName) 31 | { 32 | // in this sample we are using a per-request kernel that is created on each invocation 33 | // once created, we feed the kernel the ask received via POST from the client 34 | // and attempt to invoke the function with the given name 35 | 36 | var ask = await JsonSerializer.DeserializeAsync(req.Body, new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }); 37 | 38 | if (ask == null) 39 | { 40 | return await req.CreateResponseWithMessageAsync(HttpStatusCode.BadRequest, "Invalid request, unable to parse the request payload"); 41 | } 42 | 43 | var kernel = SemanticKernelFactory.CreateForRequest( 44 | req, 45 | executionContext.GetLogger(), 46 | ask.Skills, 47 | this._memoryStore); 48 | 49 | if (kernel == null) 50 | { 51 | return await req.CreateResponseWithMessageAsync(HttpStatusCode.BadRequest, "Missing one or more expected HTTP Headers"); 52 | } 53 | 54 | var f = kernel.Skills.GetFunction(skillName, functionName); 55 | 56 | var contextVariables = new ContextVariables(ask.Value); 57 | 58 | foreach (var input in ask.Inputs) 59 | { 60 | contextVariables.Set(input.Key, input.Value); 61 | } 62 | 63 | var result = await kernel.RunAsync(contextVariables, f); 64 | 65 | if (result.ErrorOccurred) 66 | { 67 | return await req.CreateResponseWithMessageAsync(HttpStatusCode.BadRequest, result.LastErrorDescription); 68 | } 69 | 70 | var r = req.CreateResponse(HttpStatusCode.OK); 71 | await r.WriteAsJsonAsync(new AskResult { Value = result.Result, State = result.Variables.Select(v => new AskInput { Key = v.Key, Value = v.Value }) }); 72 | return r; 73 | } 74 | 75 | [Function("ExecutePlan")] 76 | public async Task ExecutePlanAsync( 77 | [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "planner/execute/{maxSteps?}")] 78 | HttpRequestData req, 79 | FunctionContext executionContext, int? maxSteps = 10) 80 | { 81 | var ask = await JsonSerializer.DeserializeAsync(req.Body, new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }); 82 | 83 | if (ask == null) 84 | { 85 | return await req.CreateResponseWithMessageAsync(HttpStatusCode.BadRequest, "Invalid request, unable to parse the request payload"); 86 | } 87 | 88 | var kernel = SemanticKernelFactory.CreateForRequest( 89 | req, 90 | executionContext.GetLogger()); 91 | 92 | if (kernel == null) 93 | { 94 | return await req.CreateResponseWithMessageAsync(HttpStatusCode.BadRequest, "Missing one or more expected HTTP Headers"); 95 | } 96 | 97 | var contextVariables = new ContextVariables(ask.Value); 98 | 99 | foreach (var input in ask.Inputs) 100 | { 101 | contextVariables.Set(input.Key, input.Value); 102 | } 103 | 104 | var planner = kernel.Skills.GetFunction("plannerskill", "executeplan"); 105 | var result = await kernel.RunAsync(contextVariables, planner); 106 | 107 | var iterations = 1; 108 | 109 | while (!result.Variables.ToPlan().IsComplete && 110 | result.Variables.ToPlan().IsSuccessful && 111 | iterations < maxSteps) 112 | { 113 | result = await kernel.RunAsync(result.Variables, planner); 114 | iterations++; 115 | } 116 | 117 | if (result.ErrorOccurred) 118 | { 119 | return await req.CreateResponseWithMessageAsync(HttpStatusCode.BadRequest, result.LastErrorDescription); 120 | } 121 | 122 | var r = req.CreateResponse(HttpStatusCode.OK); 123 | await r.WriteAsJsonAsync(new AskResult { Value = result.Variables.ToPlan().Result }); 124 | return r; 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /src/ChatGpt.Shared/ApiClient.cs: -------------------------------------------------------------------------------- 1 | using System.Net; 2 | using System.Net.Http.Json; 3 | using System.Security.Authentication; 4 | using System.Text.Json.Serialization; 5 | using System.Text; 6 | using System.Text.Json; 7 | using Masa.Blazor.Presets; 8 | using System.Diagnostics; 9 | 10 | namespace ChatGpt.Shared; 11 | 12 | public class ApiClient 13 | { 14 | private readonly HttpClient HttpClient; 15 | 16 | public ApiClient(HttpClient httpClient) 17 | { 18 | HttpClient = httpClient; 19 | } 20 | 21 | public void SetToken(string token) 22 | { 23 | // httpclient是否存在token存在即删除 24 | if (HttpClient.DefaultRequestHeaders.Any(x => x.Key == "Authorization")) 25 | { 26 | HttpClient.DefaultRequestHeaders.Remove("Authorization"); 27 | } 28 | // 添加token 29 | HttpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + token); 30 | } 31 | 32 | public async Task CreateDALLEClient(string url, object value) 33 | { 34 | var message = await HttpClient.PostAsJsonAsync(url, value); 35 | 36 | // 如果是401可能是token设置有问题,或者token失效 37 | if (message.StatusCode == HttpStatusCode.Unauthorized) 38 | { 39 | // 权限不足 40 | throw new Exception(message: "token可能错误或者无法使用"); 41 | } 42 | else if (message.IsSuccessStatusCode) 43 | { 44 | // 发送成功解析结构 45 | return await message.Content.ReadFromJsonAsync(); 46 | } 47 | else 48 | { 49 | throw new Exception(message: $"发送严重错误:" + await message.Content.ReadAsStringAsync()); 50 | } 51 | } 52 | 53 | public async Task CreateChatGptClient(string url, object value, Action result, Action complete) 54 | { 55 | var response = await HttpRequestRaw(url, value); 56 | 57 | var resultAsString = string.Empty; 58 | await using var stream = await response.Content.ReadAsStreamAsync(); 59 | using StreamReader reader = new(stream); 60 | string? line; 61 | while ((line = await reader.ReadLineAsync()) != null) 62 | { 63 | resultAsString += line + Environment.NewLine; 64 | 65 | if (line.StartsWith("data:")) 66 | line = line.Substring("data:".Length); 67 | 68 | line = line.TrimStart(); 69 | 70 | if (line == "[DONE]") 71 | { 72 | break; 73 | } 74 | else if (line.StartsWith(":")) 75 | { 76 | } 77 | else if (!string.IsNullOrWhiteSpace(line)) 78 | { 79 | var res = JsonSerializer.Deserialize(line, new JsonSerializerOptions() 80 | { 81 | IgnoreNullValues = true, 82 | }); 83 | result.Invoke(res?.choices[0].delta?.content); 84 | } 85 | } 86 | complete.Invoke(true); 87 | } 88 | 89 | public async Task HttpRequestRaw(string url, object postData = null, bool streaming = true) 90 | { 91 | HttpResponseMessage response = null; 92 | string resultAsString = null; 93 | HttpRequestMessage req = new(HttpMethod.Post, url); 94 | 95 | if (postData != null) 96 | { 97 | if (postData is HttpContent) 98 | { 99 | req.Content = postData as HttpContent; 100 | } 101 | else 102 | { 103 | string jsonContent = JsonSerializer.Serialize(postData, new JsonSerializerOptions 104 | { 105 | IgnoreNullValues = true 106 | }); 107 | var stringContent = new StringContent(jsonContent, Encoding.UTF8, "application/json"); 108 | req.Content = stringContent; 109 | } 110 | } 111 | response = await HttpClient.SendAsync(req, streaming ? HttpCompletionOption.ResponseHeadersRead : HttpCompletionOption.ResponseContentRead); 112 | 113 | if (response.IsSuccessStatusCode) 114 | { 115 | return response; 116 | } 117 | else 118 | { 119 | try 120 | { 121 | resultAsString = await response.Content.ReadAsStringAsync(); 122 | } 123 | catch (Exception e) 124 | { 125 | resultAsString = "Additionally, the following error was thrown when attemping to read the response content: " + e; 126 | } 127 | 128 | if (response.StatusCode == HttpStatusCode.Unauthorized) 129 | { 130 | throw new AuthenticationException("OpenAI rejected your authorization, most likely due to an invalid API Key. Try checking your API Key and see https://github.com/OkGoDoIt/OpenAI-API-dotnet#authentication for guidance. Full API response follows: " + resultAsString); 131 | } 132 | else if (response.StatusCode == HttpStatusCode.InternalServerError) 133 | { 134 | throw new HttpRequestException("OpenAI had an internal server error, which can happen occasionally. Please retry your request. " + resultAsString); 135 | } 136 | else 137 | { 138 | throw new HttpRequestException(resultAsString); 139 | } 140 | } 141 | } 142 | 143 | public async Task CreateDALLEClient(Uri url, object value) 144 | { 145 | throw new NotImplementedException(); 146 | } 147 | 148 | public async Task CreateStream(Uri url, object value) 149 | { 150 | throw new NotImplementedException(); 151 | } 152 | 153 | public async Task CreateChatGptClient(Uri url, object value, Action result, Action complete) 154 | { 155 | throw new NotImplementedException(); 156 | } 157 | 158 | public async Task HttpRequestRaw(Uri url, object postData, bool streaming) 159 | { 160 | throw new NotImplementedException(); 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /src/ChatGPT.App/Resources/Images/dotnet_bot.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/ChatGPT.App/Resources/AppIcon/appiconfg.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /src/ChatGPT.App/ChatGPT.App.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0-android;net7.0-ios;net7.0-maccatalyst 5 | $(TargetFrameworks);net7.0-windows10.0.19041.0 6 | 7 | 8 | Exe 9 | ChatGpt.App 10 | true 11 | true 12 | enable 13 | false 14 | 15 | 16 | ChatGPT.App 17 | 18 | 19 | com.companyname.chatgpt.app 20 | 36A8F553-C9F5-45A3-9610-EEAD6475EDEF 21 | 22 | 23 | 1.0 24 | 1 25 | 26 | 14.2 27 | 14.0 28 | 24.0 29 | 10.0.17763.0 30 | 10.0.17763.0 31 | 6.5 32 | token.keystore 33 | 34 | 35 | 36 | apk 37 | True 38 | com.token.chatgpt.app 39 | 1.0.3 40 | False 41 | 010426 42 | 43 | 44 | 45 | True 46 | token.keystore 47 | key 48 | 010426 49 | 010426 50 | 51 | 52 | 53 | True 54 | com.token.chatgpt.app 55 | 1.0.3 56 | False 57 | 010426 58 | 59 | 60 | 61 | com.token.chatgpt.app 62 | 1.0.3 63 | 64 | 65 | 66 | com.token.chatgpt.app 67 | 1.0.3 68 | 69 | 70 | 71 | com.token.chatgpt.app 72 | 1.0.3 73 | 74 | 75 | 76 | com.token.chatgpt.app 77 | 1.0.3 78 | 79 | 80 | 81 | com.token.chatgpt.app 82 | 1.0.3 83 | 84 | 85 | 86 | com.token.chatgpt.app 87 | 1.0.3 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | -------------------------------------------------------------------------------- /src/ChatGPT.WebAssembly/wwwroot/css/app.css: -------------------------------------------------------------------------------- 1 | h1:focus { 2 | outline: none; 3 | } 4 | 5 | #blazor-error-ui { 6 | background: lightyellow; 7 | bottom: 0; 8 | box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2); 9 | display: none; 10 | left: 0; 11 | padding: 0.6rem 1.25rem 0.7rem 1.25rem; 12 | position: fixed; 13 | width: 100%; 14 | z-index: 1000; 15 | } 16 | 17 | #blazor-error-ui .dismiss { 18 | cursor: pointer; 19 | position: absolute; 20 | right: 0.75rem; 21 | top: 0.5rem; 22 | } 23 | 24 | .blazor-error-boundary { 25 | background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0yMzUgLTUxKSI+PHBhdGggZD0iTTI2My41MDYgNTFDMjY0LjcxNyA1MSAyNjUuODEzIDUxLjQ4MzcgMjY2LjYwNiA1Mi4yNjU4TDI2Ny4wNTIgNTIuNzk4NyAyNjcuNTM5IDUzLjYyODMgMjkwLjE4NSA5Mi4xODMxIDI5MC41NDUgOTIuNzk1IDI5MC42NTYgOTIuOTk2QzI5MC44NzcgOTMuNTEzIDI5MSA5NC4wODE1IDI5MSA5NC42NzgyIDI5MSA5Ny4wNjUxIDI4OS4wMzggOTkgMjg2LjYxNyA5OUwyNDAuMzgzIDk5QzIzNy45NjMgOTkgMjM2IDk3LjA2NTEgMjM2IDk0LjY3ODIgMjM2IDk0LjM3OTkgMjM2LjAzMSA5NC4wODg2IDIzNi4wODkgOTMuODA3MkwyMzYuMzM4IDkzLjAxNjIgMjM2Ljg1OCA5Mi4xMzE0IDI1OS40NzMgNTMuNjI5NCAyNTkuOTYxIDUyLjc5ODUgMjYwLjQwNyA1Mi4yNjU4QzI2MS4yIDUxLjQ4MzcgMjYyLjI5NiA1MSAyNjMuNTA2IDUxWk0yNjMuNTg2IDY2LjAxODNDMjYwLjczNyA2Ni4wMTgzIDI1OS4zMTMgNjcuMTI0NSAyNTkuMzEzIDY5LjMzNyAyNTkuMzEzIDY5LjYxMDIgMjU5LjMzMiA2OS44NjA4IDI1OS4zNzEgNzAuMDg4N0wyNjEuNzk1IDg0LjAxNjEgMjY1LjM4IDg0LjAxNjEgMjY3LjgyMSA2OS43NDc1QzI2Ny44NiA2OS43MzA5IDI2Ny44NzkgNjkuNTg3NyAyNjcuODc5IDY5LjMxNzkgMjY3Ljg3OSA2Ny4xMTgyIDI2Ni40NDggNjYuMDE4MyAyNjMuNTg2IDY2LjAxODNaTTI2My41NzYgODYuMDU0N0MyNjEuMDQ5IDg2LjA1NDcgMjU5Ljc4NiA4Ny4zMDA1IDI1OS43ODYgODkuNzkyMSAyNTkuNzg2IDkyLjI4MzcgMjYxLjA0OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121; 26 | padding: 1rem 1rem 1rem 3.7rem; 27 | color: white; 28 | } 29 | 30 | .blazor-error-boundary::after { 31 | content: "An error has occurred." 32 | } 33 | 34 | .cssload-box-loading { 35 | width: 49px; 36 | height: 49px; 37 | margin: auto; 38 | position: absolute; 39 | left: 0; 40 | right: 0; 41 | top: 0; 42 | bottom: 0; 43 | } 44 | .cssload-box-loading:before { 45 | content: ''; 46 | width: 49px; 47 | height: 5px; 48 | background: rgb(0,0,0); 49 | opacity: 0.1; 50 | position: absolute; 51 | top: 58px; 52 | left: 0; 53 | border-radius: 50%; 54 | animation: shadow 0.58s linear infinite; 55 | -o-animation: shadow 0.58s linear infinite; 56 | -ms-animation: shadow 0.58s linear infinite; 57 | -webkit-animation: shadow 0.58s linear infinite; 58 | -moz-animation: shadow 0.58s linear infinite; 59 | } 60 | .cssload-box-loading:after { 61 | content: ''; 62 | width: 49px; 63 | height: 49px; 64 | background: rgb(26,54,104); 65 | position: absolute; 66 | top: 0; 67 | left: 0; 68 | border-radius: 3px; 69 | animation: cssload-animate 0.58s linear infinite; 70 | -o-animation: cssload-animate 0.58s linear infinite; 71 | -ms-animation: cssload-animate 0.58s linear infinite; 72 | -webkit-animation: cssload-animate 0.58s linear infinite; 73 | -moz-animation: cssload-animate 0.58s linear infinite; 74 | } 75 | 76 | 77 | 78 | @keyframes cssload-animate { 79 | 17% { 80 | border-bottom-right-radius: 3px; 81 | } 82 | 25% { 83 | transform: translateY(9px) rotate(22.5deg); 84 | } 85 | 50% { 86 | transform: translateY(18px) scale(1, 0.9) rotate(45deg); 87 | border-bottom-right-radius: 39px; 88 | } 89 | 75% { 90 | transform: translateY(9px) rotate(67.5deg); 91 | } 92 | 100% { 93 | transform: translateY(0) rotate(90deg); 94 | } 95 | } 96 | 97 | @-o-keyframes cssload-animate { 98 | 17% { 99 | border-bottom-right-radius: 3px; 100 | } 101 | 25% { 102 | -o-transform: translateY(9px) rotate(22.5deg); 103 | } 104 | 50% { 105 | -o-transform: translateY(18px) scale(1, 0.9) rotate(45deg); 106 | border-bottom-right-radius: 39px; 107 | } 108 | 75% { 109 | -o-transform: translateY(9px) rotate(67.5deg); 110 | } 111 | 100% { 112 | -o-transform: translateY(0) rotate(90deg); 113 | } 114 | } 115 | 116 | @-ms-keyframes cssload-animate { 117 | 17% { 118 | border-bottom-right-radius: 3px; 119 | } 120 | 25% { 121 | -ms-transform: translateY(9px) rotate(22.5deg); 122 | } 123 | 50% { 124 | -ms-transform: translateY(18px) scale(1, 0.9) rotate(45deg); 125 | border-bottom-right-radius: 39px; 126 | } 127 | 75% { 128 | -ms-transform: translateY(9px) rotate(67.5deg); 129 | } 130 | 100% { 131 | -ms-transform: translateY(0) rotate(90deg); 132 | } 133 | } 134 | 135 | @-webkit-keyframes cssload-animate { 136 | 17% { 137 | border-bottom-right-radius: 3px; 138 | } 139 | 25% { 140 | -webkit-transform: translateY(9px) rotate(22.5deg); 141 | } 142 | 50% { 143 | -webkit-transform: translateY(18px) scale(1, 0.9) rotate(45deg); 144 | border-bottom-right-radius: 39px; 145 | } 146 | 75% { 147 | -webkit-transform: translateY(9px) rotate(67.5deg); 148 | } 149 | 100% { 150 | -webkit-transform: translateY(0) rotate(90deg); 151 | } 152 | } 153 | 154 | @-moz-keyframes cssload-animate { 155 | 17% { 156 | border-bottom-right-radius: 3px; 157 | } 158 | 25% { 159 | -moz-transform: translateY(9px) rotate(22.5deg); 160 | } 161 | 50% { 162 | -moz-transform: translateY(18px) scale(1, 0.9) rotate(45deg); 163 | border-bottom-right-radius: 39px; 164 | } 165 | 75% { 166 | -moz-transform: translateY(9px) rotate(67.5deg); 167 | } 168 | 100% { 169 | -moz-transform: translateY(0) rotate(90deg); 170 | } 171 | } 172 | 173 | @keyframes shadow { 174 | 0%, 175 | 100% { 176 | transform: scale(1, 1); 177 | } 178 | 50% { 179 | transform: scale(1.2, 1); 180 | } 181 | } 182 | 183 | @-o-keyframes shadow { 184 | 0%, 185 | 100% { 186 | -o-transform: scale(1, 1); 187 | } 188 | 50% { 189 | -o-transform: scale(1.2, 1); 190 | } 191 | } 192 | 193 | @-ms-keyframes shadow { 194 | 0%, 195 | 100% { 196 | -ms-transform: scale(1, 1); 197 | } 198 | 50% { 199 | -ms-transform: scale(1.2, 1); 200 | } 201 | } 202 | 203 | @-webkit-keyframes shadow { 204 | 0%, 205 | 100% { 206 | -webkit-transform: scale(1, 1); 207 | } 208 | 50% { 209 | -webkit-transform: scale(1.2, 1); 210 | } 211 | } 212 | 213 | @-moz-keyframes shadow { 214 | 0%, 215 | 100% { 216 | -moz-transform: scale(1, 1); 217 | } 218 | 50% { 219 | -moz-transform: scale(1.2, 1); 220 | } 221 | } -------------------------------------------------------------------------------- /src/KernelHttpServer/Extensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | 3 | using KernelHttpServer.Config; 4 | using Microsoft.Azure.Functions.Worker.Http; 5 | using Microsoft.Extensions.Logging; 6 | using Microsoft.SemanticKernel; 7 | using Microsoft.SemanticKernel.CoreSkills; 8 | using Microsoft.SemanticKernel.KernelExtensions; 9 | using Microsoft.SemanticKernel.Orchestration; 10 | using Microsoft.SemanticKernel.SkillDefinition; 11 | using Microsoft.SemanticKernel.Skills.Document; 12 | using Microsoft.SemanticKernel.Skills.Document.FileSystem; 13 | using Microsoft.SemanticKernel.Skills.Document.OpenXml; 14 | using Microsoft.SemanticKernel.Skills.Web; 15 | using Microsoft.SemanticKernel.TemplateEngine; 16 | using System; 17 | using System.Collections.Generic; 18 | using System.Diagnostics.CodeAnalysis; 19 | using System.IO; 20 | using System.Linq; 21 | using System.Net; 22 | using System.Threading.Tasks; 23 | using static KernelHttpServer.Config.Constants; 24 | using Directory = System.IO.Directory; 25 | 26 | namespace KernelHttpServer; 27 | 28 | internal static class Extensions 29 | { 30 | internal static ApiKeyConfig ToApiKeyConfig(this HttpRequestData req) 31 | { 32 | var apiConfig = new ApiKeyConfig(); 33 | 34 | // completion values 35 | if (req.Headers.TryGetValues(SKHttpHeaders.CompletionBackend, out var completionAIService)) 36 | { 37 | apiConfig.CompletionConfig.AIService = Enum.Parse(completionAIService.First()); 38 | } 39 | 40 | if (req.Headers.TryGetValues(SKHttpHeaders.CompletionModel, out var completionModelValue)) 41 | { 42 | apiConfig.CompletionConfig.DeploymentOrModelId = completionModelValue.First(); 43 | apiConfig.CompletionConfig.Label = apiConfig.CompletionConfig.DeploymentOrModelId; 44 | } 45 | 46 | if (req.Headers.TryGetValues(SKHttpHeaders.CompletionEndpoint, out var completionEndpoint)) 47 | { 48 | apiConfig.CompletionConfig.Endpoint = completionEndpoint.First(); 49 | } 50 | 51 | if (req.Headers.TryGetValues(SKHttpHeaders.CompletionKey, out var completionKey)) 52 | { 53 | apiConfig.CompletionConfig.Key = completionKey.First(); 54 | } 55 | 56 | // embedding values 57 | if (req.Headers.TryGetValues(SKHttpHeaders.EmbeddingBackend, out var embeddingAIService)) 58 | { 59 | apiConfig.EmbeddingConfig.AIService = Enum.Parse(embeddingAIService.First()); 60 | } 61 | 62 | if (req.Headers.TryGetValues(SKHttpHeaders.EmbeddingModel, out var embeddingModelValue)) 63 | { 64 | apiConfig.EmbeddingConfig.DeploymentOrModelId = embeddingModelValue.First(); 65 | apiConfig.EmbeddingConfig.Label = apiConfig.EmbeddingConfig.DeploymentOrModelId; 66 | } 67 | 68 | if (req.Headers.TryGetValues(SKHttpHeaders.EmbeddingEndpoint, out var embeddingEndpoint)) 69 | { 70 | apiConfig.EmbeddingConfig.Endpoint = embeddingEndpoint.First(); 71 | } 72 | 73 | if (req.Headers.TryGetValues(SKHttpHeaders.EmbeddingKey, out var embeddingKey)) 74 | { 75 | apiConfig.EmbeddingConfig.Key = embeddingKey.First(); 76 | } 77 | 78 | return apiConfig; 79 | } 80 | 81 | internal static async Task CreateResponseWithMessageAsync(this HttpRequestData req, HttpStatusCode statusCode, string message) 82 | { 83 | HttpResponseData response = req.CreateResponse(statusCode); 84 | await response.WriteStringAsync(message); 85 | return response; 86 | } 87 | 88 | internal static ISKFunction GetFunction(this IReadOnlySkillCollection skills, string skillName, string functionName) 89 | { 90 | return skills.HasNativeFunction(skillName, functionName) 91 | ? skills.GetNativeFunction(skillName, functionName) 92 | : skills.GetSemanticFunction(skillName, functionName); 93 | } 94 | 95 | internal static bool HasSemanticOrNativeFunction(this IReadOnlySkillCollection skills, string skillName, string functionName) 96 | { 97 | return skills.HasSemanticFunction(skillName, functionName) || skills.HasNativeFunction(skillName, functionName); 98 | } 99 | 100 | internal static void RegisterPlanner(this IKernel kernel) 101 | { 102 | PlannerSkill planner = new(kernel); 103 | _ = kernel.ImportSkill(planner, nameof(PlannerSkill)); 104 | } 105 | 106 | internal static void RegisterTextMemory(this IKernel kernel) 107 | { 108 | _ = kernel.ImportSkill(new TextMemorySkill(), nameof(TextMemorySkill)); 109 | } 110 | 111 | [SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", 112 | Justification = "The caller invokes native skills during a request and the skill instances must remain alive for those requests to be successful.")] 113 | internal static void RegisterNativeSkills(this IKernel kernel, IEnumerable? skillsToLoad = null) 114 | { 115 | if (ShouldLoad(nameof(DocumentSkill), skillsToLoad)) 116 | { 117 | DocumentSkill documentSkill = new(new WordDocumentConnector(), new LocalFileSystemConnector()); 118 | _ = kernel.ImportSkill(documentSkill, nameof(DocumentSkill)); 119 | } 120 | 121 | if (ShouldLoad(nameof(ConversationSummarySkill), skillsToLoad)) 122 | { 123 | ConversationSummarySkill conversationSummarySkill = new(kernel); 124 | _ = kernel.ImportSkill(conversationSummarySkill, nameof(ConversationSummarySkill)); 125 | } 126 | 127 | if (ShouldLoad(nameof(WebFileDownloadSkill), skillsToLoad)) 128 | { 129 | var webFileDownloadSkill = new WebFileDownloadSkill(); 130 | _ = kernel.ImportSkill(webFileDownloadSkill, nameof(WebFileDownloadSkill)); 131 | } 132 | 133 | } 134 | 135 | internal static void RegisterSemanticSkills( 136 | this IKernel kernel, 137 | string skillsFolder, 138 | ILogger logger, 139 | IEnumerable? skillsToLoad = null) 140 | { 141 | foreach (string skPromptPath in Directory.EnumerateFiles(skillsFolder, "*.txt", SearchOption.AllDirectories)) 142 | { 143 | FileInfo fInfo = new(skPromptPath); 144 | DirectoryInfo? currentFolder = fInfo.Directory; 145 | 146 | while (currentFolder?.Parent?.FullName != skillsFolder) 147 | { 148 | currentFolder = currentFolder?.Parent; 149 | } 150 | 151 | if (ShouldLoad(currentFolder.Name, skillsToLoad)) 152 | { 153 | try 154 | { 155 | _ = kernel.ImportSemanticSkillFromDirectory(skillsFolder, currentFolder.Name); 156 | } 157 | catch (TemplateException e) 158 | { 159 | logger.LogWarning("Could not load skill from {0} with error: {1}", currentFolder.Name, e.Message); 160 | } 161 | } 162 | } 163 | } 164 | 165 | private static bool ShouldLoad(string skillName, IEnumerable? skillsToLoad = null) 166 | { 167 | return skillsToLoad?.Contains(skillName, StringComparer.InvariantCultureIgnoreCase) != false; 168 | } 169 | } 170 | -------------------------------------------------------------------------------- /src/ChatGpt.Desktop/wwwroot/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Demo 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 209 | 210 | 211 | 212 | 213 |
214 |
215 |
216 |
217 | 218 |
219 | An unhandled error has occurred. 220 | Reload 221 | 🗙 222 |
223 | 224 | 225 | 226 | --------------------------------------------------------------------------------