Skip to content

Commit

Permalink
Updating images and promoting main config parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
jsboige committed Jan 12, 2024
1 parent 2b7e203 commit 2749dc1
Show file tree
Hide file tree
Showing 20 changed files with 1,410 additions and 1,319 deletions.
1,005 changes: 513 additions & 492 deletions Cards/Fallacies/Argumentum Fallacies - Taxonomy.csv

Large diffs are not rendered by default.

529 changes: 328 additions & 201 deletions Generation/Converters/Argumentum.AssetConverter/AssetConverterConfig.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Threading.Tasks;
using ImageMagick;

namespace Argumentum.AssetConverter
Expand All @@ -21,7 +22,7 @@ public class BatchImageConverterConfig
public double Modulation { get; set; } = 200;


public void Apply()
public async Task Apply()
{
var objSourceDir = new DirectoryInfo(SourcePath);
var objTargetDir = new DirectoryInfo(DestPath);
Expand Down
22 changes: 13 additions & 9 deletions Generation/Converters/Argumentum.AssetConverter/ConverterMode.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
namespace Argumentum.AssetConverter
using System;

namespace Argumentum.AssetConverter
{
public enum ConverterMode
{
WebBasedImageGeneration,
BatchImageProcessor,
Mindmapper,
Dnn2sxc,
DatasetUpdater
}
[Flags]
public enum ConverterMode
{
None = 0,
BatchImageProcessor = 1 << 0, // 1
WebBasedImageGeneration = 1 << 1, // 2
Mindmapper = 1 << 2, // 4
Dnn2sxc = 1 << 3, // 8
DatasetUpdater = 1 << 4, // 16
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class DatasetUpdaterConfig

public List<string> FieldsToUpdate { get; set; } = new();

public DataSetInfo SourceDataset { get; set; } = new();
public string SourceDataset { get; set; }

public string TargetPath { get; set; } = "";

Expand All @@ -83,7 +83,7 @@ public class DatasetUpdaterConfig
public int MaxChildren { get; set; } = 12;


public async Task Apply(bool useDebugPath)
public async Task Apply(AssetConverterConfig config)
{
var openAIKey = await File.ReadAllTextAsync(OpenAIKeyPath);

Expand All @@ -109,8 +109,9 @@ public async Task Apply(bool useDebugPath)
}
}, token);

var sourceDataset = config.DataSets.First(dataset => dataset.Name == SourceDataset);

var content = await SourceDataset.GetContent(useDebugPath);
var content = await sourceDataset.GetContent(config.UseDebugParams);

var resultTable = DataSetInfo.LoadCsvIntoDataTable(content, ",", PrimaryField);

Expand All @@ -136,7 +137,7 @@ bool RecordHasEmptyTargetFields(Dictionary<string, object> dictionary)

// load dataset in chunks,

var records = SourceDataset.GetDictionaryFromCsv(content, FieldsToInclude, useDebugPath);
var records = sourceDataset.GetDictionaryFromCsv(content, FieldsToInclude, config.UseDebugParams);

if (SelectEmptyTargets)
{
Expand Down Expand Up @@ -483,7 +484,7 @@ await Parallel.ForEachAsync(recordGroups, parallelOptions, async (recordGroup, c
Directory.CreateDirectory(Path.GetDirectoryName(TargetPath));
}

await SourceDataset.SaveContent(TargetPath, mergedCsv);
await sourceDataset.SaveContent(TargetPath, mergedCsv);


Logger.Log("Completed ChatGPT calls and saved the output to " + TargetPath);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using OpenAI.ObjectModels;

namespace Argumentum.AssetConverter;

public class DatasetUpdaterRootConfig
{

public async Task Apply(AssetConverterConfig config)
{
foreach (var datasetUpdaterConfig in this.DatasetUpdaterConfigs)
{
if (datasetUpdaterConfig.Enabled)
{
Logger.LogTitle($"Updating Dataset {datasetUpdaterConfig.SourceDataset}");
await datasetUpdaterConfig.Apply(config).ConfigureAwait(false);
Logger.LogTitle($"Updated Dataset {datasetUpdaterConfig.SourceDataset}");
}
}
}

private const string PromptsRootPath = @".\DatasetUpdater\Resources\";

public List<DatasetUpdaterConfig> DatasetUpdaterConfigs { get; set; } = new List<DatasetUpdaterConfig>()
{
new DatasetUpdaterConfig()
{
Enabled = false,
SourceDataset = @"Argumentum - Virtues - Taxonomy",
FieldsToInclude = new List<string>()
{
"path",
"family_fr",
"subfamily_fr",
"subsubfamily_fr",
"title_fr",
"description_fr",
"remark_fr",
"link_fr"
},
FieldsToUpdate = new List<string>()
{
"title_fr",
"description_fr",
"remark_fr",
"link_fr"
},
PrimaryField = "path",
TargetPath = @".\Target\Datasets\Argumentum Virtues - Taxonomy.csv",
SystemPromptPath = PromptsRootPath + "VirtuesJsonPromptSystem.txt",
DialogPrompts = new List<PromptExample>()
{
new PromptExample()
{
UserPromptPath = PromptsRootPath + "VirtuesJsonPromptSampleUser.json",
AssistantAnswerPath = PromptsRootPath + "VirtuesJsonPromptSampleAssistant.json"
}
},
Model = Models.Gpt_3_5_Turbo_1106,
MaxTokensPerMinute = 70000,
DivisionMode = DivisionMode.SequentialChunks,
ChunkSize = 3,
UseFunctionCalling = false,
NbMessageCalls = 1,
SkipChunkNb = 0,
TakeChunkNb = -1,
MaxDegreeOfParallelismWebService = 2
},
new DatasetUpdaterConfig()
{
Enabled = false,
SourceDataset = @"Argumentum - Fallacies - Taxonomy",
FieldsToInclude = new List<string>()
{
"path",
//"Famille",
//"Sous-Famille",
//"Soussousfamille",
"text_fr",
"desc_fr",
//"example_fr",
//"carte",
//"link_fr"
"text_en",
"desc_en",
//"example_en"
"link_en"
},
FieldsToUpdate = new List<string>()
{
//"path",
//"text_fr",
"desc_fr",
//"example_fr",
//"link_fr"
},
PrimaryField = "path",
TargetPath = @".\Target\Datasets\Argumentum Fallacies - Taxonomy.csv",
SystemPromptPath = PromptsRootPath + "PromptGeneralSystem.txt",
DialogPrompts = new List<PromptExample>()
{
new PromptExample()
{
UserPromptPath = PromptsRootPath + "PromptDocumentsLightUser.txt",
AssistantAnswerPath = PromptsRootPath + "PromptDocumentsAssistant.txt"
},
new PromptExample()
{
UserPromptPath = PromptsRootPath + "PromptInstructionsUserDescription.txt",
AssistantAnswerPath = PromptsRootPath + "PromptInstructionsAssistantDescription.txt"
}
},
Model = Models.Gpt_4_1106_preview,
MaxTokensPerMinute = 70000,
DivisionMode = DivisionMode.PKHierarchicalChar,
PKHierarchyLevel = 3,
UseFunctionCalling = true,
//FunctionName = nameof(RecordsUpdater.UpdateRecord),
NbMessageCalls = 1,
SkipChunkNb = 0,
TakeChunkNb = -1,
RandomizeChunks = true,
MaxDegreeOfParallelismWebService = 3,
CompareMode = true,
AutoCompare = true,
AutoCompareField = "text_fr",
CompareField = "desc_fr",
MaxGroupItemNb = 20,
MaxChildren = 12,
SelectEmptyTargets = false
},
new DatasetUpdaterConfig()
{
Enabled = false,
SourceDataset = @"Argumentum - Fallacies - Taxonomy",
FieldsToInclude = new List<string>()
{
"path",
//"Famille",
//"Sous-Famille",
//"Soussousfamille",
"text_fr",
"desc_fr",
"example_fr",
//"carte",
//"link_fr"
"text_en",
//"desc_en",
//"example_en",
//"link_en"
},
FieldsToUpdate = new List<string>()
{
//"path",
//"text_fr",
//"desc_fr",
"example_fr",
//"link_fr"
},
PrimaryField = "path",
TargetPath = @".\Target\Datasets\Argumentum Fallacies - Taxonomy.csv",
SystemPromptPath = PromptsRootPath + "PromptGeneralSystem.txt",
DialogPrompts = new List<PromptExample>()
{
new PromptExample()
{
UserPromptPath = PromptsRootPath + "PromptDocumentsLightUser.txt",
AssistantAnswerPath = PromptsRootPath + "PromptDocumentsAssistant.txt"
},
new PromptExample()
{
UserPromptPath = PromptsRootPath + "PromptInstructionsLightUserExamples.txt",
AssistantAnswerPath = PromptsRootPath + "PromptInstructionsLightAssistantExamples.txt"
}
},
Model = Models.Gpt_4_1106_preview,
MaxTokensPerMinute = 70000,
DivisionMode = DivisionMode.PKHierarchicalChar,
PKHierarchyLevel = 3,
UseFunctionCalling = true,
//FunctionName = nameof(RecordsUpdater.UpdateRecord),
NbMessageCalls = 1,
SkipChunkNb = 0,
TakeChunkNb = 0,
SelectEmptyTargets = true,
RandomizeChunks = false,
MaxDegreeOfParallelismWebService = 3,
CompareMode = false,
AutoCompare = true,
AutoCompareField = "text_fr",
CompareField = "example_fr",
MaxGroupItemNb = 25,
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static MagickImage LoadImageFromEmbeddedUrl(string srcUrl)

}

public static string GetImageFileName(WebBasedGeneratorConfig config, DocumentConfig docConfig, string language, string cardSetName, string imageName)
public static string GetImageFileName(AssetConverterConfig config, DocumentConfig docConfig, string language, string cardSetName, string imageName)
{

var cardSetFolderName = GetImageFolder(config, docConfig, language, cardSetName);
Expand All @@ -58,7 +58,7 @@ public static string GetImageFileName(WebBasedGeneratorConfig config, DocumentCo
return Path.Combine(cardSetFolderName, imageFileName);
}

public static string GetImageFolder(WebBasedGeneratorConfig config, DocumentConfig docConfig, string language, string cardSetName)
public static string GetImageFolder(AssetConverterConfig config, DocumentConfig docConfig, string language, string cardSetName)
{
var imagesFolderName = config.GetImagesDirectory(language);

Expand All @@ -72,7 +72,7 @@ public static string GetImageFolder(WebBasedGeneratorConfig config, DocumentConf

}

public static string LoadAndProcessImageUrl(this DocumentCardSet documentCardSet, string language, bool isBack, WebBasedGeneratorConfig config, CardSetDocumentConfig docConfig,
public static string LoadAndProcessImageUrl(this DocumentCardSet documentCardSet, string language, bool isBack, AssetConverterConfig config, CardSetDocumentConfig docConfig,
string imageName, string imageUrl, double sourceDpi)
{
string toReturn;
Expand Down
Loading

0 comments on commit 2749dc1

Please sign in to comment.