From 56930f76cc829845006d5c7deb17b681e722c8ea Mon Sep 17 00:00:00 2001 From: Rui Azevedo Date: Thu, 11 Jul 2024 10:39:55 +0100 Subject: [PATCH 1/2] Change the "write-tests" task prompt to enforce the generated code to be inside code fences, to ensure we can extract the code from the LLMs response Part of #257 --- model/llm/llm.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/model/llm/llm.go b/model/llm/llm.go index ae3f7961..0370d382 100644 --- a/model/llm/llm.go +++ b/model/llm/llm.go @@ -77,7 +77,7 @@ type llmSourceFilePromptContext struct { var llmGenerateTestForFilePromptTemplate = template.Must(template.New("model-llm-generate-test-for-file-prompt").Parse(bytesutil.StringTrimIndentations(` Given the following {{ .Language.Name }} code file "{{ .FilePath }}" with package "{{ .ImportPath }}", provide a test file for this code{{ with $testFramework := .Language.TestFramework }} with {{ $testFramework }} as a test framework{{ end }}. The tests should produce 100 percent code coverage and must compile. - The response must contain only the test code and nothing else. + The response must contain only the test code in a fenced code block and nothing else. ` + "```" + `{{ .Language.ID }} {{ .Code }} From b8a3bb5f236e7222ea19d64a6d2c69e0b8c6a1bb Mon Sep 17 00:00:00 2001 From: Rui Azevedo Date: Thu, 11 Jul 2024 10:43:39 +0100 Subject: [PATCH 2/2] Change the "code-repair" task prompt to enforce the generated code to be inside code fences, to ensure we can extract the code from the LLMs response Closes #257 --- model/llm/llm.go | 2 +- model/llm/llm_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/model/llm/llm.go b/model/llm/llm.go index 0370d382..9f3c451c 100644 --- a/model/llm/llm.go +++ b/model/llm/llm.go @@ -108,7 +108,7 @@ type llmCodeRepairSourceFilePromptContext struct { // llmCodeRepairSourceFilePromptTemplate is the template for generating an LLM code repair prompt. var llmCodeRepairSourceFilePromptTemplate = template.Must(template.New("model-llm-code-repair-source-file-prompt").Parse(bytesutil.StringTrimIndentations(` Given the following {{ .Language.Name }} code file "{{ .FilePath }}" with package "{{ .ImportPath }}" and a list of compilation errors, modify the code such that the errors are resolved. - The response must contain only the source code and nothing else. + The response must contain only the source code in a fenced code block and nothing else. ` + "```" + `{{ .Language.ID }} {{ .Code }} diff --git a/model/llm/llm_test.go b/model/llm/llm_test.go index 284f1c03..4c328f8c 100644 --- a/model/llm/llm_test.go +++ b/model/llm/llm_test.go @@ -324,7 +324,7 @@ func TestLLMCodeRepairSourceFilePrompt(t *testing.T) { ExpectedMessage: bytesutil.StringTrimIndentations(` Given the following Go code file "/path/to/foobar.go" with package "foobar" and a list of compilation errors, modify the code such that the errors are resolved. - The response must contain only the source code and nothing else. + The response must contain only the source code in a fenced code block and nothing else. ` + "```" + `golang package foobar