Skip to content

Commit

Permalink
Remove Code Analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
dfuchss committed Sep 5, 2024
1 parent 9ecf51d commit 9f6f62b
Showing 1 changed file with 0 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@
import dev.langchain4j.model.openai.OpenAiChatModel;
import dev.langchain4j.model.openai.OpenAiChatModelName;
import edu.kit.kastel.mcse.ardoco.core.api.models.ArchitectureModelType;
import edu.kit.kastel.mcse.ardoco.core.api.models.CodeModelType;
import edu.kit.kastel.mcse.ardoco.core.api.models.ModelStates;
import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.ArchitectureModel;
import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.CodeModel;
import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.architecture.ArchitectureComponent;
import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.architecture.ArchitectureItem;
import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.code.CodePackage;
import edu.kit.kastel.mcse.ardoco.core.common.util.DataRepositoryHelper;
import edu.kit.kastel.mcse.ardoco.core.data.DataRepository;
import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.Informant;
Expand All @@ -38,32 +35,6 @@ public class LLMArchitectureProviderInformant extends Informant {
""",
"Now provide a list that only covers the component names. Omit common prefixes and suffixes in the names.");

private static final List<String> TEMPLATES_CODE_TO_ARCHITECTURE = List.of(
"""
You get the package names of a software project. Your task is to summarize the packages w.r.t. the architecture of the system. Try to identify possible components.
Packages:
%s
""",
"""
You get a summarization and a suggestion of the components of a software project.
Identify the possible component names and list them. Only list the component names. If you don't know what the component is about, omit it.
Summarization:
%s
""");

private static final String AGGREGATION_PROMPT = """
You get a list of possible component names. Your task is to aggregate the list and remove duplicates.
Also filter out component names, that are very generic. Do not repeat what you filtered out.
Possible component names:
%s
""";

public LLMArchitectureProviderInformant(DataRepository dataRepository) {
super(LLMArchitectureProviderInformant.class.getSimpleName(), dataRepository);
String apiKey = System.getenv("OPENAI_API_KEY");
Expand All @@ -83,53 +54,10 @@ public LLMArchitectureProviderInformant(DataRepository dataRepository) {
protected void process() {
List<String> componentNames = new ArrayList<>();
documentationToArchitecture(componentNames);
// codeToArchitecture(componentNames);
// Remove any not letter characters
componentNames = componentNames.stream().map(it -> it.replaceAll("[^a-zA-Z -_]", "").trim()).filter(it -> !it.isBlank()).distinct().sorted().toList();

/*
var aggregation = chatLanguageModel.generate(AGGREGATION_PROMPT.formatted(String.join("\n", componentNames)));
componentNames = new ArrayList<>();
parseComponentNames(aggregation, componentNames);
*/
logger.info("Component names:\n{}", String.join("\n", componentNames));

buildModel(componentNames);

}

private void codeToArchitecture(List<String> componentNames) {
var models = DataRepositoryHelper.getModelStatesData(dataRepository);
CodeModel codeModel = (CodeModel) models.getModel(CodeModelType.CODE_MODEL.getModelId());
if (codeModel == null) {
logger.warn("Code model not found");
return;
}

var packages = codeModel.getAllPackages().stream().filter(it -> it.getContent().size() > 1).toList();

List<String> responses = new ArrayList<>();
responses.add(String.join("\n", packages.stream().map(it -> getPackageName(it)).toList()));
for (String template : TEMPLATES_CODE_TO_ARCHITECTURE) {
var filledTemplate = template.formatted(responses.getLast());
var response = chatLanguageModel.generate(filledTemplate);
logger.info("Response: {}", response);
responses.add(response);
}
parseComponentNames(responses.getLast(), componentNames);

}

private String getPackageName(CodePackage codePackage) {
List<String> packageName = new ArrayList<>();
packageName.add(codePackage.getName());
var parent = codePackage.getParent();
while (parent != null) {
packageName.add(parent.getName());
parent = parent.getParent();
}
packageName = packageName.reversed();
return String.join(".", packageName);
}

private void documentationToArchitecture(List<String> componentNames) {
Expand Down

0 comments on commit 9f6f62b

Please sign in to comment.