fixed errors when .config.json is corrupt

This commit is contained in:
test 2024-01-04 11:36:16 -05:00
parent ad9364400c
commit 0061ca9dfc

9
askai Normal file → Executable file
View File

@ -1,4 +1,4 @@
#!#!/usr/bin/env askai #!/usr/bin/env python
from langchain.llms import Ollama from langchain.llms import Ollama
import json import json
@ -49,11 +49,10 @@ else:
try: try:
with open(os.path.expanduser('~/.config.json'), 'r') as f: with open(os.path.expanduser('~/.config.json'), 'r') as f:
data = json.load(f) data = json.load(f)
except FileNotFoundError: except:
print("Error: Please run this tool with the --config flag set before you continue.") print("Error: The config file is corrupt. Please run with the --config flag set.")
exit() exit()
if 'base_url' not in data or 'model' not in data: if 'base_url' not in data or 'model' not in data:
print('Error: missing base url or model please rerun with --config flag') print('Error: missing base url or model please rerun with --config flag')
exit() exit()
@ -77,4 +76,4 @@ Information: {textwrap.indent(std_input, ' ')}
#print(prompt) #print(prompt)
output = ollama(prompt) output = ollama(prompt)
print(output) print(output)