commit 3a798f63f865693e1306e6a7b120746191cee2de Author: test Date: Sat Jan 20 18:07:28 2024 -0500 created llm_cmd diff --git a/llm_cmd b/llm_cmd new file mode 100755 index 0000000..70815b2 --- /dev/null +++ b/llm_cmd @@ -0,0 +1,86 @@ +#!/home/brickman/anaconda3/bin/python +import requests +import json +import requests +from markdown import markdown +from bs4 import BeautifulSoup +from rich.console import Console +from rich.markdown import Markdown +import sys + +try: + if len(sys.argv[1]) > 1: + question = sys.argv[1] + else: + print("Error: Please specifice a question") + exit() +except: + print("Error: Please specifice a question") + exit() + +def codeparse(text_code): + html = markdown(text_code, output_format="html5") + soup = BeautifulSoup(html, "html.parser") + for code in soup.findAll('code'): + code = str(code) + code = code.replace("bash\n","") + code = code.replace("","") + code = code.replace("","") + print(code) + + +def check_substring(main_string, substring): + return substring in main_string + +def generate_text(model, prompt, system): + url = "http://localhost:11434/api/generate" + data = { + "model": model, + "prompt": prompt, + "system": system, + "stream": False, + "options": { + "temperature": 0.8, + } + } + response = requests.post(url, json=data) + text = json.loads(response.text) + return text["response"] + +out = "" + + +while not check_substring(out, "CODETRUE"): + print('Thinking....') + text = generate_text("codellama:7b", f"You are Linux Assistant. I will ask you a question in natural language and you will return a single bash code block. Make sure that you keep the result as brief as posible.\n\nPrompt:\n{question}", """You are Linux Assistant. I will ask you a question in natural language and you will return a single bash code block. The format should be as follows: +Discription here +```bash +code goes here +``` +""") + + #text = 'The `sudo` command takes an optional argument `-h` which stands for "help". Running `sudo -h | more` will display the help message for the `sudo` command, which includes a description of its usage and options.' + + out = generate_text("codellama:7b", f"""Check the following prompt and see if it lines up with the code. +Look at the prompt and then the resulting bash code. If the result is in the correct format as speciffied below +return CODETRUE if the format is wrong or if the code is incorrect return CODEFALSE. Do not write any code or return CODE_TRUE if you write code that fixes the problem. + +Correct format: +Discription here +```bash +code goes here +``` + +Prompt: +{question} + +Bash: +{text}""", "You are a code expert.") + + +console = Console() +md = Markdown(text) +console.print(md) + + +#codeparse(text) \ No newline at end of file