diff --git a/.env.template b/.env.template index b8140dd8..2eb2b872 100644 --- a/.env.template +++ b/.env.template @@ -21,20 +21,11 @@ AI_SETTINGS_FILE=ai_settings.yaml # TEMPERATURE - Sets temperature in OpenAI (Default: 1) # USE_AZURE - Use Azure OpenAI or not (Default: False) OPENAI_API_KEY=your-openai-api-key -TEMPERATURE=1 +TEMPERATURE=0 USE_AZURE=False ### AZURE -# OPENAI_AZURE_API_BASE - OpenAI API base URL for Azure (Example: https://my-azure-openai-url.com) -# OPENAI_AZURE_API_VERSION - OpenAI API version for Azure (Example: v1) -# OPENAI_AZURE_DEPLOYMENT_ID - OpenAI deployment ID for Azure (Example: my-deployment-id) -# OPENAI_AZURE_CHAT_DEPLOYMENT_ID - OpenAI deployment ID for Azure Chat (Example: my-deployment-id-for-azure-chat) -# OPENAI_AZURE_EMBEDDINGS_DEPLOYMENT_ID - OpenAI deployment ID for Embedding (Example: my-deployment-id-for-azure-embeddigs) -OPENAI_AZURE_API_BASE=your-base-url-for-azure -OPENAI_AZURE_API_VERSION=api-version-for-azure -OPENAI_AZURE_DEPLOYMENT_ID=deployment-id-for-azure -OPENAI_AZURE_CHAT_DEPLOYMENT_ID=deployment-id-for-azure-chat -OPENAI_AZURE_EMBEDDINGS_DEPLOYMENT_ID=deployment-id-for-azure-embeddigs +# cleanup azure env as already moved to `azure.yaml.template` ################################################################################ ### LLM MODELS diff --git a/.gitignore b/.gitignore index 9874d425..91d932d8 100644 --- a/.gitignore +++ b/.gitignore @@ -151,4 +151,7 @@ dmypy.json # Pyre type checker .pyre/ llama-* -vicuna-* \ No newline at end of file +vicuna-* + +# mac +.DS_Store diff --git a/README.md b/README.md index 00bb0ea3..5559cc20 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,7 @@ pip install -r requirements.txt ``` 5. Rename `.env.template` to `.env` and fill in your `OPENAI_API_KEY`. If you plan to use Speech Mode, fill in your `ELEVEN_LABS_API_KEY` as well. - - Obtain your OpenAI API key from: https://platform.openai.com/account/api-keys. + - See [OpenAI API Keys Configuration](#openai-api-keys-configuration) to obtain your OpenAI API key. - Obtain your ElevenLabs API key from: https://elevenlabs.io. You can view your xi-api-key using the "Profile" tab on the website. - If you want to use GPT on an Azure instance, set `USE_AZURE` to `True` and then: - Rename `azure.yaml.template` to `azure.yaml` and provide the relevant `azure_api_base`, `azure_api_version` and all of the deployment ids for the relevant models in the `azure_model_map` section: @@ -179,6 +179,17 @@ Use this to use TTS for Auto-GPT python -m autogpt --speak ``` +## OpenAI API Keys Configuration + +Obtain your OpenAI API key from: https://platform.openai.com/account/api-keys. + +To use OpenAI API key for Auto-GPT, you NEED to have billing set up (AKA paid account). + +You can set up paid account at https://platform.openai.com/account/billing/overview. + +![For OpenAI API key to work, set up paid account at OpenAI API > Billing](./docs/imgs/openai-api-key-billing-paid-account.png) + + ## 🔍 Google API Keys Configuration This section is optional, use the official google api if you are having issues with error 429 when running a google search. diff --git a/autogpt/app.py b/autogpt/app.py index 0adfde5d..8d9cc9ee 100644 --- a/autogpt/app.py +++ b/autogpt/app.py @@ -105,9 +105,11 @@ def execute_command(command_name: str, arguments): # search method key = CFG.google_api_key if key and key.strip() and key != "your-google-api-key": - return google_official_search(arguments["input"]) + google_result = google_official_search(arguments["input"]) else: - return google_search(arguments["input"]) + google_result = google_search(arguments["input"]) + safe_message = google_result.encode('utf-8', 'ignore') + return str(safe_message) elif command_name == "memory_add": return memory.add(arguments["string"]) elif command_name == "start_agent": diff --git a/autogpt/config/config.py b/autogpt/config/config.py index 667c8178..1d962a3e 100644 --- a/autogpt/config/config.py +++ b/autogpt/config/config.py @@ -131,15 +131,9 @@ class Config(metaclass=Singleton): config_params = yaml.load(file, Loader=yaml.FullLoader) except FileNotFoundError: config_params = {} - self.openai_api_type = os.getenv( - "OPENAI_API_TYPE", config_params.get("azure_api_type", "azure") - ) - self.openai_api_base = os.getenv( - "OPENAI_AZURE_API_BASE", config_params.get("azure_api_base", "") - ) - self.openai_api_version = os.getenv( - "OPENAI_AZURE_API_VERSION", config_params.get("azure_api_version", "") - ) + self.openai_api_type = config_params.get("azure_api_type") or "azure" + self.openai_api_base = config_params.get("azure_api_base") or "" + self.openai_api_version = config_params.get("azure_api_version") or "2023-03-15-preview" self.azure_model_to_deployment_id_map = config_params.get("azure_model_map", []) def set_continuous_mode(self, value: bool) -> None: diff --git a/docs/imgs/openai-api-key-billing-paid-account.png b/docs/imgs/openai-api-key-billing-paid-account.png new file mode 100644 index 00000000..8948505a Binary files /dev/null and b/docs/imgs/openai-api-key-billing-paid-account.png differ diff --git a/tests/smoke_test.py b/tests/smoke_test.py new file mode 100644 index 00000000..1f0f24f9 --- /dev/null +++ b/tests/smoke_test.py @@ -0,0 +1,60 @@ +import os +import subprocess +import sys +import unittest + +from autogpt.file_operations import delete_file, read_file + +env_vars = { + 'MEMORY_BACKEND': 'no_memory', + 'TEMPERATURE': "0" +} + + +class TestCommands(unittest.TestCase): + + def test_write_file(self): + # Test case to check if the write_file command can successfully write 'Hello World' to a file + # named 'hello_world.txt'. + + # Read the current ai_settings.yaml file and store its content. + ai_settings = None + if os.path.exists('ai_settings.yaml'): + with open('ai_settings.yaml', 'r') as f: + ai_settings = f.read() + os.remove('ai_settings.yaml') + + try: + if os.path.exists('hello_world.txt'): + # Clean up any existing 'hello_world.txt' file before testing. + delete_file('hello_world.txt') + # Prepare input data for the test. + input_data = '''write_file-GPT +an AI designed to use the write_file command to write 'Hello World' into a file named "hello_world.txt" and then use the task_complete command to complete the task. +Use the write_file command to write 'Hello World' into a file named "hello_world.txt". +Use the task_complete command to complete the task. +Do not use any other commands. + +y -5 +EOF''' + command = f'{sys.executable} -m autogpt' + + # Execute the script with the input data. + process = subprocess.Popen(command, stdin=subprocess.PIPE, shell=True, env={**os.environ, **env_vars}) + process.communicate(input_data.encode()) + + # Read the content of the 'hello_world.txt' file created during the test. + content = read_file('hello_world.txt') + finally: + if ai_settings: + # Restore the original ai_settings.yaml file. + with open('ai_settings.yaml', 'w') as f: + f.write(ai_settings) + + # Check if the content of the 'hello_world.txt' file is equal to 'Hello World'. + self.assertEqual(content, 'Hello World', f"Expected 'Hello World', got {content}") + + +# Run the test case. +if __name__ == '__main__': + unittest.main()