From 6ff8478118935b72c35f3ec1b31e74f2a1aa2e90 Mon Sep 17 00:00:00 2001 From: DGdev91 Date: Sat, 10 Jun 2023 13:57:42 +0200 Subject: [PATCH] Add settings for custom base url (#2594) * Add settings for custom base url and embedding dimension Making the openai base url and embedding dimension configurable, these are useful to integrate AutoGPT with other models, like LLaMA * Update to milvus.py to load the configuration also in the init_collection function * Update radismem.py to get rid of Config() loading * Update local.py to get rid of Config() loading * Correct code format (python black) * Revert DEFAULT_EMBED_DIM name to EMBED_DIM to keep tests valid * Better description for EMBED_DIM setting * Set MockConfig to the type Config in Milvus test * Fix formatting * Update Milvus test, using Config() instead of building a mock config * using the last milvus test code from main * Remove embed_dim , no more needed after #4208 * Add example for OPENAI_BASE_URL --------- Co-authored-by: Nicholas Tindle Co-authored-by: Reinier van der Leer Co-authored-by: merwanehamadi --- .env.template | 4 ++++ autogpt/config/config.py | 2 ++ 2 files changed, 6 insertions(+) diff --git a/.env.template b/.env.template index f0b3c7cb..bf6e2453 100644 --- a/.env.template +++ b/.env.template @@ -22,6 +22,10 @@ OPENAI_API_KEY=your-openai-api-key ## PROMPT_SETTINGS_FILE - Specifies which Prompt Settings file to use (defaults to prompt_settings.yaml) # PROMPT_SETTINGS_FILE=prompt_settings.yaml +## OPENAI_API_BASE_URL - Custom url for the OpenAI API, useful for connecting to custom backends. No effect if USE_AZURE is true, leave blank to keep the default url +# the following is an example: +# OPENAI_API_BASE_URL=http://localhost:443/v1 + ## AUTHORISE COMMAND KEY - Key to authorise commands # AUTHORISE_COMMAND_KEY=y diff --git a/autogpt/config/config.py b/autogpt/config/config.py index 3737308c..df77b383 100644 --- a/autogpt/config/config.py +++ b/autogpt/config/config.py @@ -82,6 +82,8 @@ class Config(metaclass=Singleton): openai.api_type = self.openai_api_type openai.api_base = self.openai_api_base openai.api_version = self.openai_api_version + elif os.getenv("OPENAI_API_BASE_URL", None): + openai.api_base = os.getenv("OPENAI_API_BASE_URL") if self.openai_organization is not None: openai.organization = self.openai_organization