Skip to content

Commit

Permalink
Update env example and configuration list.
Browse files Browse the repository at this point in the history
Also change api priority
  • Loading branch information
taozhiwang committed Aug 2, 2024
1 parent 213d9ec commit 47407ae
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 44 deletions.
31 changes: 23 additions & 8 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
"""
This file is a template for the .env file.

Please copy this file to .env and fill in the values.

For more information about configuration options, please refer to the documentation

"""

# Global configs:
USE_AZURE=False
USE_AZURE_TOKEN_PROVIDER=False
MAX_RETRY=10
RETRY_WAIT_SECONDS=20

# api key
OPENAI_API_KEY=your_api_key
# LLM API Setting:
OPENAI_API_KEY=<your_api_key>
CHAT_MODEL=gpt-4-turbo
CHAT_MAX_TOKENS=3000
CHAT_TEMPERATURE=0.7
# CHAT_AZURE_API_BASE=<for_Azure_user>
# CHAT_AZURE_API_VERSION=<for_Azure_user>

# embedding model configs:
EMBEDDING_MODEL=text-embedding-3-small
# EMBEDDING_AZURE_API_BASE=<for_Azure_user>
# EMBEDDING_AZURE_API_VERSION=<for_Azure_user>

# chat model configs:
CHAT_MODEL=your_model_version
CHAT_MAX_TOKENS=3000
CHAT_TEMPERATURE=0.7
CHAT_STREAM=True
# Cache Setting (Optional):

# Senario Configs:
80 changes: 58 additions & 22 deletions docs/installation_and_configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Here are some other configuration options that you can use:
OpenAI API
------------

You can use different OpenAI API keys for embedding model and chat model.
You can Use `OPENAI_API_KEY` to set the API key for the OpenAI API, or use different API keys for embedding model and chat model.

.. code-block:: Properties
Expand Down Expand Up @@ -53,52 +53,88 @@ Use Azure Token Provider
------------------------

If you are using the Azure token provider, you need to set the `USE_AZURE_TOKEN_PROVIDER` environment variable to `True`. then
use the environment variables provided in the `Azure Configuration section <installation.html#azure-openai>`_.
use the environment variables provided in the `Azure Configuration section <installation_and_configuration.html#azure-openai>`_.


☁️ Azure Configuration
- Install Azure CLI:

```sh
curl -L https://aka.ms/InstallAzureCli | bash
```

- Log in to Azure:

```sh
az login --use-device-code
```

- `exit` and re-login to your environment (this step may not be necessary).


Configuration List
------------------

- LLM API Setting
- OpenAI API Setting

+-----------------------------+--------------------------------------------------+-------------------------+
| Configuration Option | Meaning | Default Value |
+=============================+==================================================+=========================+
| OPENAI_API_KEY | API key for the OpenAI API | None |
| OPENAI_API_KEY | API key for both chat and embedding models | None |
+-----------------------------+--------------------------------------------------+-------------------------+
| EMBEDDING_OPENAI_API_KEY | API key for the embedding model | None |
| EMBEDDING_OPENAI_API_KEY | Set to use a different API key for embedding model | None |
+-----------------------------+--------------------------------------------------+-------------------------+
| CHAT_OPENAI_API_KEY | API key for the chat model | None |
| CHAT_OPENAI_API_KEY | Set to use a different API key for chat model | None |
+-----------------------------+--------------------------------------------------+-------------------------+
| EMBEDDING_MODEL | Name of the embedding model | text-embedding-3-small |
+-----------------------------+--------------------------------------------------+-------------------------+
| CHAT_MODEL | Name of the chat model | gpt-4-turbo |
+-----------------------------+--------------------------------------------------+-------------------------+
| USE_AZURE | Flag to indicate if Azure OpenAI is being used | False |
+-----------------------------+--------------------------------------------------+-------------------------+
| EMBEDDING_AZURE_API_BASE | Base URL for the Azure OpenAI API | None |
+-----------------------------+--------------------------------------------------+-------------------------+
| EMBEDDING_AZURE_API_VERSION | Version of the Azure OpenAI API | None |
+-----------------------------+--------------------------------------------------+-------------------------+
| CHAT_AZURE_API_BASE | Base URL for the Azure OpenAI API | None |
+-----------------------------+--------------------------------------------------+-------------------------+
| CHAT_AZURE_API_VERSION | Version of the Azure OpenAI API | None |
+-----------------------------+--------------------------------------------------+-------------------------+
| USE_AZURE_TOKEN_PROVIDER | Flag to indicate if Azure token provider is used | False |
| USE_AZURE | True if you are using Azure OpenAI | False |
+-----------------------------+--------------------------------------------------+-------------------------+
| USE_AZURE_TOKEN_PROVIDER | True if you are using a Azure Token Provider | False |
+-----------------------------+--------------------------------------------------+-------------------------+

