Add askai
This commit is contained in:
parent
4381fd48a4
commit
0c4fafbfb6
79
askai
Normal file
79
askai
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
#!/home/brickman/voice-ollama/venv/bin/python3
|
||||||
|
|
||||||
|
from langchain.llms import Ollama
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import textwrap
|
||||||
|
|
||||||
|
# Load model details from the config file
|
||||||
|
try:
|
||||||
|
with open(os.path.expanduser('~/.config.json'), 'r') as f:
|
||||||
|
data = json.load(f)
|
||||||
|
except FileNotFoundError:
|
||||||
|
print("Error: Please run this tool with the --config flag set before you continue.")
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
if '--config' in sys.argv:
|
||||||
|
# Check that no
|
||||||
|
if not sys.stdin.isatty():
|
||||||
|
print("Error: Please do not use the --config flag when piping data into askai")
|
||||||
|
exit()
|
||||||
|
|
||||||
|
# Check if the config.json file exists
|
||||||
|
if not os.path.isfile(os.path.expanduser('~/.config.json')):
|
||||||
|
# Create a new configuration file
|
||||||
|
f = open(os.path.expanduser('~/.config.json'), 'x')
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
f = open(os.path.expanduser('~/.config.json'), 'w')
|
||||||
|
data = {}
|
||||||
|
|
||||||
|
# Ask the user to set the model details
|
||||||
|
print("Please enter the model that you want to use:")
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
data['model'] = input()
|
||||||
|
break
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
# Ask the user to set the model details
|
||||||
|
print("Please enter the Ollama url that you want to use:")
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
data['base_url'] = input()
|
||||||
|
break
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Save the configuration file
|
||||||
|
json.dump(data, f)
|
||||||
|
f.close()
|
||||||
|
print("You have secessfully saved " + data['model'] + " as you default model and " + data['base_url'] + " as the ollama url")
|
||||||
|
print('')
|
||||||
|
exit()
|
||||||
|
|
||||||
|
if 'base_url' not in data or 'model' not in data:
|
||||||
|
print('Error: missing base url or model please rerun with --config flag')
|
||||||
|
exit()
|
||||||
|
|
||||||
|
ollama = Ollama(base_url=data['base_url'], model=data['model'])
|
||||||
|
|
||||||
|
user_input = "\n"+ sys.argv[-1]
|
||||||
|
|
||||||
|
if not sys.stdin.isatty():
|
||||||
|
std_input = "\n" + sys.stdin.read()
|
||||||
|
else:
|
||||||
|
print("Please input data to the stdin")
|
||||||
|
exit()
|
||||||
|
|
||||||
|
|
||||||
|
prompt = f"""You are askai an interactive Linux tool that takes data in through stdin and process it according to what the user specifies. Make sure that your response is short and factual.
|
||||||
|
|
||||||
|
User: {textwrap.indent(user_input, ' ')} using the following information.
|
||||||
|
Information: {textwrap.indent(std_input, ' ')}
|
||||||
|
"""
|
||||||
|
#print(prompt)
|
||||||
|
|
||||||
|
output = ollama(prompt)
|
||||||
|
print(output)
|
Loading…
Reference in New Issue
Block a user