Config
Allow us to easily read from and write to roboduck's config file.
Roboduck creates a config file at ~/.roboduck/config.yaml
. You can also
change this path by setting the ROBODUCK_CONFIG_PATH environment variable
in a python script:
import os
os.environ["ROBODUCK_CONFIG_PATH"] = "/Users/path/to/custom/config.yaml"
or by adding this to your ~/.bashrc file:
export ROBODUCK_CONFIG_PATH=/Users/path/to/custom/config.yaml
The config currently supports only two fields:
-
openai_api_key
: See the Quickstart for setup help. -
model_name
(optional): Roboduck is configured to use gpt-4o-mini by default. This field lets you change that (e.g. to gpt-4). If present in the config file, this will take priority over any model_name field specified in a chat template (e.g. our default debug prompt template). You can view valid options withroboduck.available_models()
. You can still override the config default by manually passing a value into a function, e.g.duck(model_name='gpt-4-32k')
.
You can manually edit your config file or use a command like
roboduck.update_config(model_name='gpt-4')
. Passing in a value of None
(e.g. roboduck.update_config(model_name=None)
) will delete that field from
your config file.
Attributes
CONFIG_PATH = Path('~/.roboduck/config.yaml').expanduser()
module-attribute
CONFIG_PATH_ENV_VAR = 'ROBODUCK_CONFIG_PATH'
module-attribute
Functions
get_config_path()
Get the path to the roboduck config file. We use this instead of just referencing the variable in case the user sets a custom location.
Returns:
Type | Description |
---|---|
Path
|
The path to the roboduck config file (yaml), either the default path or the path specified by the user-set environment variable. |
Source code in lib/roboduck/config.py
52 53 54 55 56 57 58 59 60 61 62 |
|
update_config(**kwargs)
Update roboduck config file with settings that persist for future sessions.
Other fields may be configurable here in the future, but as of v1 this should really only be used to set openai_api_key and/or model_name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kwargs |
any
|
Available fields include:
- openai_api_key
- model_name: name like 'gpt-4o-mini' that controls what model
to use for completions. Model_name is resolved as follows:
1. kwargs explicitly passed in by user (e.g.
|
{}
|
Source code in lib/roboduck/config.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
|
load_config()
Load roboduck config.
Returns:
Type | Description |
---|---|
dict
|
|
Source code in lib/roboduck/config.py
105 106 107 108 109 110 111 112 113 114 115 116 |
|
apply_config_defaults(chat_kwargs, template_only)
Help resolve model_name in place. Recall we prioritize sources in this order:
- value a user specified explicitly, e.g. Chat(..., model_name='gpt-4').
- value specified in roboduck config file
- value specified in a prompt template (can be native to roboduck or user-defined)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
chat_kwargs |
dict
|
Kwargs to pass to our langchain.chat.Chat constructor. May include a model_name str field. |
required |
template_only |
bool
|
Specifies whether chat_kwargs are passed in directly from a prompt template (template_only=True) or include kwargs that a user passed in explicitly (template_only=False). |
required |
Returns:
Type | Description |
---|---|
None
|
Update happens in place (if at all). |
Source code in lib/roboduck/config.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
|
set_openai_api_key(key=None, strict=False, update_config_=False)
Set OPENAI_API_KEY environment variable for langchain.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
str or None
|
Optionally pass in openai api key (str). If not provided, we check the
users's roboduck config and try to load a key (using the
"openai_api_key" field). If |
None
|
strict |
bool
|
Determines what happens when key is None and the roboduck config does not exist. Strict=True raises a runtime error, False just warns user. |
False
|
update_config_ |
bool
|
If True, we update the roboduck yaml config file with the provided api key. |
False
|
Source code in lib/roboduck/config.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
|