|
| 1 | +For every LLM to be used in a project, there should be configuration data that is necessary for using the LLM. |
| 2 | +Configuration data is expected as a dictionary which contains the key `llms` associated with a list of per-LLM configurations |
| 3 | +and optionally the key `providers` associated with a dictionary mapping provider names to settings common to all LLMs of that |
| 4 | +provider. |
| 5 | + |
| 6 | +Here is an example configuration showing a subset of the settings: |
| 7 | +``` |
| 8 | +{ |
| 9 | + "llms" : [ |
| 10 | + { |
| 11 | + "api_key_env" : "OPENAI_KEY1", |
| 12 | + "llm" : "openai/gpt-4o", |
| 13 | + "temperature" : 0 |
| 14 | + }, |
| 15 | + { |
| 16 | + "llm" : "gemini/gemini-1.5-flash", |
| 17 | + "temperature" : 1, |
| 18 | + "alias": "gemini1" |
| 19 | + }, |
| 20 | + { |
| 21 | + "llm" : "gemini/gemini-1.5-flash", |
| 22 | + "temperature" : 0, |
| 23 | + "alias": "gemini2" |
| 24 | + } |
| 25 | + ], |
| 26 | + "providers" : { |
| 27 | + "gemini" : { |
| 28 | + "api_key_env" : "GEMINI_KEY1" |
| 29 | + } |
| 30 | + } |
| 31 | +} |
| 32 | +``` |
| 33 | + |
| 34 | +Each llm is identified by the provider name, e.g. "openai" or "gemini" followed by a slash, followed by the model name or id. Provider |
| 35 | +names must match the provider names known in the [litellm](https://docs.litellm.ai/docs/providers) package. |
| 36 | + |
| 37 | +Parameters specified for each of the providers in the `providers` section apply to every llm in the `llms` section unless the same |
| 38 | +parameter is also specified for the llm, in which case that value takes precedence. |
| 39 | + |
| 40 | +The following parameters are known and supported in the `llms` and/or `providers` sections: |
| 41 | + |
| 42 | +* `llm` (`llms` section only): specifies a specific model using the format `providername/modelid`. |
| 43 | +* `api_key`: the literal API key to use |
| 44 | +* `api_key_env`: the environment variable which contains the API key |
| 45 | +* `api_url`: the base URL to use for the model, e.g. for an ollama server. The URL may contain placeholders which will get replaced with |
| 46 | + the model name (`${model}`), or the user and password for basic authentication (`${user}`, `${password}`), e.g. |
| 47 | + `http://${user}:${password}@localhost:11434` |
| 48 | +* `user`, `password`: the user and password to use for basic authentication, this requires `api_url` to also be specified with the |
| 49 | + corresponding placeholders |
| 50 | +* `alias` (`llms` section only): an alias name for the model which will have to be used in the API. If no `alias` is specified, the name |
| 51 | + specified for `llm` is used. |
| 52 | +* `num_retries`: if present, can specify the number of retries to perform if an error occurs before giving up |
| 53 | +* `timeout`: if present, raise timeout error after that many seconds |
| 54 | + |
| 55 | +All other settings are passed as is to the model invocation function. Different providers or APIs may support different parameters, but |
| 56 | +most will support `temperature`, `max_tokens` and `top_p` |
| 57 | + |
| 58 | +IMPORTANT: the raw configuration as shown in the example above needs to get processed by the function `llms_wrapper.config.update_llm_config` |
| 59 | +in order to perform all the necessary substitutions! |
| 60 | + |
| 61 | +#### Other top-leve config entries |
| 62 | + |
| 63 | +Currently the following other top level configuration fields in addition to `llms` and `providers` are recognized: |
| 64 | + |
| 65 | +* `use_phoenix`: if present, should be the URL of a local phoenix endpoint or a list containing the endpoint URL and the project name |
| 66 | + |
| 67 | +## Configuration files |
| 68 | + |
| 69 | +The configuration as described above can be created programmatically or read in from some config file. |
| 70 | +The function `llms_wrapper.config.read_config_file` allows reading the configuration from files in any of the following |
| 71 | +formats: json, hsjson, yaml, toml. By default, reading the configuration that way will also perform the necessary substitutions by |
| 72 | +automatically invoking `llms_wrapper.config.update_llm_config` |
| 73 | + |
0 commit comments