From 5c18ce8cea7b5310df6a8dd4f84d3b5889e80a04 Mon Sep 17 00:00:00 2001 From: Nikolaj Bjorner Date: Wed, 12 Feb 2025 19:55:39 -0800 Subject: [PATCH] genai testing Signed-off-by: Nikolaj Bjorner --- genaisrc/mycop.genai.mts | 40 ++++++++++++++++------------------------ genaisrc/myopt.genai.mts | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 24 deletions(-) create mode 100644 genaisrc/myopt.genai.mts diff --git a/genaisrc/mycop.genai.mts b/genaisrc/mycop.genai.mts index 8330267fe..d99974e5e 100644 --- a/genaisrc/mycop.genai.mts +++ b/genaisrc/mycop.genai.mts @@ -1,33 +1,21 @@ script({ title: "Invoke LLM code update", + files: "src/muz/spacer/spacer_qe_project.cpp" }) -async function runCodePrompt(role, message, code) { +async function invokeLLMUpdate(code) { const answer = await runPrompt( (_) => { - _.def("ROLE", role); - _.def("REQUEST", message); - _.def("CODE", code); - _.$`Your role is . - The request is given by - original code: - .` - } - ) - console.log(answer.text); - return answer.text; -} - -async function invokeLLMUpdate(code, inputFile) { - - let role = `You are a highly experienced compiler engineer with over 20 years of expertise, + _.def("CODE", code); + _.$` + You are a highly experienced compiler engineer with over 20 years of expertise, specializing in C and C++ programming. Your deep knowledge of best coding practices and software engineering principles enables you to produce robust, efficient, and - maintainable code in any scenario.`; + maintainable code in any scenario. - let userMessage = `Please modify the original code to ensure that it enforces the following: + Please modify the original code in to ensure that it enforces the following: - do not use pointer arithmetic. - do not introduce uses of std::vector. - do not remove comments from the code. @@ -80,17 +68,21 @@ async function invokeLLMUpdate(code, inputFile) { for (auto arg : *a) { ... } - `; - - return runCodePrompt(role, userMessage, code); + ` + }, { + system: [], + systemSafety: false + } + ) + console.log(answer.text); + return answer.text; } const inputFile = env.files[0]; const file = await workspace.readText(inputFile); -const answer = await invokeLLMUpdate(file.content, inputFile); +const answer = await invokeLLMUpdate(file.content); // Extract the code from the answer by removing ```cpp and ```: let code = answer.replace(/```cpp/g, "").replace(/```/g, ""); const outputFile = inputFile.filename + ".patch"; await workspace.writeText(outputFile, code); - diff --git a/genaisrc/myopt.genai.mts b/genaisrc/myopt.genai.mts new file mode 100644 index 000000000..a3aa62dac --- /dev/null +++ b/genaisrc/myopt.genai.mts @@ -0,0 +1,34 @@ +script({ + title: "Invoke LLM code optimization", + files: "code_slices/muz/spacer/orig_spacer_antiunify.cpp_anti_unifier.cpp" +}) + + +async function invokeLLMUpdate(code) { + const answer = await runPrompt( + (_) => { + _.def("CODE", code); + _.$` + You are a highly experienced compiler engineer with over 20 years of expertise, + specializing in C and C++ programming. Your deep knowledge of best coding practices + and software engineering principles enables you to produce robust, efficient, and + maintainable code in any scenario. + + Please modify the original code in to ensure that it uses best practices for optimal code execution.' ` + }, { + system: [], + systemSafety: false + } + ) + console.log(answer.text); + return answer.text; +} + + +const inputFile = env.files[0]; +const file = await workspace.readText(inputFile); +const answer = await invokeLLMUpdate(file.content); +// Extract the code from the answer by removing ```cpp and ```: +let code = answer.replace(/```cpp/g, "").replace(/```/g, ""); +const outputFile = inputFile.filename + ".patch"; +await workspace.writeText(outputFile, code);