- Globol Setting

+-----------------------------+--------------------------------------------------+-------------------------+
| Configuration Option | Meaning | Default Value |
+=============================+==================================================+=========================+
| max_retry | Maximum number of times to retry | 10 |
+-----------------------------+--------------------------------------------------+-------------------------+
| retry_wait_seconds | Number of seconds to wait before retrying | 1 |
+-----------------------------+--------------------------------------------------+-------------------------+
+ log_trace_path | Path to log trace file | None |
+-----------------------------+--------------------------------------------------+-------------------------+
+ log_llm_chat_content | Flag to indicate if chat content is logged | True |
+-----------------------------+--------------------------------------------------+-------------------------+

☁️ Azure Configuration
- Install Azure CLI:

```sh
curl -L https://aka.ms/InstallAzureCli | bash
```

- Log in to Azure:

```sh
az login --use-device-code
```

- `exit` and re-login to your environment (this step may not be necessary).
- Cache Setting

+------------------------------+--------------------------------------------------+-------------------------+
| Configuration Option | Meaning | Default Value |
+==============================+==================================================+=========================+
| dump_chat_cache | Flag to indicate if chat cache is dumped | False |
+------------------------------+--------------------------------------------------+-------------------------+
| dump_embedding_cache | Flag to indicate if embedding cache is dumped | False |
+------------------------------+--------------------------------------------------+-------------------------+
| use_chat_cache | Flag to indicate if chat cache is used | False |
+------------------------------+--------------------------------------------------+-------------------------+
| use_embedding_cache | Flag to indicate if embedding cache is used | False |
+------------------------------+--------------------------------------------------+-------------------------+
| prompt_cache_path | Path to prompt cache | ./prompt_cache.db |
+------------------------------+--------------------------------------------------+-------------------------+
| session_cache_folder_location| Path to session cache | ./session_cache_folder |
+------------------------------+--------------------------------------------------+-------------------------+
| max_past_message_include | Maximum number of past messages to include | 10 |
+------------------------------+--------------------------------------------------+-------------------------+

2 changes: 1 addition & 1 deletion rdagent/core/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class RDAgentSettings(BaseSettings):
chat_token_limit: int = (
100000 # 100000 is the maximum limit of gpt4, which might increase in the future version of gpt
)
default_system_prompt: str = "You are an AI assistant who helps to answer user's questions about finance."
default_system_prompt: str = "You are an AI assistant who helps to answer user's questions."

# Embedding configs
embedding_openai_api_key: str = ""
Expand Down
17 changes: 4 additions & 13 deletions rdagent/oai/llm_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,19 +298,10 @@ def __init__( # noqa: C901, PLR0912, PLR0915
self.use_azure_token_provider = self.cfg.use_azure_token_provider
self.managed_identity_client_id = self.cfg.managed_identity_client_id

# Priority: openai_api_key > chat_api_key/embedding_api_key > os.environ.get("OPENAI_API_KEY")
if self.cfg.openai_api_key:
self.chat_api_key = self.cfg.openai_api_key
self.embedding_api_key = self.cfg.openai_api_key
else:
self.chat_api_key = self.cfg.chat_openai_api_key if chat_api_key is None else chat_api_key
self.embedding_api_key = (
self.cfg.embedding_openai_api_key if embedding_api_key is None else embedding_api_key
)
if self.chat_api_key is None:
self.chat_api_key = os.environ.get("OPENAI_API_KEY")
if self.embedding_api_key is None:
self.embedding_api_key = os.environ.get("OPENAI_API_KEY")
# Priority: chat_api_key/embedding_api_key > openai_api_key > os.environ.get("OPENAI_API_KEY")
self.chat_api_key = chat_api_key or self.cfg.chat_openai_api_key or self.cfg.openai_api_key or os.environ.get("OPENAI_API_KEY")
self.embedding_api_key = embedding_api_key or self.cfg.embedding_openai_api_key or self.cfg.openai_api_key or os.environ.get("OPENAI_API_KEY")

self.chat_model = self.cfg.chat_model if chat_model is None else chat_model
self.encoder = tiktoken.encoding_for_model(self.chat_model)
self.chat_api_base = self.cfg.chat_azure_api_base if chat_api_base is None else chat_api_base
Expand Down

0 comments on commit 47407ae

Please sign in to comment.