Skip to content

Commit acfd36f

Browse files
taozhiwangyou-n-g
andauthored
docs: Config Docs Update (microsoft#148)
* Add a table & factor debug * Congfig setting * Update env example and configuration list. Also change api priority * Add a TODO for the rst * CI: shorter line * Update docs/installation_and_configuration.rst * Update docs/installation_and_configuration.rst * Update links & standard config * Add TODO * Fix bug * Update rdagent/oai/llm_utils.py --------- Co-authored-by: you-n-g <you-n-g@users.noreply.github.com>
1 parent b5ea040 commit acfd36f

File tree

6 files changed

+183
-91
lines changed

6 files changed

+183
-91
lines changed

.env.example

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
1+
"""
2+
This file is a template for the .env file.
3+
4+
Please copy this file to .env and fill in the values.
5+
6+
For more information about configuration options, please refer to the documentation
7+
8+
"""
9+
110
# Global configs:
11+
USE_AZURE=False
12+
USE_AZURE_TOKEN_PROVIDER=False
213
MAX_RETRY=10
314
RETRY_WAIT_SECONDS=20
415

5-
# api key
6-
OPENAI_API_KEY=your_api_key
16+
# LLM API Setting:
17+
OPENAI_API_KEY=<your_api_key>
18+
CHAT_MODEL=gpt-4-turbo
19+
CHAT_MAX_TOKENS=3000
20+
CHAT_TEMPERATURE=0.7
21+
# CHAT_AZURE_API_BASE=<for_Azure_user>
22+
# CHAT_AZURE_API_VERSION=<for_Azure_user>
723

8-
# embedding model configs:
924
EMBEDDING_MODEL=text-embedding-3-small
25+
# EMBEDDING_AZURE_API_BASE=<for_Azure_user>
26+
# EMBEDDING_AZURE_API_VERSION=<for_Azure_user>
1027

11-
# chat model configs:
12-
CHAT_MODEL=your_model_version
13-
CHAT_MAX_TOKENS=3000
14-
CHAT_TEMPERATURE=0.7
15-
CHAT_STREAM=True
28+
# Cache Setting (Optional):
29+
30+
# Senario Configs:

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Welcome to RDAgent's documentation!
1111
:caption: Doctree:
1212

1313
demo_and_introduction
14-
installation
14+
installation_and_configuration
1515
scenarios_and_quickstart
1616
project_framework_introduction
1717
development

docs/installation.rst

Lines changed: 0 additions & 72 deletions
This file was deleted.
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
==============================
2+
Installation and Configuration
3+
==============================
4+
5+
Installation
6+
============
7+
8+
For different scenarios
9+
- for purely users:
10+
- for dev users: `See development <development.html>`_
11+
12+
Configuration
13+
=============
14+
15+
To run the application, please create a `.env` file in the root directory of the project and add environment variables according to your requirements.
16+
17+
The standard configuration options for the user using the OpenAI API are provided in the `.env.example` file.
18+
19+
Here are some other configuration options that you can use:
20+
21+
OpenAI API
22+
------------
23+
24+
Here is a standard configuration for the user using the OpenAI API.
25+
26+
.. code-block:: Properties
27+
28+
OPENAI_API_KEY=<your_api_key>
29+
EMBEDDING_MODEL=text-embedding-3-small
30+
CHAT_MODEL=gpt-4-turbo
31+
32+
Azure OpenAI
33+
------------
34+
35+
The following environment variables are standard configuration options for the user using the OpenAI API.
36+
37+
.. code-block:: Properties
38+
39+
USE_AZURE=True
40+
41+
OPENAI_API_KEY=<replace_with_your_openai_api_key>
42+
43+
EMBEDDING_MODEL=text-embedding-3-small
44+
EMBEDDING_AZURE_API_BASE= # The base URL for the Azure OpenAI API.
45+
EMBEDDING_AZURE_API_VERSION = # The version of the Azure OpenAI API.
46+
47+
CHAT_MODEL=gpt-4-turbo
48+
CHAT_AZURE_API_VERSION = # The version of the Azure OpenAI API.
49+
50+
Use Azure Token Provider
51+
------------------------
52+
53+
If you are using the Azure token provider, you need to set the `USE_AZURE_TOKEN_PROVIDER` environment variable to `True`. then
54+
use the environment variables provided in the `Azure Configuration section <installation_and_configuration.html#azure-openai>`_.
55+
56+
57+
☁️ Azure Configuration
58+
- Install Azure CLI:
59+
60+
```sh
61+
curl -L https://aka.ms/InstallAzureCli | bash
62+
```
63+
64+
- Log in to Azure:
65+
66+
```sh
67+
az login --use-device-code
68+
```
69+
70+
- `exit` and re-login to your environment (this step may not be necessary).
71+
72+
73+
Configuration List
74+
------------------
75+
76+
.. TODO: use `autodoc-pydantic` .
77+
78+
- OpenAI API Setting
79+
80+
+-----------------------------+--------------------------------------------------+-------------------------+
81+
| Configuration Option | Meaning | Default Value |
82+
+=============================+==================================================+=========================+
83+
| OPENAI_API_KEY | API key for both chat and embedding models | None |
84+
+-----------------------------+--------------------------------------------------+-------------------------+
85+
| EMBEDDING_OPENAI_API_KEY | Use a different API key for embedding model | None |
86+
+-----------------------------+--------------------------------------------------+-------------------------+
87+
| CHAT_OPENAI_API_KEY | Set to use a different API key for chat model | None |
88+
+-----------------------------+--------------------------------------------------+-------------------------+
89+
| EMBEDDING_MODEL | Name of the embedding model | text-embedding-3-small |
90+
+-----------------------------+--------------------------------------------------+-------------------------+
91+
| CHAT_MODEL | Name of the chat model | gpt-4-turbo |
92+
+-----------------------------+--------------------------------------------------+-------------------------+
93+
| EMBEDDING_AZURE_API_BASE | Base URL for the Azure OpenAI API | None |
94+
+-----------------------------+--------------------------------------------------+-------------------------+
95+
| EMBEDDING_AZURE_API_VERSION | Version of the Azure OpenAI API | None |
96+
+-----------------------------+--------------------------------------------------+-------------------------+
97+
| CHAT_AZURE_API_BASE | Base URL for the Azure OpenAI API | None |
98+
+-----------------------------+--------------------------------------------------+-------------------------+
99+
| CHAT_AZURE_API_VERSION | Version of the Azure OpenAI API | None |
100+
+-----------------------------+--------------------------------------------------+-------------------------+
101+
| USE_AZURE | True if you are using Azure OpenAI | False |
102+
+-----------------------------+--------------------------------------------------+-------------------------+
103+
| USE_AZURE_TOKEN_PROVIDER | True if you are using a Azure Token Provider | False |
104+
+-----------------------------+--------------------------------------------------+-------------------------+
105+
106+
- Globol Setting
107+
108+
+-----------------------------+--------------------------------------------------+-------------------------+
109+
| Configuration Option | Meaning | Default Value |
110+
+=============================+==================================================+=========================+
111+
| max_retry | Maximum number of times to retry | 10 |
112+
+-----------------------------+--------------------------------------------------+-------------------------+
113+
| retry_wait_seconds | Number of seconds to wait before retrying | 1 |
114+
+-----------------------------+--------------------------------------------------+-------------------------+
115+
+ log_trace_path | Path to log trace file | None |
116+
+-----------------------------+--------------------------------------------------+-------------------------+
117+
+ log_llm_chat_content | Flag to indicate if chat content is logged | True |
118+
+-----------------------------+--------------------------------------------------+-------------------------+
119+
120+
121+
- Cache Setting
122+
123+
.. TODO: update Meaning for caches
124+
125+
+------------------------------+--------------------------------------------------+-------------------------+
126+
| Configuration Option | Meaning | Default Value |
127+
+==============================+==================================================+=========================+
128+
| dump_chat_cache | Flag to indicate if chat cache is dumped | False |
129+
+------------------------------+--------------------------------------------------+-------------------------+
130+
| dump_embedding_cache | Flag to indicate if embedding cache is dumped | False |
131+
+------------------------------+--------------------------------------------------+-------------------------+
132+
| use_chat_cache | Flag to indicate if chat cache is used | False |
133+
+------------------------------+--------------------------------------------------+-------------------------+
134+
| use_embedding_cache | Flag to indicate if embedding cache is used | False |
135+
+------------------------------+--------------------------------------------------+-------------------------+
136+
| prompt_cache_path | Path to prompt cache | ./prompt_cache.db |
137+
+------------------------------+--------------------------------------------------+-------------------------+
138+
| session_cache_folder_location| Path to session cache | ./session_cache_folder |
139+
+------------------------------+--------------------------------------------------+-------------------------+
140+
| max_past_message_include | Maximum number of past messages to include | 10 |
141+
+------------------------------+--------------------------------------------------+-------------------------+
142+

rdagent/core/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class RDAgentSettings(BaseSettings):
2020
log_trace_path: str | None = None
2121
log_llm_chat_content: bool = True
2222

23-
use_azure: bool = True
23+
use_azure: bool = False
2424
use_azure_token_provider: bool = False
2525
managed_identity_client_id: str | None = None
2626
max_retry: int = 10
@@ -48,7 +48,7 @@ class RDAgentSettings(BaseSettings):
4848
chat_token_limit: int = (
4949
100000 # 100000 is the maximum limit of gpt4, which might increase in the future version of gpt
5050
)
51-
default_system_prompt: str = "You are an AI assistant who helps to answer user's questions about finance."
51+
default_system_prompt: str = "You are an AI assistant who helps to answer user's questions."
5252

5353
# Embedding configs
5454
embedding_openai_api_key: str = ""

rdagent/oai/llm_utils.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -298,14 +298,21 @@ def __init__( # noqa: C901, PLR0912, PLR0915
298298
self.use_azure_token_provider = self.cfg.use_azure_token_provider
299299
self.managed_identity_client_id = self.cfg.managed_identity_client_id
300300

301-
if self.cfg.openai_api_key:
302-
self.chat_api_key = self.cfg.openai_api_key
303-
self.embedding_api_key = self.cfg.openai_api_key
304-
else:
305-
self.chat_api_key = self.cfg.chat_openai_api_key if chat_api_key is None else chat_api_key
306-
self.embedding_api_key = (
307-
self.cfg.embedding_openai_api_key if embedding_api_key is None else embedding_api_key
308-
)
301+
# Priority: chat_api_key/embedding_api_key > openai_api_key > os.environ.get("OPENAI_API_KEY")
302+
# TODO: Simplify the key design. Consider Pandatic's field alias & priority.
303+
self.chat_api_key = (
304+
chat_api_key
305+
or self.cfg.chat_openai_api_key
306+
or self.cfg.openai_api_key
307+
or os.environ.get("OPENAI_API_KEY")
308+
)
309+
self.embedding_api_key = (
310+
embedding_api_key
311+
or self.cfg.embedding_openai_api_key
312+
or self.cfg.openai_api_key
313+
or os.environ.get("OPENAI_API_KEY")
314+
)
315+
309316
self.chat_model = self.cfg.chat_model if chat_model is None else chat_model
310317
self.encoder = tiktoken.encoding_for_model(self.chat_model)
311318
self.chat_api_base = self.cfg.chat_azure_api_base if chat_api_base is None else chat_api_base

0 commit comments

Comments
 (0)