mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-07 04:06:05 +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>();
|
||||
foreach (System.Collections.DictionaryEntry entry in resourceSet)
|
||||
{
|
||||
string key = (string)entry.Key;
|
||||
object value = entry.Value;
|
||||
|
||||
if (value is string strValue)
|
||||
if (entry.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
|
||||
.ToDictionary(k => k, k => ConfigurationManager.AppSettings[k]);
|
||||
|
||||
// Merge keys from both sources (app.config has priority)
|
||||
var allKeys = new HashSet<string>(resourceStrings.Keys.Concat(appConfig.Keys));
|
||||
var finalConfig = new Dictionary<string, string>();
|
||||
|
||||
foreach (var key in allKeys)
|
||||
// Merge by starting with resourceStrings and letting app.config override
|
||||
var finalConfig = new Dictionary<string, string>(resourceStrings);
|
||||
foreach (var kv in appConfig)
|
||||
{
|
||||
if (appConfig.ContainsKey(key))
|
||||
finalConfig[key] = appConfig[key];
|
||||
else if (resourceStrings.ContainsKey(key))
|
||||
finalConfig[key] = resourceStrings[key];
|
||||
finalConfig[kv.Key] = kv.Value;
|
||||
}
|
||||
|
||||
// Generate XML using XElement
|
||||
|
|
|
@ -164,6 +164,13 @@
|
|||
});
|
||||
}
|
||||
|
||||
function pushPromptMessage(role, content) {
|
||||
promptMessages.push({
|
||||
role: role,
|
||||
content: content
|
||||
});
|
||||
}
|
||||
|
||||
require(["vs/editor/editor.main"], function () {
|
||||
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'),
|
||||
|
@ -270,11 +277,7 @@
|
|||
}
|
||||
|
||||
appendTextToEditor(`\n// ${promptMessage}... Generating text with Copilot...`);
|
||||
|
||||
promptMessages.push({
|
||||
role: 'user',
|
||||
content: promptMessage
|
||||
})
|
||||
pushPromptMessage("user", promptMessage);
|
||||
|
||||
(async function () {
|
||||
const targetWsUrl = await getTargetByUrl('copilot.microsoft.com');
|
||||
|
@ -294,15 +297,11 @@
|
|||
}
|
||||
|
||||
appendTextToEditor(`\n// ${promptMessage}... Generating text with Azure AI...`);
|
||||
pushPromptMessage("user", promptMessage);
|
||||
|
||||
const apiKey = settings.AzureAiServiceApiKey;
|
||||
const url = `${settings.AzureAiServicePrefix}models/chat/completions?api-version=${settings.AzureAiServiceApiVersion}`;
|
||||
|
||||
promptMessages.push({
|
||||
role: 'user',
|
||||
content: promptMessage
|
||||
})
|
||||
|
||||
const data = {
|
||||
messages: promptMessages,
|
||||
max_tokens: 2048,
|
||||
|
@ -322,10 +321,7 @@
|
|||
.then(response => {
|
||||
response.data.choices.forEach(x => {
|
||||
const responseContent = x.message.content;
|
||||
promptMessages.push({
|
||||
role: 'assistant',
|
||||
content: responseContent
|
||||
});
|
||||
pushPromptMessage("assistant", responseContent);
|
||||
|
||||
const responseText = DOMPurify.sanitize(responseContent, { ALLOWED_TAGS: [], ALLOWED_ATTR: [] });
|
||||
appendTextToEditor(`/*\n${responseText}\n*/`);
|
||||
|
@ -457,12 +453,9 @@
|
|||
if (response.id == 3) {
|
||||
const responseContent = response.result.result.value;
|
||||
|
||||
promptMessages.push({
|
||||
role: 'assistant',
|
||||
content: responseContent
|
||||
});
|
||||
|
||||
appendTextToEditor(responseContent);
|
||||
pushPromptMessage("assistant", responseContent);
|
||||
|
||||
socket.close();
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user