2023-04-15 12:56:23 +00:00
|
|
|
"""Configuration class to store the state of bools for different scripts access."""
|
2023-04-03 02:35:28 +00:00
|
|
|
import os
|
2023-04-15 12:56:23 +00:00
|
|
|
from colorama import Fore
|
|
|
|
|
|
|
|
from autogpt.config.singleton import Singleton
|
2023-04-14 19:42:28 +00:00
|
|
|
|
2023-04-03 02:57:51 +00:00
|
|
|
import openai
|
2023-04-12 09:27:37 +00:00
|
|
|
import yaml
|
2023-03-31 03:13:31 +00:00
|
|
|
|
2023-04-15 12:56:23 +00:00
|
|
|
from dotenv import load_dotenv
|
2023-03-31 03:13:31 +00:00
|
|
|
|
2023-04-15 12:56:23 +00:00
|
|
|
load_dotenv(verbose=True)
|
2023-04-07 03:25:17 +00:00
|
|
|
|
|
|
|
|
2023-03-31 03:13:31 +00:00
|
|
|
class Config(metaclass=Singleton):
|
|
|
|
"""
|
|
|
|
Configuration class to store the state of bools for different scripts access.
|
|
|
|
"""
|
|
|
|
|
2023-04-15 12:56:23 +00:00
|
|
|
def __init__(self) -> None:
|
2023-04-09 13:42:53 +00:00
|
|
|
"""Initialize the Config class"""
|
2023-04-10 11:10:11 +00:00
|
|
|
self.debug_mode = False
|
2023-03-31 03:13:31 +00:00
|
|
|
self.continuous_mode = False
|
2023-04-12 21:30:34 +00:00
|
|
|
self.continuous_limit = 0
|
2023-03-31 03:13:31 +00:00
|
|
|
self.speak_mode = False
|
2023-04-13 09:57:57 +00:00
|
|
|
self.skip_reprompt = False
|
2023-04-10 12:35:47 +00:00
|
|
|
|
2023-04-13 11:02:42 +00:00
|
|
|
self.ai_settings_file = os.getenv("AI_SETTINGS_FILE", "ai_settings.yaml")
|
2023-04-10 16:17:11 +00:00
|
|
|
self.fast_llm_model = os.getenv("FAST_LLM_MODEL", "gpt-3.5-turbo")
|
2023-04-03 02:35:28 +00:00
|
|
|
self.smart_llm_model = os.getenv("SMART_LLM_MODEL", "gpt-4")
|
2023-04-03 10:30:39 +00:00
|
|
|
self.fast_token_limit = int(os.getenv("FAST_TOKEN_LIMIT", 4000))
|
|
|
|
self.smart_token_limit = int(os.getenv("SMART_TOKEN_LIMIT", 8000))
|
2023-04-13 22:48:07 +00:00
|
|
|
self.browse_chunk_max_length = int(os.getenv("BROWSE_CHUNK_MAX_LENGTH", 8192))
|
2023-04-14 19:42:28 +00:00
|
|
|
self.browse_summary_max_token = int(os.getenv("BROWSE_SUMMARY_MAX_TOKEN", 300))
|
2023-04-09 12:58:05 +00:00
|
|
|
|
2023-04-03 02:35:28 +00:00
|
|
|
self.openai_api_key = os.getenv("OPENAI_API_KEY")
|
2023-04-13 14:19:02 +00:00
|
|
|
self.temperature = float(os.getenv("TEMPERATURE", "1"))
|
2023-04-14 19:42:28 +00:00
|
|
|
self.use_azure = os.getenv("USE_AZURE") == "True"
|
|
|
|
self.execute_local_commands = (
|
|
|
|
os.getenv("EXECUTE_LOCAL_COMMANDS", "False") == "True"
|
|
|
|
)
|
2023-04-13 05:43:25 +00:00
|
|
|
|
2023-04-05 17:44:28 +00:00
|
|
|
if self.use_azure:
|
2023-04-12 09:27:37 +00:00
|
|
|
self.load_azure_config()
|
2023-04-13 16:47:16 +00:00
|
|
|
openai.api_type = self.openai_api_type
|
2023-04-05 17:44:28 +00:00
|
|
|
openai.api_base = self.openai_api_base
|
|
|
|
openai.api_version = self.openai_api_version
|
2023-04-09 12:58:05 +00:00
|
|
|
|
2023-04-03 02:35:28 +00:00
|
|
|
self.elevenlabs_api_key = os.getenv("ELEVENLABS_API_KEY")
|
2023-04-12 04:37:03 +00:00
|
|
|
self.elevenlabs_voice_1_id = os.getenv("ELEVENLABS_VOICE_1_ID")
|
|
|
|
self.elevenlabs_voice_2_id = os.getenv("ELEVENLABS_VOICE_2_ID")
|
2023-04-09 12:58:05 +00:00
|
|
|
|
2023-04-10 09:20:58 +00:00
|
|
|
self.use_mac_os_tts = False
|
2023-04-10 09:18:17 +00:00
|
|
|
self.use_mac_os_tts = os.getenv("USE_MAC_OS_TTS")
|
2023-04-12 20:12:25 +00:00
|
|
|
|
2023-04-11 01:00:43 +00:00
|
|
|
self.use_brian_tts = False
|
|
|
|
self.use_brian_tts = os.getenv("USE_BRIAN_TTS")
|
|
|
|
|
2023-04-03 20:44:10 +00:00
|
|
|
self.google_api_key = os.getenv("GOOGLE_API_KEY")
|
|
|
|
self.custom_search_engine_id = os.getenv("CUSTOM_SEARCH_ENGINE_ID")
|
2023-04-03 02:35:28 +00:00
|
|
|
|
2023-04-04 00:31:01 +00:00
|
|
|
self.pinecone_api_key = os.getenv("PINECONE_API_KEY")
|
|
|
|
self.pinecone_region = os.getenv("PINECONE_ENV")
|
|
|
|
|
2023-04-11 11:36:41 +00:00
|
|
|
# milvus configuration, e.g., localhost:19530.
|
|
|
|
self.milvus_addr = os.getenv("MILVUS_ADDR", "localhost:19530")
|
|
|
|
self.milvus_collection = os.getenv("MILVUS_COLLECTION", "autogpt")
|
|
|
|
|
2023-04-07 19:47:49 +00:00
|
|
|
self.image_provider = os.getenv("IMAGE_PROVIDER")
|
2023-04-07 15:02:48 +00:00
|
|
|
self.huggingface_api_token = os.getenv("HUGGINGFACE_API_TOKEN")
|
|
|
|
|
2023-04-05 21:44:16 +00:00
|
|
|
# User agent headers to use when browsing web
|
2023-04-15 12:56:23 +00:00
|
|
|
# Some websites might just completely deny request with an error code if
|
|
|
|
# no user agent was found.
|
2023-04-14 19:42:28 +00:00
|
|
|
self.user_agent = os.getenv(
|
|
|
|
"USER_AGENT",
|
2023-04-15 12:56:23 +00:00
|
|
|
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36"
|
|
|
|
" (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36",
|
2023-04-14 19:42:28 +00:00
|
|
|
)
|
2023-04-08 01:58:00 +00:00
|
|
|
self.redis_host = os.getenv("REDIS_HOST", "localhost")
|
|
|
|
self.redis_port = os.getenv("REDIS_PORT", "6379")
|
|
|
|
self.redis_password = os.getenv("REDIS_PASSWORD", "")
|
2023-04-14 19:42:28 +00:00
|
|
|
self.wipe_redis_on_start = os.getenv("WIPE_REDIS_ON_START", "True") == "True"
|
|
|
|
self.memory_index = os.getenv("MEMORY_INDEX", "auto-gpt")
|
2023-04-12 02:10:37 +00:00
|
|
|
# Note that indexes must be created on db 0 in redis, this is not configurable.
|
2023-04-07 05:48:27 +00:00
|
|
|
|
2023-04-14 19:42:28 +00:00
|
|
|
self.memory_backend = os.getenv("MEMORY_BACKEND", "local")
|
2023-04-03 02:57:38 +00:00
|
|
|
# Initialize the OpenAI API client
|
|
|
|
openai.api_key = self.openai_api_key
|
2023-04-03 02:35:28 +00:00
|
|
|
|
2023-04-12 09:27:37 +00:00
|
|
|
def get_azure_deployment_id_for_model(self, model: str) -> str:
|
|
|
|
"""
|
|
|
|
Returns the relevant deployment id for the model specified.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
model(str): The model to map to the deployment id.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
The matching deployment id if found, otherwise an empty string.
|
|
|
|
"""
|
2023-04-13 06:29:07 +00:00
|
|
|
if model == self.fast_llm_model:
|
2023-04-15 12:56:23 +00:00
|
|
|
return self.azure_model_to_deployment_id_map[
|
|
|
|
"fast_llm_model_deployment_id"
|
|
|
|
] # type: ignore
|
2023-04-13 06:29:07 +00:00
|
|
|
elif model == self.smart_llm_model:
|
2023-04-14 19:42:28 +00:00
|
|
|
return self.azure_model_to_deployment_id_map[
|
|
|
|
"smart_llm_model_deployment_id"
|
2023-04-15 12:56:23 +00:00
|
|
|
] # type: ignore
|
2023-04-13 06:29:07 +00:00
|
|
|
elif model == "text-embedding-ada-002":
|
2023-04-14 19:42:28 +00:00
|
|
|
return self.azure_model_to_deployment_id_map[
|
|
|
|
"embedding_model_deployment_id"
|
2023-04-15 12:56:23 +00:00
|
|
|
] # type: ignore
|
2023-04-13 06:29:07 +00:00
|
|
|
else:
|
2023-04-13 06:41:18 +00:00
|
|
|
return ""
|
2023-04-12 09:27:37 +00:00
|
|
|
|
2023-04-14 19:42:28 +00:00
|
|
|
AZURE_CONFIG_FILE = os.path.join(os.path.dirname(__file__), "..", "azure.yaml")
|
2023-04-12 09:27:37 +00:00
|
|
|
|
2023-04-14 19:42:28 +00:00
|
|
|
def load_azure_config(self, config_file: str = AZURE_CONFIG_FILE) -> None:
|
2023-04-12 09:27:37 +00:00
|
|
|
"""
|
2023-04-15 12:56:23 +00:00
|
|
|
Loads the configuration parameters for Azure hosting from the specified file
|
|
|
|
path as a yaml file.
|
2023-04-12 09:27:37 +00:00
|
|
|
|
|
|
|
Parameters:
|
|
|
|
config_file(str): The path to the config yaml file. DEFAULT: "../azure.yaml"
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
None
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
with open(config_file) as file:
|
|
|
|
config_params = yaml.load(file, Loader=yaml.FullLoader)
|
|
|
|
except FileNotFoundError:
|
|
|
|
config_params = {}
|
2023-04-14 19:42:28 +00:00
|
|
|
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", "")
|
|
|
|
)
|
2023-04-12 09:27:37 +00:00
|
|
|
self.azure_model_to_deployment_id_map = config_params.get("azure_model_map", [])
|
|
|
|
|
2023-04-15 12:56:23 +00:00
|
|
|
def set_continuous_mode(self, value: bool) -> None:
|
2023-04-02 17:03:37 +00:00
|
|
|
"""Set the continuous mode value."""
|
2023-03-31 03:13:31 +00:00
|
|
|
self.continuous_mode = value
|
|
|
|
|
2023-04-15 12:56:23 +00:00
|
|
|
def set_continuous_limit(self, value: int) -> None:
|
2023-04-12 21:30:34 +00:00
|
|
|
"""Set the continuous limit value."""
|
|
|
|
self.continuous_limit = value
|
|
|
|
|
2023-04-15 12:56:23 +00:00
|
|
|
def set_speak_mode(self, value: bool) -> None:
|
2023-04-02 17:03:37 +00:00
|
|
|
"""Set the speak mode value."""
|
2023-04-02 08:13:15 +00:00
|
|
|
self.speak_mode = value
|
2023-04-02 22:17:46 +00:00
|
|
|
|
2023-04-15 12:56:23 +00:00
|
|
|
def set_fast_llm_model(self, value: str) -> None:
|
2023-04-03 12:10:02 +00:00
|
|
|
"""Set the fast LLM model value."""
|
2023-04-02 22:17:46 +00:00
|
|
|
self.fast_llm_model = value
|
|
|
|
|
2023-04-15 12:56:23 +00:00
|
|
|
def set_smart_llm_model(self, value: str) -> None:
|
2023-04-03 12:10:02 +00:00
|
|
|
"""Set the smart LLM model value."""
|
2023-04-02 22:17:46 +00:00
|
|
|
self.smart_llm_model = value
|
|
|
|
|
2023-04-15 12:56:23 +00:00
|
|
|
def set_fast_token_limit(self, value: int) -> None:
|
2023-04-03 12:10:02 +00:00
|
|
|
"""Set the fast token limit value."""
|
2023-04-03 10:30:39 +00:00
|
|
|
self.fast_token_limit = value
|
|
|
|
|
2023-04-15 12:56:23 +00:00
|
|
|
def set_smart_token_limit(self, value: int) -> None:
|
2023-04-03 12:10:02 +00:00
|
|
|
"""Set the smart token limit value."""
|
2023-04-03 10:30:39 +00:00
|
|
|
self.smart_token_limit = value
|
2023-04-03 02:35:28 +00:00
|
|
|
|
2023-04-15 12:56:23 +00:00
|
|
|
def set_browse_chunk_max_length(self, value: int) -> None:
|
2023-04-12 14:36:27 +00:00
|
|
|
"""Set the browse_website command chunk max length value."""
|
|
|
|
self.browse_chunk_max_length = value
|
|
|
|
|
2023-04-15 12:56:23 +00:00
|
|
|
def set_browse_summary_max_token(self, value: int) -> None:
|
2023-04-12 14:36:27 +00:00
|
|
|
"""Set the browse_website command summary max token value."""
|
|
|
|
self.browse_summary_max_token = value
|
|
|
|
|
2023-04-15 12:56:23 +00:00
|
|
|
def set_openai_api_key(self, value: str) -> None:
|
2023-04-03 12:10:02 +00:00
|
|
|
"""Set the OpenAI API key value."""
|
2023-04-03 21:35:01 +00:00
|
|
|
self.openai_api_key = value
|
2023-04-04 09:29:02 +00:00
|
|
|
|
2023-04-15 12:56:23 +00:00
|
|
|
def set_elevenlabs_api_key(self, value: str) -> None:
|
2023-04-03 12:10:02 +00:00
|
|
|
"""Set the ElevenLabs API key value."""
|
2023-04-03 02:35:28 +00:00
|
|
|
self.elevenlabs_api_key = value
|
2023-04-04 09:29:02 +00:00
|
|
|
|
2023-04-15 12:56:23 +00:00
|
|
|
def set_elevenlabs_voice_1_id(self, value: str) -> None:
|
2023-04-12 04:37:03 +00:00
|
|
|
"""Set the ElevenLabs Voice 1 ID value."""
|
|
|
|
self.elevenlabs_voice_1_id = value
|
|
|
|
|
2023-04-15 12:56:23 +00:00
|
|
|
def set_elevenlabs_voice_2_id(self, value: str) -> None:
|
2023-04-12 04:37:03 +00:00
|
|
|
"""Set the ElevenLabs Voice 2 ID value."""
|
|
|
|
self.elevenlabs_voice_2_id = value
|
|
|
|
|
2023-04-15 12:56:23 +00:00
|
|
|
def set_google_api_key(self, value: str) -> None:
|
2023-04-04 08:37:42 +00:00
|
|
|
"""Set the Google API key value."""
|
2023-04-03 20:44:10 +00:00
|
|
|
self.google_api_key = value
|
2023-04-04 09:29:02 +00:00
|
|
|
|
2023-04-15 12:56:23 +00:00
|
|
|
def set_custom_search_engine_id(self, value: str) -> None:
|
2023-04-09 13:42:53 +00:00
|
|
|
"""Set the custom search engine id value."""
|
2023-04-04 00:31:01 +00:00
|
|
|
self.custom_search_engine_id = value
|
|
|
|
|
2023-04-15 12:56:23 +00:00
|
|
|
def set_pinecone_api_key(self, value: str) -> None:
|
2023-04-09 13:42:53 +00:00
|
|
|
"""Set the Pinecone API key value."""
|
2023-04-04 00:31:01 +00:00
|
|
|
self.pinecone_api_key = value
|
|
|
|
|
2023-04-15 12:56:23 +00:00
|
|
|
def set_pinecone_region(self, value: str) -> None:
|
2023-04-09 13:42:53 +00:00
|
|
|
"""Set the Pinecone region value."""
|
2023-04-04 00:31:01 +00:00
|
|
|
self.pinecone_region = value
|
2023-04-09 10:33:30 +00:00
|
|
|
|
2023-04-15 12:56:23 +00:00
|
|
|
def set_debug_mode(self, value: bool) -> None:
|
2023-04-09 13:42:53 +00:00
|
|
|
"""Set the debug mode value."""
|
2023-04-10 11:10:11 +00:00
|
|
|
self.debug_mode = value
|
2023-04-15 12:56:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
def check_openai_api_key() -> None:
|
|
|
|
"""Check if the OpenAI API key is set in config.py or as an environment variable."""
|
|
|
|
cfg = Config()
|
|
|
|
if not cfg.openai_api_key:
|
|
|
|
print(
|
|
|
|
Fore.RED
|
|
|
|
+ "Please set your OpenAI API key in .env or as an environment variable."
|
|
|
|
)
|
|
|
|
print("You can get your key from https://beta.openai.com/account/api-keys")
|
|
|
|
exit(1)
|