From 9ed140f4331568a597c0dd2e1d57cb5e3adc4ec4 Mon Sep 17 00:00:00 2001
From: Sivert2101 <89571140+Sivert2101@users.noreply.github.com>
Date: Thu, 17 Oct 2024 11:33:21 +0200
Subject: [PATCH] Made a new main file that runs automatic, and added a prompt
 list

---
 llama/main_automatic.go | 86 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 86 insertions(+)
 create mode 100644 llama/main_automatic.go

diff --git a/llama/main_automatic.go b/llama/main_automatic.go
new file mode 100644
index 0000000..289bfc7
--- /dev/null
+++ b/llama/main_automatic.go
@@ -0,0 +1,86 @@
+package main
+
+import (
+	"fmt"
+	"io"
+	"llama/compiler"
+	displayindicator "llama/display-indicator"
+	"llama/extraction"
+	ollamaimplementation "llama/ollama-implementation"
+	"os"
+	"strings"
+)
+
+func main_automatic() {
+	//reader := bufio.NewReader(os.Stdin)
+	var conversationContext []int // Variable to store conversation context
+
+	//fmt.Print("Enter your prompt (or type 'exit' to quit): ")
+	//userPrompt, _ := reader.ReadString('\n')
+	//userPrompt = strings.TrimSpace(userPrompt)
+	promptText, err := os.Open("promptList.txt")
+	if err != nil {
+		fmt.Println("Error opening file", err)
+	}
+
+	text, err := io.ReadAll(promptText)
+	if err != nil {
+		fmt.Println("Error reading file:", err)
+		return
+	}
+
+	prompt := string(text)
+
+	promptList := strings.Split(prompt, "\n")
+
+	var userPrompt = ""
+	for i := range promptList {
+		fmt.Println(promptList[i])
+		userPrompt = promptList[i]
+	}
+
+	for {
+
+		//if userPrompt == "exit" {
+		//	fmt.Println("Exiting the program.")
+		//	break
+		//}
+
+		var modifiedPrompt = userPrompt + extraction.GoPrompt
+
+		fmt.Println("Prompt received. Generating response...")
+
+		// Start a go routine to display a waiting indicator while the response is being generated
+		done := make(chan bool)
+		go displayindicator.DisplayLoadingIndicator(done)
+
+		// Generate response using Ollama API, passing the context
+		response, updatedContext, err := ollamaimplementation.GetOllamaResponse(modifiedPrompt, conversationContext)
+
+		// Signal the waiting indicator to stop
+		done <- true
+
+		if err != nil {
+			fmt.Println("Error generating response:", err)
+			continue
+		}
+
+		// Update the conversation context with the response
+		//conversationContext = updatedContext
+		fmt.Println(updatedContext)
+
+		generatedCode, _ := extraction.Extract(response) // Handle error with string
+
+		fmt.Println("Ollama's response:", generatedCode)
+
+		output, err := compiler.CompileStringToGo(generatedCode)
+
+		if err != 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