Merge branch 'master' into pr-whitespace

This commit is contained in:
Toran Bruce Richards
2023-04-10 13:35:47 +01:00
committed by GitHub
6 changed files with 25 additions and 14 deletions

1
.gitignore vendored
View File

@@ -10,4 +10,5 @@ auto_gpt_workspace/*
venv/* venv/*
outputs/* outputs/*
ai_settings.yaml ai_settings.yaml
.vscode
auto-gpt.json auto-gpt.json

View File

@@ -193,7 +193,7 @@ Alternatively, you can set them from the command line (advanced):
For Windows Users: For Windows Users:
``` ```
setx PINECONE_API_KEY "YOUR_PINECONE_API_KEY" setx PINECONE_API_KEY "YOUR_PINECONE_API_KEY"
export PINECONE_ENV="Your pinecone region" # something like: us-east4-gcp setx PINECONE_ENV "Your pinecone region" # something like: us-east4-gcp
``` ```
For macOS and Linux users: For macOS and Linux users:

View File

@@ -44,8 +44,7 @@ def chat_with_ai(
user_input, user_input,
full_message_history, full_message_history,
permanent_memory, permanent_memory,
token_limit, token_limit):
debug=False):
"""Interact with the OpenAI API, sending the prompt, user input, message history, and permanent memory.""" """Interact with the OpenAI API, sending the prompt, user input, message history, and permanent memory."""
while True: while True:
try: try:
@@ -64,13 +63,15 @@ def chat_with_ai(
""" """
model = cfg.fast_llm_model # TODO: Change model from hardcode to argument model = cfg.fast_llm_model # TODO: Change model from hardcode to argument
# Reserve 1000 tokens for the response # Reserve 1000 tokens for the response
if debug:
print(f"Token limit: {token_limit}") if cfg.debug_mode:
print(f"Token limit: {token_limit}")
send_token_limit = token_limit - 1000 send_token_limit = token_limit - 1000
relevant_memory = permanent_memory.get_relevant(str(full_message_history[-5:]), 10) relevant_memory = permanent_memory.get_relevant(str(full_message_history[-5:]), 10)
if debug: if cfg.debug_mode:
print('Memory Stats: ', permanent_memory.get_stats()) print('Memory Stats: ', permanent_memory.get_stats())
next_message_to_add_index, current_tokens_used, insertion_index, current_context = generate_context( next_message_to_add_index, current_tokens_used, insertion_index, current_context = generate_context(
@@ -109,7 +110,7 @@ def chat_with_ai(
# assert tokens_remaining >= 0, "Tokens remaining is negative. This should never happen, please submit a bug report at https://www.github.com/Torantulino/Auto-GPT" # assert tokens_remaining >= 0, "Tokens remaining is negative. This should never happen, please submit a bug report at https://www.github.com/Torantulino/Auto-GPT"
# Debug print the current context # Debug print the current context
if debug: if cfg.debug_mode:
print(f"Token limit: {token_limit}") print(f"Token limit: {token_limit}")
print(f"Send Token Count: {current_tokens_used}") print(f"Send Token Count: {current_tokens_used}")
print(f"Tokens remaining for response: {tokens_remaining}") print(f"Tokens remaining for response: {tokens_remaining}")

View File

@@ -36,8 +36,8 @@ class Config(metaclass=Singleton):
self.debug = False self.debug = False
self.continuous_mode = False self.continuous_mode = False
self.speak_mode = False self.speak_mode = False
# TODO - make these models be self-contained, using langchain, so we can configure them once and call it good
self.fast_llm_model = os.getenv("FAST_LLM_MODEL", "gpt-3.5-turbo") self.fast_llm_model = os.getenv("FAST_LLM_MODEL", "gpt-3.5-turbo")
self.smart_llm_model = os.getenv("SMART_LLM_MODEL", "gpt-4") self.smart_llm_model = os.getenv("SMART_LLM_MODEL", "gpt-4")
self.fast_token_limit = int(os.getenv("FAST_TOKEN_LIMIT", 4000)) self.fast_token_limit = int(os.getenv("FAST_TOKEN_LIMIT", 4000))
self.smart_token_limit = int(os.getenv("SMART_TOKEN_LIMIT", 8000)) self.smart_token_limit = int(os.getenv("SMART_TOKEN_LIMIT", 8000))
@@ -86,6 +86,9 @@ class Config(metaclass=Singleton):
"""Set the speak mode value.""" """Set the speak mode value."""
self.speak_mode = value self.speak_mode = value
def set_debug_mode(self, value: bool):
self.debug_mode = value
def set_fast_llm_model(self, value: str): def set_fast_llm_model(self, value: str):
"""Set the fast LLM model value.""" """Set the fast LLM model value."""
self.fast_llm_model = value self.fast_llm_model = value

View File

@@ -60,7 +60,8 @@ def fix_and_parse_json(
" your prompt is confusing the AI. Try changing it up" " your prompt is confusing the AI. Try changing it up"
" slightly.") " slightly.")
# Now try to fix this up using the ai_functions # Now try to fix this up using the ai_functions
ai_fixed_json = fix_json(json_str, JSON_SCHEMA, cfg.debug) ai_fixed_json = fix_json(json_str, JSON_SCHEMA)
if ai_fixed_json != "failed": if ai_fixed_json != "failed":
return json.loads(ai_fixed_json) return json.loads(ai_fixed_json)
else: else:
@@ -70,10 +71,11 @@ def fix_and_parse_json(
return json_str return json_str
else: else:
raise e raise e
def fix_json(json_str: str, schema: str, debug=False) -> str: 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.""" """Fix the given JSON string to make it parseable and fully complient with the provided schema."""
# Try to fix the JSON using gpt: # Try to fix the JSON using gpt:
function_string = "def fix_json(json_str: str, schema:str=None) -> str:" function_string = "def fix_json(json_str: str, schema:str=None) -> str:"
args = [f"'''{json_str}'''", f"'''{schema}'''"] args = [f"'''{json_str}'''", f"'''{schema}'''"]
@@ -89,7 +91,7 @@ def fix_json(json_str: str, schema: str, debug=False) -> str:
result_string = call_ai_function( result_string = call_ai_function(
function_string, args, description_string, model=cfg.fast_llm_model function_string, args, description_string, model=cfg.fast_llm_model
) )
if debug: if cfg.debug_mode:
print("------------ JSON FIX ATTEMPT ---------------") print("------------ JSON FIX ATTEMPT ---------------")
print(f"Original JSON: {json_str}") print(f"Original JSON: {json_str}")
print("-----------") print("-----------")

View File

@@ -277,6 +277,10 @@ def parse_arguments():
print_to_console("Speak Mode: ", Fore.GREEN, "ENABLED") print_to_console("Speak Mode: ", Fore.GREEN, "ENABLED")
cfg.set_speak_mode(True) cfg.set_speak_mode(True)
if args.debug:
print_to_console("Debug Mode: ", Fore.GREEN, "ENABLED")
cfg.set_debug_mode(True)
if args.gpt3only: if args.gpt3only:
print_to_console("GPT3.5 Only Mode: ", Fore.GREEN, "ENABLED") print_to_console("GPT3.5 Only Mode: ", Fore.GREEN, "ENABLED")
cfg.set_smart_llm_model(cfg.fast_llm_model) cfg.set_smart_llm_model(cfg.fast_llm_model)