diff --git a/docs/source/users/index.md b/docs/source/users/index.md index 128ef3b23..b9e5e4452 100644 --- a/docs/source/users/index.md +++ b/docs/source/users/index.md @@ -765,6 +765,28 @@ The `--response-path` option is a [JSONPath](https://goessner.net/articles/JsonP You can specify an allowlist, to only allow only a certain list of providers, or a blocklist, to block some providers. +### Initializing default providers + +This configuration allows for setting a default model, and embedding provider with their corresponding API keys, or related fields configuration. + +Following command line arguments can be used to initialize Jupyter AI extension with default providers: +1. ```--AiExtension.model_provider_id```: Specify the default LLM model. E.g.: ```--AiExtension.model_provider_id="bedrock-chat:anthropic.claude-v2"``` +2. ```--AiExtension.embeddings_provider_id```: Specify default embedding provider. E.g.: ```--AiExtension.embeddings_provider_id="bedrock:amazon.titan-embed-text-v1"``` +3. ```--AiExtension.api_keys```: Specify model provider keys in a JSON format. E.g. ```--AiExtension.api_keys='{"OPENAI_API_KEY": "sk-abcd}'``` +4. ```--AiExtension.fields```: Specify additional configuration required for a LLM, and embedding model. E.g: ```--AiExtension.fields='{"bedrock-chat:anthropic.claude-v1":{"credentials_profile_name": "default","region_name": "us-west-2"},"bedrock:amazon.titan-embed-text-v1":{"credentials_profile_name": "default","region_name": "us-west-2"}}'``` + +#### Initializing model provider with API keys + +``` + jupyter lab --AiExtension.model_provider_id="bedrock-chat:anthropic.claude-v1" --AiExtension.fields='{"bedrock-chat:anthropic.claude-v1":{"credentials_profile_name": "default","region_name": "us-west-2"},"bedrock:amazon.titan-embed-text-v1":{"credentials_profile_name": "default","region_name": "us-west-2"}}' --AiExtension.api_keys='{"OPENAI_API_KEY": "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"} +``` + +#### Initializing model provider which requires additional fields + +``` + jupyter lab --AiExtension.model_provider_id="bedrock-chat:anthropic.claude-v1" --AiExtension.fields='{"bedrock-chat:anthropic.claude-v1":{"credentials_profile_name": "default","region_name": "us-west-2"},"bedrock:amazon.titan-embed-text-v1":{"credentials_profile_name": "default","region_name": "us-west-2"}}' --AiExtension.api_keys='{"OPENAI_API_KEY": "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"} +``` + ### Blocklisting providers This configuration allows for blocking specific providers in the settings panel. diff --git a/packages/jupyter-ai/jupyter_ai/tests/test_config_manager.py b/packages/jupyter-ai/jupyter_ai/tests/test_config_manager.py index c238fc448..eeddfff88 100644 --- a/packages/jupyter-ai/jupyter_ai/tests/test_config_manager.py +++ b/packages/jupyter-ai/jupyter_ai/tests/test_config_manager.py @@ -183,6 +183,44 @@ def test_init_with_allowlists(cm: ConfigManager, common_cm_kwargs): assert test_cm.lm_gid == None assert test_cm.em_gid == None +def test_init_with_default_values( + cm_with_defaults: ConfigManager, config_path: str, schema_path: str +): + """ + Test that the ConfigManager initializes with the expected default values. + + Args: + cm_with_defaults (ConfigManager): A ConfigManager instance with default values. + config_path (str): The path to the configuration file. + schema_path (str): The path to the schema file. + """ + config_response = cm_with_defaults.get_config() + #assert config response + assert config_response.model_provider_id == "bedrock-chat:anthropic.claude-v1" + assert config_response.embeddings_provider_id == "bedrock:amazon.titan-embed-text-v1" + assert config_response.api_keys == ["OPENAI_API_KEY"] + assert config_response.fields == {"bedrock-chat:anthropic.claude-v1":{"credentials_profile_name": "default","region_name": "us-west-2"}} + + del cm_with_defaults + + log = logging.getLogger() + lm_providers = get_lm_providers() + em_providers = get_em_providers() + cm_with_defaults_override =ConfigManager( + log=log, + lm_providers=lm_providers, + em_providers=em_providers, + config_path=config_path, + schema_path=schema_path, + restrictions={"allowed_providers": None, "blocked_providers": None}, + provider_defaults={"model_provider_id": "bedrock-chat:anthropic.claude-v2"}, + ) + + assert cm_with_defaults_override.get_config().model_provider_id == "bedrock-chat:anthropic.claude-v2" + + + + def test_property_access_on_default_config(cm: ConfigManager): """Asserts that the CM behaves well with an empty, default