fixed loop and added code to run code
This commit is contained in:
parent
3a798f63f8
commit
ed1d399b85
36
llm_cmd
36
llm_cmd
@ -6,7 +6,7 @@ from markdown import markdown
|
||||
from bs4 import BeautifulSoup
|
||||
from rich.console import Console
|
||||
from rich.markdown import Markdown
|
||||
import sys
|
||||
import sys, os
|
||||
|
||||
try:
|
||||
if len(sys.argv[1]) > 1:
|
||||
@ -40,7 +40,7 @@ def generate_text(model, prompt, system):
|
||||
"system": system,
|
||||
"stream": False,
|
||||
"options": {
|
||||
"temperature": 0.8,
|
||||
"temperature": 0.6,
|
||||
}
|
||||
}
|
||||
response = requests.post(url, json=data)
|
||||
@ -49,9 +49,10 @@ def generate_text(model, prompt, system):
|
||||
|
||||
out = ""
|
||||
|
||||
count = 0
|
||||
|
||||
while not check_substring(out, "CODETRUE"):
|
||||
print('Thinking....')
|
||||
#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
|
||||
@ -76,11 +77,34 @@ Prompt:
|
||||
|
||||
Bash:
|
||||
{text}""", "You are a code expert.")
|
||||
count+=1
|
||||
if count > 4:
|
||||
print('\n\nError: Could not find an answer to your problem')
|
||||
exit()
|
||||
|
||||
|
||||
# Showing llm output
|
||||
console = Console()
|
||||
md = Markdown(text)
|
||||
md = Markdown("# LLM Output\n" + text)
|
||||
console.print(md)
|
||||
|
||||
|
||||
#codeparse(text)
|
||||
# printing code blocks
|
||||
html = markdown(text, output_format="html5")
|
||||
soup = BeautifulSoup(html, "html.parser")
|
||||
for code in soup.findAll('code'):
|
||||
code = str(code)
|
||||
code = code.replace("<code>bash\n","")
|
||||
code = code.replace("<code>","")
|
||||
code = code.replace("</code>","")
|
||||
if len(code) < 4:
|
||||
continue
|
||||
|
||||
print("\n\n------------------------CODE----------------------------")
|
||||
console.print(Markdown(f"```bash\n{code}\n```"))
|
||||
print("--------------------------------------------------------")
|
||||
|
||||
answer = input("Would you like to run this code [N/y]:").lower()
|
||||
if answer == "y" or answer == "yes":
|
||||
print("\n")
|
||||
os.system(code)
|
||||
print("")
|
Loading…
Reference in New Issue
Block a user