Setup Guide¶
You need to set up API keys or your own LLM backends to interact with LLMs. Besides, APPL has many configurations that you can customize to fit your needs.
Setup Environment Variables¶
Using Dotenv (Recommended)¶
We recommended you to store all your environment variables, including API keys, in a .env
file in the root directory of your project (or other directories, see Priority of Configurations for more details). Based on the python-dotenv
package, APPL will automatically load the environment variables into the current environment.
Remember to setup your .gitignore file
Make sure to add .env
to your .gitignore
file to prevent it from being committed to your repository.
For example, you can create a .env
file with the following content to specify your OpenAI API key:
Export or Shell Configuration¶
Alterantively, you can export the environment variables directly in your terminal, or add them to your shell configuration file (e.g., .bashrc
, .zshrc
). For example:
Setup APPL Configuration¶
Default Configs¶
default_configs.yaml
contains the default configurations for APPL.
You should setup your own default server.
The default server (currently gpt-4o-mini
) set in APPL could be outdated and changed in the future. We recommend you to specify your own default model in the appl.yaml
file.
Override Configs¶
You can override these configurations by creating a appl.yaml
file in the root directory of your project (or other directories, see Priority of Configurations for more details). A typical usage is to override the servers
configuration to specify the LLM servers you want to use, as shown in the following example appl.yaml
file.
How configurations are updated?
The configurations are implemented as a nested dictionary in Python using addict.Dict
. The update is recursively applied according to this link.
Other file formats like JSON or TOML are also supported.
You can also use other file formats, such as JSON (appl.json
) or TOML (appl.toml
), to specify the configurations. We recommend using YAML for better readability.
Setup LLMs¶
You can configure the LLM servers in the appl.yaml
file by overriding the servers
configuration as shown in the example above.
LLM APIs¶
APPL uses litellm to support various LLM APIs using the OpenAI format. Please refer to the list of supported providers.
You need to setup the corresponding API keys for the LLM backend you want to use in environment variables and specify corresponding configurations in appl.yaml
.
An example of .env
file that matches the appl.yaml
example above to support using APIs from OpenAI, Anthropic, Azure, Moonshot, and DeepSeek is as follows:
OPENAI_API_KEY=<your openai api key>
# Anthropic environment variables
ANTHROPIC_API_KEY=<your anthropic api key>
# Azure environment variables
AZURE_API_KEY=<your azure api key>
AZURE_API_BASE=<the base url of the API>
AZURE_API_VERSION=<the version of the API>
# Moonshot environment variables
MOONSHOT_API_KEY=<your moonshot api key>
# DeepSeek environment variables
DEEPSEEK_API_KEY=<your deepseek api key>
Local LLMs¶
We recommend using SGlang Runtime (SRT) to serve the local LLMs, which is fast and supports the regex constraints. You can install it following the official guide.
To serve local LLMs, please following SGLang's official guide.
Using Llama-2-7b-chat-hf as an example:
You may also use vLLM to host a local server, and the usage in APPL is similar to SRT.
Setup Tracing¶
APPL Tracing¶
You can enable APPL tracing by overriding the tracing
configuration to true
in appl.yaml
.
To resume from a previous trace, you can specify the APPL_RESUME_TRACE
environment variable with the path to the trace file. See more details in the tutorial.
LangSmith¶
To enable LangSmith tracing, you need to to obtain your API key from LangSmith and add the following environment variables to your .env
file:
LANGCHAIN_TRACING_V2=true
LANGCHAIN_API_KEY=<your api key>
# [Optional] specify the project name
# LANGCHAIN_PROJECT=<your project name>
Priority of Configurations¶
Let's say you are running a script (main.py
) in the project
directory which calls appl.init
, and you have the following directory structure:
Starting from the directory containing the file calling appl.init
(in this case, main.py
), APPL will walk up the directory tree to find custom configurations. The configurations in the files closer to the file calling appl.init
will have higher priority.
In this case, the configurations in appl.yaml
will be loaded first, followed by the ones in project/appl.yaml
with overriding the previous ones. The environment variables in .env
will be loaded first, followed by the ones in project/.env
with overriding the previous ones.
Difference between .env
and appl.yaml
.env
is used to store environment variables, including API keys. The contents should not be committed to the repository as they may contain sensitive information.appl.yaml
is used to store APPL configurations, such as LLM servers and tracing settings. When used in a project, it should not contain sensitive information. The settings in general should be committed to the repository so that others can reproduce the results.