Configure the Comet LLM SDK¶
When getting started with logging your prompt engineering workflows to CometLLM, you need to make sure to provide your Comet API key and also define the correct Comet LLM project settings. Both these goals are achieved by initializing the Comet SDK.
This page presents you with instructions on how to best initialize the Comet SDK, and an overview of all configuration parameters for initialization.
Set the API key¶
The recommended way to set the API key is by running comet_llm.init()
in your Python code without setting the API key beforehand:
1 2 3 |
|
When no API key is set in the environment, the .init()
method interactively prompts you for your API key and stores it for you in the .comet.config
configuration file. Once available, Comet directly accesses your API key from configuration file so you only need to input your API key once.
Note
You can also set the API key using one of the methods introduced in the Configure CometLLM logging section below.
Note that it is not recommended to pass the API key as an .init()
method argument because it is not safe to hardcode its value.
Configure CometLLM logging¶
Below we provide instructions and an example for each of the three different ways in which you can configure the comet_llm
Python SDK.
The provided examples all use the project_name
configuration parameter. For a comprehensive list of Comet configuration names—for both the config file and environment variables—, please refer to the Explore Comet LLM configuration options section below.
Note
Comet prioritizes setting configuration options in the following order:
- From
.init()
method arguments. - With Comet environment variables.
- From the
.comet.config
file in your current folder. - From the
.comet.config
file in yourHOME
directory.
So, a configuration parameter explicitly passed to code has top priority.
From the .comet.config file¶
The .comet.config
configuration file follows the format:
[section_name]
config_name=value
You can update directly the configuration file by adding each configuration option under the right section name. For example:
[comet]
project_name="llm-example"
With Comet environment variables¶
You can use environment variables to define Comet LLM configuration parameter.
Define them from terminal with your desired scope as follows:
export $COMET_PROJECT_NAME="llm-example"
1. Open one of .bashrc
, .bash_profile
, or .profile
configuration files depending on your set-up.
2. Add the following line to the file:
export COMET_PROJECT_NAME="llm-example"
3. Save and execute the file, e.g. with source ~/.bashrc
.
For more information and instructions, read more about setting environment variables in Python.
From .init()
method arguments¶
You can pass a subset of the configuration parameters as .init()
method arguments. For example:
1 2 3 4 |
|
Please refer to the comet_llm.init()
reference for a complete list of supported arguments.
Explore Comet LLM configuration options¶
The table below outlines all the available configuration environment variables for Comet LLM and their corresponding section<>attribute names in the .comet.config
file.
Comet Config Section<>Name | Environment Variable | Description |
---|---|---|
[comet] api_key | COMET_API_KEY | The API key used for logging data and using the Python API. |
[comet] workspace | COMET_WORKSPACE | Use this workspace when logging data. |
[comet] project_name | COMET_PROJECT_NAME | Use this project when logging data. |
[comet] url_override | COMET_URL_OVERRIDE | URL to upload data to, this needs to be updated for on-premise deployments. Defaults to https://www.comet.com/clientlib/ . |
In addition, the following configuration parameters are available only as environment variables:
Environment Variable | Description |
---|---|
COMET_INI | A path to another .comet.config file to take into account |
Warning
If configuration options are not explicitly set, Comet uses default values. Specifically, the default workspace corresponds to your username and the default project_name corresponds to "llm-general".