Files

1 line
7.0 KiB
JSON
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{"repo": "bigbrother42/reactivedemo", "files": {"ReactiveDemo/ViewModels/MainWindow/DeepSeek/DeepSeekDemoViewModel.cs": {"bbdb272dc4d6f4ecc2e6086abe314931da28175e": {"t": 1785746210.0637069, "n": 3257, "h": "e44744bd1ff1dcf4", "c": "using Newtonsoft.Json.Linq;\nusing Reactive.Bindings;\nusing Reactive.Bindings.Extensions;\nusing System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Net.Http.Headers;\nusing System.Net.Http;\nusing System.Text;\nusing System.Threading.Tasks;\nusing Newtonsoft.Json;\nusing Microsoft.EntityFrameworkCore.Metadata;\n\nnamespace ReactiveDemo.ViewModels.MainWindow.DeepSeek\n{\n public class DeepSeekDemoViewModel : ViewModelBase\n {\n #region Field\n\n private static readonly string apiKey = \"sk-989bef8c6eb8452b86363aa5007dce9f\";\n private static readonly string apiUrl = \"https://api.deepseek.com\";\n\n #endregion\n\n #region PrivateProperty\n\n\n\n #endregion\n\n #region ReactiveCommand\n\n public AsyncReactiveCommand CallAPICommand { get; set; }\n\n #endregion\n\n #region ReactiveProperty\n\n\n\n #endregion\n\n #region Request\n\n \n\n #endregion\n\n #region Events\n\n\n\n #endregion\n\n #region Override\n\n protected override void InitData()\n {\n base.InitData();\n\n }\n\n protected override void RegisterProperties()\n {\n base.RegisterProperties();\n }\n\n protected override void RegisterCommands()\n {\n base.RegisterCommands();\n\n CallAPICommand = new AsyncReactiveCommand().AddTo(DisposablePool);\n CallAPICommand.Subscribe(CallAPIMethodAsync).AddTo(DisposablePool);\n }\n\n protected override void RegisterPubEvents()\n {\n base.RegisterPubEvents();\n }\n\n #endregion\n\n #region Method\n\n private async Task CallAPIMethodAsync()\n {\n string searchTerm = \"4+5等于多少?\";\n\n try\n {\n var response = await CallDeepSeekApiAsync(searchTerm);\n }\n catch (Exception ex)\n {\n Console.WriteLine($\"An error occurred: {ex.Message}\");\n }\n }\n\n private async Task<String> CallDeepSeekApiAsync(string searchTerm)\n {\n using (var client = new HttpClient())\n {\n client.DefaultRequestHeaders.TryAddWithoutValidation(\"Authorization\", $\"Bearer {apiKey}\");\n client.DefaultRequestHeaders.Add(\"Accept\", \"application/json\");\n\n var requestData = new\n {\n prompt = searchTerm,\n max_tokens = 50\n };\n\n var jsonContent = JsonConvert.SerializeObject(requestData);\n var httpContent = new StringContent(jsonContent, Encoding.UTF8, \"application/json\");\n\n var response = await client.PostAsync($\"{apiUrl}\", httpContent);\n\n if (response.IsSuccessStatusCode)\n {\n var responseJson = await response.Content.ReadAsStringAsync();\n return responseJson;\n }\n else\n {\n var errorResponse = await response.Content.ReadAsStringAsync();\n throw new Exception($\"API call failed: {response.StatusCode}\\n{errorResponse}\");\n }\n }\n }\n\n #endregion\n }\n}\n"}, "df4a33b65c8fe59a5e11b5f433a03684778bbda9": {"t": 1785760640.8171568, "n": 3257, "h": "e44744bd1ff1dcf4", "c": "using Newtonsoft.Json.Linq;\nusing Reactive.Bindings;\nusing Reactive.Bindings.Extensions;\nusing System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Net.Http.Headers;\nusing System.Net.Http;\nusing System.Text;\nusing System.Threading.Tasks;\nusing Newtonsoft.Json;\nusing Microsoft.EntityFrameworkCore.Metadata;\n\nnamespace ReactiveDemo.ViewModels.MainWindow.DeepSeek\n{\n public class DeepSeekDemoViewModel : ViewModelBase\n {\n #region Field\n\n private static readonly string apiKey = \"sk-989bef8c6eb8452b86363aa5007dce9f\";\n private static readonly string apiUrl = \"https://api.deepseek.com\";\n\n #endregion\n\n #region PrivateProperty\n\n\n\n #endregion\n\n #region ReactiveCommand\n\n public AsyncReactiveCommand CallAPICommand { get; set; }\n\n #endregion\n\n #region ReactiveProperty\n\n\n\n #endregion\n\n #region Request\n\n \n\n #endregion\n\n #region Events\n\n\n\n #endregion\n\n #region Override\n\n protected override void InitData()\n {\n base.InitData();\n\n }\n\n protected override void RegisterProperties()\n {\n base.RegisterProperties();\n }\n\n protected override void RegisterCommands()\n {\n base.RegisterCommands();\n\n CallAPICommand = new AsyncReactiveCommand().AddTo(DisposablePool);\n CallAPICommand.Subscribe(CallAPIMethodAsync).AddTo(DisposablePool);\n }\n\n protected override void RegisterPubEvents()\n {\n base.RegisterPubEvents();\n }\n\n #endregion\n\n #region Method\n\n private async Task CallAPIMethodAsync()\n {\n string searchTerm = \"4+5等于多少?\";\n\n try\n {\n var response = await CallDeepSeekApiAsync(searchTerm);\n }\n catch (Exception ex)\n {\n Console.WriteLine($\"An error occurred: {ex.Message}\");\n }\n }\n\n private async Task<String> CallDeepSeekApiAsync(string searchTerm)\n {\n using (var client = new HttpClient())\n {\n client.DefaultRequestHeaders.TryAddWithoutValidation(\"Authorization\", $\"Bearer {apiKey}\");\n client.DefaultRequestHeaders.Add(\"Accept\", \"application/json\");\n\n var requestData = new\n {\n prompt = searchTerm,\n max_tokens = 50\n };\n\n var jsonContent = JsonConvert.SerializeObject(requestData);\n var httpContent = new StringContent(jsonContent, Encoding.UTF8, \"application/json\");\n\n var response = await client.PostAsync($\"{apiUrl}\", httpContent);\n\n if (response.IsSuccessStatusCode)\n {\n var responseJson = await response.Content.ReadAsStringAsync();\n return responseJson;\n }\n else\n {\n var errorResponse = await response.Content.ReadAsStringAsync();\n throw new Exception($\"API call failed: {response.StatusCode}\\n{errorResponse}\");\n }\n }\n }\n\n #endregion\n }\n}\n"}}}}