You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

FAQ.md 4.5 kB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. # Frequently Asked Questions
  2. ## Set your API endpoints
  3. There are multiple ways to construct a list of configurations for LLM inference.
  4. ### Option 1: Load a list of endpoints from json
  5. The [`config_list_from_json`](/docs/reference/oai/openai_utils#config_list_from_json) function loads a list of configurations from an environment variable or a json file.
  6. For example,
  7. ```python
  8. import autogen
  9. config_list = autogen.config_list_from_json(
  10. "OAI_CONFIG_LIST",
  11. file_location=".",
  12. filter_dict={
  13. "model": {
  14. "gpt-4",
  15. "gpt-3.5-turbo",
  16. }
  17. }
  18. )
  19. ```
  20. It first looks for environment variable "OAI_CONFIG_LIST" which needs to be a valid json string. If that variable is not found, it then looks for a json file named "OAI_CONFIG_LIST" under the specified `file_location`. It then filters the configs by models (you can filter by other keys as well).
  21. The `OAI_CONFIG_LIST` var or file content looks like the following:
  22. ```json
  23. [
  24. {
  25. "model": "gpt-4",
  26. "api_key": "<your OpenAI API key here>"
  27. },
  28. {
  29. "model": "gpt-4",
  30. "api_key": "<your Azure OpenAI API key here>",
  31. "api_base": "<your Azure OpenAI API base here>",
  32. "api_type": "azure",
  33. "api_version": "2023-07-01-preview"
  34. },
  35. {
  36. "model": "gpt-3.5-turbo",
  37. "api_key": "<your Azure OpenAI API key here>",
  38. "api_base": "<your Azure OpenAI API base here>",
  39. "api_type": "azure",
  40. "api_version": "2023-07-01-preview"
  41. }
  42. ]
  43. ```
  44. ### Option 2: Construct a list of endpoints for OpenAI or Azure OpenAI
  45. The [`config_list_from_models`](/docs/reference/oai/openai_utils#config_list_from_models) function tries to create a list of configurations using Azure OpenAI endpoints and OpenAI endpoints for the provided list of models. It assumes the api keys and api bases are stored in the corresponding environment variables or local txt files:
  46. - OpenAI API key: os.environ["OPENAI_API_KEY"] or `openai_api_key_file="key_openai.txt"`.
  47. - Azure OpenAI API key: os.environ["AZURE_OPENAI_API_KEY"] or `aoai_api_key_file="key_aoai.txt"`. Multiple keys can be stored, one per line.
  48. - Azure OpenAI API base: os.environ["AZURE_OPENAI_API_BASE"] or `aoai_api_base_file="base_aoai.txt"`. Multiple bases can be stored, one per line.
  49. It's OK to have only the OpenAI API key, or only the Azure OpenAI API key + base.
  50. ```python
  51. import autogen
  52. config_list = autogen.config_list_from_models(model_list=["gpt-4", "gpt-3.5-turbo", "gpt-3.5-turbo-16k"])
  53. ```
  54. The config list looks like the following, if only OpenAI API key is available:
  55. ```python
  56. config_list = [
  57. {
  58. 'model': 'gpt-4',
  59. 'api_key': '<your OpenAI API key here>',
  60. }, # OpenAI API endpoint for gpt-4
  61. {
  62. 'model': 'gpt-3.5-turbo',
  63. 'api_key': '<your OpenAI API key here>',
  64. }, # OpenAI API endpoint for gpt-3.5-turbo
  65. {
  66. 'model': 'gpt-3.5-turbo-16k',
  67. 'api_key': '<your OpenAI API key here>',
  68. }, # OpenAI API endpoint for gpt-3.5-turbo-16k
  69. ]
  70. ```
  71. ### Use the constructed configuration list in agents
  72. Make sure the "config_list" is included in the `llm_config` in the constructor of the LLM-based agent. For example,
  73. ```python
  74. assistant = autogen.AssistantAgent(
  75. name="assistant",
  76. llm_config={"config_list": config_list}
  77. )
  78. ```
  79. The `llm_config` is used in the [`create`](/docs/reference/oai/completion#create) function for LLM inference.
  80. When `llm_config` is not provided, the agent will rely on other openai settings such as `openai.api_key` or the environment variable `OPENAI_API_KEY`, which can also work when you'd like to use a single endpoint.
  81. You can also explicitly specify that by:
  82. ```python
  83. assistant = autogen.AssistantAgent(name="assistant", llm_config={"api_key": ...})
  84. ```
  85. ## Handle Rate Limit Error and Timeout Error
  86. You can set `retry_wait_time` and `max_retry_period` to handle rate limit error. And you can set `request_timeout` to handle timeout error. They can all be specified in `llm_config` for an agent, which will be used in the [`create`](/docs/reference/oai/completion#create) function for LLM inference.
  87. - `retry_wait_time` (int): the time interval to wait (in seconds) before retrying a failed request.
  88. - `max_retry_period` (int): the total timeout (in seconds) allowed for retrying failed requests.
  89. - `request_timeout` (int): the timeout (in seconds) sent with a single request.
  90. Please refer to the [documentation](/docs/Use-Cases/enhanced_inference#runtime-error) for more info.