diff --git a/llama/main.go b/llama/main.go index d6d1c7ca0278144bbb6958fabb72ba6d47007807..d186ad1eebcd77198fc3e3249d71361e9884fb08 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" + } + } }