Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow split credentials for embeddings vs LLMs #1056

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions memgpt/cli/cli_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
app = typer.Typer()


def get_azure_credentials():
def get_azure_credentials() -> dict:
creds = dict(
azure_key=os.getenv("AZURE_OPENAI_KEY"),
azure_endpoint=os.getenv("AZURE_OPENAI_ENDPOINT"),
Expand All @@ -41,12 +41,17 @@ def get_azure_credentials():
# embedding endpoint and version default to non-embedding
creds["azure_embedding_endpoint"] = os.getenv("AZURE_OPENAI_EMBEDDING_ENDPOINT", creds["azure_endpoint"])
creds["azure_embedding_version"] = os.getenv("AZURE_OPENAI_EMBEDDING_VERSION", creds["azure_version"])
creds["azure_embedding_key"] = os.getenv("AZURE_OPENAI_EMBEDDING_KEY", creds["azure_key"])
return creds


def get_openai_credentials():
def get_openai_credentials() -> dict:
openai_key = os.getenv("OPENAI_API_KEY")
return openai_key
openai_embedding_key = os.getenv("OPENAI_API_EMBEDDING_KEY", openai_key)
return {
"openai_key": openai_key,
"openai_embedding_key": openai_embedding_key,
}


def configure_llm_endpoint(config: MemGPTConfig, credentials: MemGPTCredentials):
Expand Down Expand Up @@ -117,6 +122,7 @@ def configure_llm_endpoint(config: MemGPTConfig, credentials: MemGPTCredentials)
)
else:
credentials.azure_key = azure_creds["azure_key"]
credentials.azure_embedding_key = azure_creds["azure_embedding_key"]
credentials.azure_embedding_version = azure_creds["azure_embedding_version"]
credentials.azure_embedding_endpoint = azure_creds["azure_embedding_endpoint"]
if "azure_embedding_deployment" in azure_creds:
Expand Down Expand Up @@ -460,7 +466,14 @@ def configure_embedding_endpoint(config: MemGPTConfig, credentials: MemGPTCreden
elif embedding_provider == "azure":
# check for necessary vars
azure_creds = get_azure_credentials()
if not all([azure_creds["azure_key"], azure_creds["azure_embedding_endpoint"], azure_creds["azure_embedding_version"]]):
if not all(
[
azure_creds["azure_key"],
azure_creds["azure_embedding_endpoint"],
azure_creds["azure_embedding_version"],
azure_creds["azure_embedding_key"],
]
):
raise ValueError(
"Missing environment variables for Azure (see https://memgpt.readme.io/docs/endpoints#azure-openai). Please set then run `memgpt configure` again."
)
Expand Down Expand Up @@ -624,7 +637,7 @@ def configure():

# check credentials
credentials = MemGPTCredentials.load()
openai_key = get_openai_credentials()
openai_creds = get_openai_credentials()
azure_creds = get_azure_credentials()

MemGPTConfig.create_config_dir()
Expand Down Expand Up @@ -663,7 +676,7 @@ def configure():
return

# openai key might have gotten added along the way
openai_key = credentials.openai_key if credentials.openai_key is not None else openai_key
openai_key = credentials.openai_key if credentials.openai_key is not None else openai_creds["openai_key"]

# TODO: remove most of this (deplicated with User table)
config = MemGPTConfig(
Expand Down
6 changes: 6 additions & 0 deletions memgpt/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class MemGPTCredentials:
# openai config
openai_auth_type: str = "bearer_token"
openai_key: Optional[str] = None
openai_embedding_key: Optional[str] = None

# azure config
azure_auth_type: str = "api_key"
Expand All @@ -39,6 +40,7 @@ class MemGPTCredentials:
azure_endpoint: Optional[str] = None
azure_deployment: Optional[str] = None
# embeddings
azure_embedding_key: Optional[str] = None
azure_embedding_version: Optional[str] = None
azure_embedding_endpoint: Optional[str] = None
azure_embedding_deployment: Optional[str] = None
Expand All @@ -64,12 +66,14 @@ def load(cls) -> "MemGPTCredentials":
# openai
"openai_auth_type": get_field(config, "openai", "auth_type"),
"openai_key": get_field(config, "openai", "key"),
"openai_embedding_key": get_field(config, "openai", "embedding_key"),
# azure
"azure_auth_type": get_field(config, "azure", "auth_type"),
"azure_key": get_field(config, "azure", "key"),
"azure_version": get_field(config, "azure", "version"),
"azure_endpoint": get_field(config, "azure", "endpoint"),
"azure_deployment": get_field(config, "azure", "deployment"),
"azure_embedding_key": get_field(config, "azure", "embedding_key"),
"azure_embedding_version": get_field(config, "azure", "embedding_version"),
"azure_embedding_endpoint": get_field(config, "azure", "embedding_endpoint"),
"azure_embedding_deployment": get_field(config, "azure", "embedding_deployment"),
Expand All @@ -94,13 +98,15 @@ def save(self):
# openai config
set_field(config, "openai", "auth_type", self.openai_auth_type)
set_field(config, "openai", "key", self.openai_key)
set_field(config, "openai", "embedding_key", self.openai_embedding_key)

# azure config
set_field(config, "azure", "auth_type", self.azure_auth_type)
set_field(config, "azure", "key", self.azure_key)
set_field(config, "azure", "version", self.azure_version)
set_field(config, "azure", "endpoint", self.azure_endpoint)
set_field(config, "azure", "deployment", self.azure_deployment)
set_field(config, "azure", "embedding_key", self.azure_embedding_key)
set_field(config, "azure", "embedding_version", self.azure_embedding_version)
set_field(config, "azure", "embedding_endpoint", self.azure_embedding_endpoint)
set_field(config, "azure", "embedding_deployment", self.azure_embedding_deployment)
Expand Down
Loading