Improve readability in oai_openai_utils.ipynb (#365)

This commit is contained in:
Shruti Patel 2023-10-22 00:20:04 -04:00 committed by GitHub
parent c2e0ddf667
commit da88d6379c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 12 deletions

View File

@ -6,7 +6,7 @@
"source": [
"# In-depth Guide to OpenAI Utility Functions\n",
"\n",
"Managing API configurations can be tricky, especially when dealing with multiple models and API versions. The provided utility functions assist users in managing these configurations effectively. Ensure your API keys and other sensitive data are stored securely. For local development, you might store keys in `.txt` or `.env` files or environment variables. Never expose your API keys publicly. If you insist on having your key files stored locally on your repo (you shouldn't), make sure the key file path is added to the `.gitignore` file.\n",
"Managing API configurations can be tricky, especially when dealing with multiple models and API versions. The provided utility functions assist users in managing these configurations effectively. Ensure your API keys and other sensitive data are stored securely. You might store keys in `.txt` or `.env` files or environment variables for local development. Never expose your API keys publicly. If you insist on storing your key files locally on your repo (you shouldn't), ensure the key file path is added to the `.gitignore` file.\n",
"\n",
"#### Steps:\n",
"1. Obtain API keys from OpenAI and optionally from Azure OpenAI (or other provider).\n",
@ -32,7 +32,7 @@
"metadata": {},
"source": [
"#### What is a `config_list`?\n",
"When instantiating an assistant, such as the example below, you see that it is being passed a `config_list`. This is used to tell the `AssistantAgent` which models or configurations it has access to:\n",
"When instantiating an assistant, such as the example below, it is passed a `config_list`. This is used to tell the `AssistantAgent` which models or configurations it has access to:\n",
"```python\n",
"\n",
"assistant = AssistantAgent(\n",
@ -51,7 +51,7 @@
"- Generate creative content (using gpt-4).\n",
"- Answer general queries (using gpt-3.5-turbo).\n",
"\n",
"Different tasks may require different models, and the `config_list` aids in dynamically selecting the appropriate model configuration, managing API keys, endpoints, and versions for efficient operation of the intelligent assistant. In summary, the `config_list` help the agents work efficiently, reliably, and optimally by managing various configurations and interactions with the OpenAI API - enhancing the adaptability and functionality of the agents."
"Different tasks may require different models, and the `config_list` aids in dynamically selecting the appropriate model configuration, managing API keys, endpoints, and versions for efficient operation of the intelligent assistant. In summary, the `config_list` helps the agents work efficiently, reliably, and optimally by managing various configurations and interactions with the OpenAI API - enhancing the adaptability and functionality of the agents."
]
},
{
@ -108,7 +108,7 @@
"source": [
"## config_list_openai_aoai\n",
"\n",
"This method creates a list of configurations using Azure OpenAI endpoints and OpenAI endpoints. It tries to extract API keys and bases either from environment variables or from local text files.\n",
"This method creates a list of configurations using Azure OpenAI endpoints and OpenAI endpoints. It tries to extract API keys and bases from environment variables or local text files.\n",
"\n",
"Steps:\n",
"- Store OpenAI API key in:\n",
@ -151,7 +151,7 @@
" 2. Alternatively, save configurations in a local JSON file named `OAI_CONFIG_LIST.json`\n",
" 3. Add `OAI_CONFIG_LIST` to your `.gitignore` file on your local repository.\n",
"\n",
"Your JSON struction should look something like this:\n",
"Your JSON structure should look something like this:\n",
"\n",
"```json\n",
"# OAI_CONFIG_LIST file example\n",
@ -195,7 +195,7 @@
"\n",
"The z parameter in `autogen.config_list_from_json` function is used to selectively filter the configurations loaded from the environment variable or JSON file based on specified criteria. It allows you to define criteria to select only those configurations that match the defined conditions.\n",
"\n",
"lets say you want to config an assistant agent to only LLM type. Take the below example: even though we have \"gpt-3.5-turbo\" and \"gpt-4\" in our `OAI_CONFIG_LIST`, this agent would only be configured to use"
"let's say you want to configure an assistant agent to only LLM type. Take the below example: even though we have \"gpt-3.5-turbo\" and \"gpt-4\" in our `OAI_CONFIG_LIST`, this agent would only be configured to use"
]
},
{
@ -249,9 +249,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"With the `OAI_CONFIG_LIST` we set earlier, there isn't much to filter on. But when the complexity of a project grows and the and you're managing multiple models for various purposes, you can see how `filter_dict` can be useful. \n",
"With the `OAI_CONFIG_LIST` we set earlier, there isn't much to filter on. But when the complexity of a project grows and you're managing multiple models for various purposes, you can see how `filter_dict` can be useful. \n",
"\n",
"A more complex filtering criteria could be the following: Assuming we have a `OAI_CONFIG_LIST` several models used to create various agents - Lets say we want to load configurations for `gpt-4` using API version `\"2023-03-01-preview\"` and we want the `api_type` to be `aoai`, we can set up `filter_dict` as follows:"
"A more complex filtering criteria could be the following: Assuming we have an `OAI_CONFIG_LIST` several models used to create various agents - Let's say we want to load configurations for `gpt-4` using API version `\"2023-03-01-preview\"` and we want the `api_type` to be `aoai`, we can set up `filter_dict` as follows:"
]
},
{
@ -310,9 +310,9 @@
"source": [
"## config_list_from_dotenv\n",
"\n",
"If you are interest in keeping all of your keys in a single location like a `.env` file rather than using a configuration specifically for OpenAI, you can use `config_list_from_dotenv`. The allows you to conveniently create a config list without creating a complex `OAI_CONFIG_LIST` file.\n",
"If you are interested in keeping all of your keys in a single location like a `.env` file rather than using a configuration specifically for OpenAI, you can use `config_list_from_dotenv`. This allows you to conveniently create a config list without creating a complex `OAI_CONFIG_LIST` file.\n",
"\n",
"The `model_api_key_map` parameter is a dictionary that maps model names to the environment variable names in the `.env` file where their respective API keys are stored. It allows the code to know which API key to use for each model. \n",
"The `model_api_key_map` parameter is a dictionary that maps model names to the environment variable names in the `.env` file where their respective API keys are stored. It lets the code know which API key to use for each model. \n",
"\n",
"If not provided, it defaults to using `OPENAI_API_KEY` for `gpt-4` and `OPENAI_API_KEY` for `gpt-3.5-turbo`.\n",
"\n",
@ -354,7 +354,7 @@
"import autogen\n",
"\n",
"config_list = autogen.config_list_from_dotenv(\n",
" dotenv_file_path='.env', # If None the function will try find in the working directory\n",
" dotenv_file_path='.env', # If None the function will try to find in the working directory\n",
" filter_dict={\n",
" \"model\": {\n",
" \"gpt-4\",\n",
@ -386,7 +386,7 @@
"source": [
"# gpt-3.5-turbo will default to OPENAI_API_KEY\n",
"config_list = autogen.config_list_from_dotenv(\n",
" dotenv_file_path='.env', # If None the function will try find in the working directory\n",
" dotenv_file_path='.env', # If None the function will try to find in the working directory\n",
" model_api_key_map={\n",
" \"gpt-4\": \"ANOTHER_API_KEY\", # String or dict accepted\n",
" },\n",