From 38c3cca96dc54ff6ec87d0fc3b4dfa565e96d350 Mon Sep 17 00:00:00 2001
From: ammar68 <ammaa@stud.ntnu.no>
Date: Thu, 10 Oct 2024 00:43:21 +0200
Subject: [PATCH] add fixing errors prompt. Handle compiler output

---
 llama/main.go | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/llama/main.go b/llama/main.go
index d6d1c7c..d186ad1 100644
--- a/llama/main.go
+++ b/llama/main.go
@@ -3,6 +3,7 @@ package main
 import (
 	"bufio"
 	"fmt"
+	"llama/compiler"
 	displayindicator "llama/display-indicator"
 	"llama/extraction"
 	ollamaimplementation "llama/ollama-implementation"
@@ -14,11 +15,11 @@ func main() {
 	reader := bufio.NewReader(os.Stdin)
 	var conversationContext []int // Variable to store conversation context
 
-	for {
+	fmt.Print("Enter your prompt (or type 'exit' to quit): ")
+	userPrompt, _ := reader.ReadString('\n')
+	userPrompt = strings.TrimSpace(userPrompt)
 
-		fmt.Print("Enter your prompt (or type 'exit' to quit): ")
-		userPrompt, _ := reader.ReadString('\n')
-		userPrompt = strings.TrimSpace(userPrompt)
+	for {
 
 		if userPrompt == "exit" {
 			fmt.Println("Exiting the program.")
@@ -50,6 +51,18 @@ func main() {
 		var generatedCode = extraction.Extract(response)
 
 		fmt.Println("Ollama's response:", generatedCode)
+
+		var output string
+		var er error
+		output, er = compiler.CompileStringToGo(generatedCode)
+
+		if er != nil {
+			userPrompt = output + "\nFollowing are the errors, please fix the code. Write it again, and write only source code along with same test cases with no further explanation. The format should be ```rust <yourcode + testcases> ```"
+		} else {
+			fmt.Println("Compiled successfully. Here is the output: %v", output)
+			userPrompt = "exit"
+		}
+
 	}
 }
 
-- 
GitLab