Merge branch 'master' into added-new-voice

pull/754/head
meta-fx 2023-04-11 08:39:15 -05:00 committed by GitHub
commit efd6a7ecf5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 14 additions and 24 deletions

1
.gitignore vendored
View File

@ -12,3 +12,4 @@ outputs/*
ai_settings.yaml
.vscode
auto-gpt.json
log.txt

View File

@ -92,4 +92,3 @@ class AIConfig:
full_prompt += f"\n\n{data.load_prompt()}"
return full_prompt

View File

@ -15,7 +15,7 @@ def scrape_text(url):
# Most basic check if the URL is valid:
if not url.startswith('http'):
return "Error: Invalid URL"
# Restrict access to local files
if check_local_file_access(url):
return "Error: Access to local files is restricted"

View File

@ -63,10 +63,10 @@ def chat_with_ai(
"""
model = cfg.fast_llm_model # TODO: Change model from hardcode to argument
# Reserve 1000 tokens for the response
if cfg.debug:
print(f"Token limit: {token_limit}")
send_token_limit = token_limit - 1000
relevant_memory = permanent_memory.get_relevant(str(full_message_history[-5:]), 10)

View File

@ -24,7 +24,7 @@ def read_file(filename):
"""Read a file and return the contents"""
try:
filepath = safe_join(working_directory, filename)
with open(filepath, "r") as f:
with open(filepath, "r", encoding='utf-8') as f:
content = f.read()
return content
except Exception as e:

View File

@ -71,11 +71,11 @@ def fix_and_parse_json(
return json_str
else:
raise e
def fix_json(json_str: str, schema: str) -> str:
"""Fix the given JSON string to make it parseable and fully complient with the provided schema."""
# Try to fix the JSON using gpt:
function_string = "def fix_json(json_str: str, schema:str=None) -> str:"
args = [f"'''{json_str}'''", f"'''{schema}'''"]

View File

@ -76,7 +76,7 @@ def balance_braces(json_string: str) -> str:
json.loads(json_string)
return json_string
except json.JSONDecodeError as e:
raise e
pass
def fix_invalid_escape(json_str: str, error_message: str) -> str:
@ -88,7 +88,7 @@ def fix_invalid_escape(json_str: str, error_message: str) -> str:
json.loads(json_str)
return json_str
except json.JSONDecodeError as e:
if cfg.debug:
if cfg.debug_mode:
print('json loads error - fix invalid escape', e)
error_message = str(e)
return json_str
@ -103,12 +103,12 @@ def correct_json(json_str: str) -> str:
"""
try:
if cfg.debug:
if cfg.debug_mode:
print("json", json_str)
json.loads(json_str)
return json_str
except json.JSONDecodeError as e:
if cfg.debug:
if cfg.debug_mode:
print('json loads error', e)
error_message = str(e)
if error_message.startswith('Invalid \\escape'):
@ -119,7 +119,7 @@ def correct_json(json_str: str) -> str:
json.loads(json_str)
return json_str
except json.JSONDecodeError as e:
if cfg.debug:
if cfg.debug_mode:
print('json loads error - add quotes', e)
error_message = str(e)
if balanced_str := balance_braces(json_str):

View File

@ -9,8 +9,6 @@ from colorama import Fore, Style
from spinner import Spinner
import time
import speak
from enum import Enum, auto
import sys
from config import Config
from json_parser import fix_and_parse_json
from ai_config import AIConfig
@ -172,7 +170,7 @@ def load_variables(config_file="config.yaml"):
documents = yaml.dump(config, file)
prompt = data.load_prompt()
prompt_start = """Your decisions must always be made independently without seeking user assistance. Play to your strengths as an LLM and pursue simple strategies with no legal complications."""
prompt_start = """Your decisions must always be made independently without seeking user assistance. Play to your strengths as a LLM and pursue simple strategies with no legal complications."""
# Construct full prompt
full_prompt = f"You are {ai_name}, {ai_role}\n{prompt_start}\n\nGOALS:\n\n"
@ -290,17 +288,10 @@ def parse_arguments():
print_to_console("Speak Mode: ", Fore.GREEN, "ENABLED")
cfg.set_speak_mode(True)
if args.debug:
print_to_console("Debug Mode: ", Fore.GREEN, "ENABLED")
cfg.set_debug_mode(True)
if args.gpt3only:
print_to_console("GPT3.5 Only Mode: ", Fore.GREEN, "ENABLED")
cfg.set_smart_llm_model(cfg.fast_llm_model)
if args.debug:
print_to_console("Debug Mode: ", Fore.GREEN, "ENABLED")
cfg.set_debug_mode(True)
# TODO: fill in llm values here
@ -417,4 +408,3 @@ while True:
chat.create_chat_message(
"system", "Unable to execute command"))
print_to_console("SYSTEM: ", Fore.YELLOW, "Unable to execute command")