mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-05-13 15:44:12 +00:00
improved provider export to handle formatting of comments
This commit is contained in:
parent
e3cb7e9734
commit
027b80eac7
@ -176,30 +176,36 @@ public sealed record EmbeddingProvider(
|
||||
/// <returns>A Lua configuration section string.</returns>
|
||||
public string ExportAsConfigurationSection(string? encryptedApiKey = null)
|
||||
{
|
||||
var apiKeyLine = string.Empty;
|
||||
if (!string.IsNullOrWhiteSpace(encryptedApiKey))
|
||||
var lines = new List<string>
|
||||
{
|
||||
apiKeyLine = $"""
|
||||
["APIKey"] = "{LuaTools.EscapeLuaString(encryptedApiKey)}",
|
||||
""";
|
||||
"CONFIG[\"EMBEDDING_PROVIDERS\"][#CONFIG[\"EMBEDDING_PROVIDERS\"]+1] = {",
|
||||
$" [\"Id\"] = \"{Guid.NewGuid()}\",",
|
||||
$" [\"Name\"] = \"{LuaTools.EscapeLuaString(this.Name)}\",",
|
||||
$" [\"UsedLLMProvider\"] = \"{this.UsedLLMProvider}\",",
|
||||
};
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(this.TokenizerPath))
|
||||
{
|
||||
lines.Add(string.Empty);
|
||||
lines.Add(" -- The tokenizer path shown is local to this model. To use it with the plugin:");
|
||||
lines.Add(" -- 1. Copy the tokenizer into the zip.");
|
||||
lines.Add(" -- 2. Update the path in the plugin file to be relative to the zip's root.");
|
||||
lines.Add($" [\"TokenizerPath\"] = \"{LuaTools.EscapeLuaString(this.TokenizerPath)}\",");
|
||||
}
|
||||
|
||||
return $$"""
|
||||
CONFIG["EMBEDDING_PROVIDERS"][#CONFIG["EMBEDDING_PROVIDERS"]+1] = {
|
||||
["Id"] = "{{Guid.NewGuid().ToString()}}",
|
||||
["Name"] = "{{LuaTools.EscapeLuaString(this.Name)}}",
|
||||
["UsedLLMProvider"] = "{{this.UsedLLMProvider}}",
|
||||
|
||||
["TokenizerPath"] = "{{this.TokenizerPath}}",
|
||||
|
||||
["Host"] = "{{this.Host}}",
|
||||
["Hostname"] = "{{LuaTools.EscapeLuaString(this.Hostname)}}",
|
||||
{{apiKeyLine}}
|
||||
["Model"] = {
|
||||
["Id"] = "{{LuaTools.EscapeLuaString(this.Model.Id)}}",
|
||||
["DisplayName"] = "{{LuaTools.EscapeLuaString(this.Model.DisplayName ?? string.Empty)}}",
|
||||
},
|
||||
}
|
||||
""";
|
||||
lines.Add(string.Empty);
|
||||
lines.Add($" [\"Host\"] = \"{this.Host}\",");
|
||||
lines.Add($" [\"Hostname\"] = \"{LuaTools.EscapeLuaString(this.Hostname)}\",");
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(encryptedApiKey))
|
||||
lines.Add($" [\"APIKey\"] = \"{LuaTools.EscapeLuaString(encryptedApiKey)}\",");
|
||||
|
||||
lines.Add(" [\"Model\"] = {");
|
||||
lines.Add($" [\"Id\"] = \"{LuaTools.EscapeLuaString(this.Model.Id)}\",");
|
||||
lines.Add($" [\"DisplayName\"] = \"{LuaTools.EscapeLuaString(this.Model.DisplayName ?? string.Empty)}\",");
|
||||
lines.Add(" },");
|
||||
lines.Add("}");
|
||||
|
||||
return string.Join(Environment.NewLine, lines);
|
||||
}
|
||||
}
|
||||
|
||||
@ -233,40 +233,40 @@ public sealed record Provider(
|
||||
/// <returns>A Lua configuration section string.</returns>
|
||||
public string ExportAsConfigurationSection(string? encryptedApiKey = null)
|
||||
{
|
||||
var hfInferenceProviderLine = string.Empty;
|
||||
var lines = new List<string>
|
||||
{
|
||||
"CONFIG[\"LLM_PROVIDERS\"][#CONFIG[\"LLM_PROVIDERS\"]+1] = {",
|
||||
$" [\"Id\"] = \"{Guid.NewGuid()}\",",
|
||||
$" [\"InstanceName\"] = \"{LuaTools.EscapeLuaString(this.InstanceName)}\",",
|
||||
$" [\"UsedLLMProvider\"] = \"{this.UsedLLMProvider}\",",
|
||||
};
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(this.TokenizerPath))
|
||||
{
|
||||
lines.Add(string.Empty);
|
||||
lines.Add(" -- The tokenizer path shown is local to this model. To use it with the plugin:");
|
||||
lines.Add(" -- 1. Copy the tokenizer into the zip.");
|
||||
lines.Add(" -- 2. Update the path in the plugin file to be relative to the zip's root.");
|
||||
lines.Add($" [\"TokenizerPath\"] = \"{LuaTools.EscapeLuaString(this.TokenizerPath)}\",");
|
||||
}
|
||||
|
||||
lines.Add(string.Empty);
|
||||
lines.Add($" [\"Host\"] = \"{this.Host}\",");
|
||||
lines.Add($" [\"Hostname\"] = \"{LuaTools.EscapeLuaString(this.Hostname)}\",");
|
||||
|
||||
if (this.HFInferenceProvider is not HFInferenceProvider.NONE)
|
||||
{
|
||||
hfInferenceProviderLine = $"""
|
||||
["HFInferenceProvider"] = "{this.HFInferenceProvider}",
|
||||
""";
|
||||
}
|
||||
lines.Add($" [\"HFInferenceProvider\"] = \"{this.HFInferenceProvider}\",");
|
||||
|
||||
var apiKeyLine = string.Empty;
|
||||
if (!string.IsNullOrWhiteSpace(encryptedApiKey))
|
||||
{
|
||||
apiKeyLine = $"""
|
||||
["APIKey"] = "{LuaTools.EscapeLuaString(encryptedApiKey)}",
|
||||
""";
|
||||
}
|
||||
lines.Add($" [\"APIKey\"] = \"{LuaTools.EscapeLuaString(encryptedApiKey)}\",");
|
||||
|
||||
return $$"""
|
||||
CONFIG["LLM_PROVIDERS"][#CONFIG["LLM_PROVIDERS"]+1] = {
|
||||
["Id"] = "{{Guid.NewGuid().ToString()}}",
|
||||
["InstanceName"] = "{{LuaTools.EscapeLuaString(this.InstanceName)}}",
|
||||
["UsedLLMProvider"] = "{{this.UsedLLMProvider}}",
|
||||
|
||||
["TokenizerPath"] = "{{this.TokenizerPath}}",
|
||||
lines.Add($" [\"AdditionalJsonApiParameters\"] = \"{LuaTools.EscapeLuaString(this.AdditionalJsonApiParameters)}\",");
|
||||
lines.Add(" [\"Model\"] = {");
|
||||
lines.Add($" [\"Id\"] = \"{LuaTools.EscapeLuaString(this.Model.Id)}\",");
|
||||
lines.Add($" [\"DisplayName\"] = \"{LuaTools.EscapeLuaString(this.Model.DisplayName ?? this.Model.Id)}\",");
|
||||
lines.Add(" },");
|
||||
lines.Add("}");
|
||||
|
||||
["Host"] = "{{this.Host}}",
|
||||
["Hostname"] = "{{LuaTools.EscapeLuaString(this.Hostname)}}",
|
||||
{{hfInferenceProviderLine}}
|
||||
{{apiKeyLine}}
|
||||
["AdditionalJsonApiParameters"] = "{{LuaTools.EscapeLuaString(this.AdditionalJsonApiParameters)}}",
|
||||
["Model"] = {
|
||||
["Id"] = "{{LuaTools.EscapeLuaString(this.Model.Id)}}",
|
||||
["DisplayName"] = "{{LuaTools.EscapeLuaString(this.Model.DisplayName ?? this.Model.Id)}}",
|
||||
},
|
||||
}
|
||||
""";
|
||||
return string.Join(Environment.NewLine, lines);
|
||||
}
|
||||
}
|
||||
|
||||
@ -167,28 +167,26 @@ public sealed record TranscriptionProvider(
|
||||
/// <returns>A Lua configuration section string.</returns>
|
||||
public string ExportAsConfigurationSection(string? encryptedApiKey = null)
|
||||
{
|
||||
var apiKeyLine = string.Empty;
|
||||
if (!string.IsNullOrWhiteSpace(encryptedApiKey))
|
||||
var lines = new List<string>
|
||||
{
|
||||
apiKeyLine = $"""
|
||||
["APIKey"] = "{LuaTools.EscapeLuaString(encryptedApiKey)}",
|
||||
""";
|
||||
}
|
||||
"CONFIG[\"TRANSCRIPTION_PROVIDERS\"][#CONFIG[\"TRANSCRIPTION_PROVIDERS\"]+1] = {",
|
||||
$" [\"Id\"] = \"{Guid.NewGuid()}\",",
|
||||
$" [\"Name\"] = \"{LuaTools.EscapeLuaString(this.Name)}\",",
|
||||
$" [\"UsedLLMProvider\"] = \"{this.UsedLLMProvider}\",",
|
||||
string.Empty,
|
||||
$" [\"Host\"] = \"{this.Host}\",",
|
||||
$" [\"Hostname\"] = \"{LuaTools.EscapeLuaString(this.Hostname)}\",",
|
||||
};
|
||||
|
||||
return $$"""
|
||||
CONFIG["TRANSCRIPTION_PROVIDERS"][#CONFIG["TRANSCRIPTION_PROVIDERS"]+1] = {
|
||||
["Id"] = "{{Guid.NewGuid().ToString()}}",
|
||||
["Name"] = "{{LuaTools.EscapeLuaString(this.Name)}}",
|
||||
["UsedLLMProvider"] = "{{this.UsedLLMProvider}}",
|
||||
if (!string.IsNullOrWhiteSpace(encryptedApiKey))
|
||||
lines.Add($" [\"APIKey\"] = \"{LuaTools.EscapeLuaString(encryptedApiKey)}\",");
|
||||
|
||||
["Host"] = "{{this.Host}}",
|
||||
["Hostname"] = "{{LuaTools.EscapeLuaString(this.Hostname)}}",
|
||||
{{apiKeyLine}}
|
||||
["Model"] = {
|
||||
["Id"] = "{{LuaTools.EscapeLuaString(this.Model.Id)}}",
|
||||
["DisplayName"] = "{{LuaTools.EscapeLuaString(this.Model.DisplayName ?? string.Empty)}}",
|
||||
},
|
||||
}
|
||||
""";
|
||||
lines.Add(" [\"Model\"] = {");
|
||||
lines.Add($" [\"Id\"] = \"{LuaTools.EscapeLuaString(this.Model.Id)}\",");
|
||||
lines.Add($" [\"DisplayName\"] = \"{LuaTools.EscapeLuaString(this.Model.DisplayName ?? string.Empty)}\",");
|
||||
lines.Add(" },");
|
||||
lines.Add("}");
|
||||
|
||||
return string.Join(Environment.NewLine, lines);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user