mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-07 12:16:04 +00:00
Reduce code complexity
This commit is contained in:
parent
5b2863058a
commit
e7b6a87175
|
@ -49,12 +49,9 @@ namespace WelsonJS.Launcher.ResourceTools
|
||||||
var resourceStrings = new Dictionary<string, string>();
|
var resourceStrings = new Dictionary<string, string>();
|
||||||
foreach (System.Collections.DictionaryEntry entry in resourceSet)
|
foreach (System.Collections.DictionaryEntry entry in resourceSet)
|
||||||
{
|
{
|
||||||
string key = (string)entry.Key;
|
if (entry.Value is string strValue)
|
||||||
object value = entry.Value;
|
|
||||||
|
|
||||||
if (value is string strValue)
|
|
||||||
{
|
{
|
||||||
resourceStrings[key] = strValue;
|
resourceStrings[(string)entry.Key] = strValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,16 +59,11 @@ namespace WelsonJS.Launcher.ResourceTools
|
||||||
var appConfig = ConfigurationManager.AppSettings.AllKeys
|
var appConfig = ConfigurationManager.AppSettings.AllKeys
|
||||||
.ToDictionary(k => k, k => ConfigurationManager.AppSettings[k]);
|
.ToDictionary(k => k, k => ConfigurationManager.AppSettings[k]);
|
||||||
|
|
||||||
// Merge keys from both sources (app.config has priority)
|
// Merge by starting with resourceStrings and letting app.config override
|
||||||
var allKeys = new HashSet<string>(resourceStrings.Keys.Concat(appConfig.Keys));
|
var finalConfig = new Dictionary<string, string>(resourceStrings);
|
||||||
var finalConfig = new Dictionary<string, string>();
|
foreach (var kv in appConfig)
|
||||||
|
|
||||||
foreach (var key in allKeys)
|
|
||||||
{
|
{
|
||||||
if (appConfig.ContainsKey(key))
|
finalConfig[kv.Key] = kv.Value;
|
||||||
finalConfig[key] = appConfig[key];
|
|
||||||
else if (resourceStrings.ContainsKey(key))
|
|
||||||
finalConfig[key] = resourceStrings[key];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate XML using XElement
|
// Generate XML using XElement
|
||||||
|
|
|
@ -164,6 +164,13 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function pushPromptMessage(role, content) {
|
||||||
|
promptMessages.push({
|
||||||
|
role: role,
|
||||||
|
content: content
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
require(["vs/editor/editor.main"], function () {
|
require(["vs/editor/editor.main"], function () {
|
||||||
editor = monaco.editor.create(document.getElementById('container'), {
|
editor = monaco.editor.create(document.getElementById('container'), {
|
||||||
value: ['// lib/sayhello.js', 'function say() {', ' console.log("hello");', '}', '', 'exports.say = say;', '', 'exports.VERSIONINFO = "SayHello (sayhello.js) version 0.1";', 'exports.AUTHOR = "abuse@catswords.net";', 'exports.global = global;', 'exports.require = global.require;'].join('\n'),
|
value: ['// lib/sayhello.js', 'function say() {', ' console.log("hello");', '}', '', 'exports.say = say;', '', 'exports.VERSIONINFO = "SayHello (sayhello.js) version 0.1";', 'exports.AUTHOR = "abuse@catswords.net";', 'exports.global = global;', 'exports.require = global.require;'].join('\n'),
|
||||||
|
@ -270,11 +277,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
appendTextToEditor(`\n// ${promptMessage}... Generating text with Copilot...`);
|
appendTextToEditor(`\n// ${promptMessage}... Generating text with Copilot...`);
|
||||||
|
pushPromptMessage("user", promptMessage);
|
||||||
promptMessages.push({
|
|
||||||
role: 'user',
|
|
||||||
content: promptMessage
|
|
||||||
})
|
|
||||||
|
|
||||||
(async function () {
|
(async function () {
|
||||||
const targetWsUrl = await getTargetByUrl('copilot.microsoft.com');
|
const targetWsUrl = await getTargetByUrl('copilot.microsoft.com');
|
||||||
|
@ -294,15 +297,11 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
appendTextToEditor(`\n// ${promptMessage}... Generating text with Azure AI...`);
|
appendTextToEditor(`\n// ${promptMessage}... Generating text with Azure AI...`);
|
||||||
|
pushPromptMessage("user", promptMessage);
|
||||||
|
|
||||||
const apiKey = settings.AzureAiServiceApiKey;
|
const apiKey = settings.AzureAiServiceApiKey;
|
||||||
const url = `${settings.AzureAiServicePrefix}models/chat/completions?api-version=${settings.AzureAiServiceApiVersion}`;
|
const url = `${settings.AzureAiServicePrefix}models/chat/completions?api-version=${settings.AzureAiServiceApiVersion}`;
|
||||||
|
|
||||||
promptMessages.push({
|
|
||||||
role: 'user',
|
|
||||||
content: promptMessage
|
|
||||||
})
|
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
messages: promptMessages,
|
messages: promptMessages,
|
||||||
max_tokens: 2048,
|
max_tokens: 2048,
|
||||||
|
@ -322,10 +321,7 @@
|
||||||
.then(response => {
|
.then(response => {
|
||||||
response.data.choices.forEach(x => {
|
response.data.choices.forEach(x => {
|
||||||
const responseContent = x.message.content;
|
const responseContent = x.message.content;
|
||||||
promptMessages.push({
|
pushPromptMessage("assistant", responseContent);
|
||||||
role: 'assistant',
|
|
||||||
content: responseContent
|
|
||||||
});
|
|
||||||
|
|
||||||
const responseText = DOMPurify.sanitize(responseContent, { ALLOWED_TAGS: [], ALLOWED_ATTR: [] });
|
const responseText = DOMPurify.sanitize(responseContent, { ALLOWED_TAGS: [], ALLOWED_ATTR: [] });
|
||||||
appendTextToEditor(`/*\n${responseText}\n*/`);
|
appendTextToEditor(`/*\n${responseText}\n*/`);
|
||||||
|
@ -457,12 +453,9 @@
|
||||||
if (response.id == 3) {
|
if (response.id == 3) {
|
||||||
const responseContent = response.result.result.value;
|
const responseContent = response.result.result.value;
|
||||||
|
|
||||||
promptMessages.push({
|
|
||||||
role: 'assistant',
|
|
||||||
content: responseContent
|
|
||||||
});
|
|
||||||
|
|
||||||
appendTextToEditor(responseContent);
|
appendTextToEditor(responseContent);
|
||||||
|
pushPromptMessage("assistant", responseContent);
|
||||||
|
|
||||||
socket.close();
|
socket.close();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user