Skip to main content

使用 Qdrant 进行检索增强代码生成和问答的 RetrieveChat

在 Colab 中打开 在 GitHub 上打开

Qdrant 是一个高性能的向量搜索引擎/数据库。

本笔记本演示了使用 QdrantRetrieveUserProxyAgent 进行 RAG 的用法,基于 agentchat_RetrieveChat.ipynb

RetrieveChat 是一个用于检索增强代码生成和问答的对话系统。在本笔记本中,我们演示了如何利用 RetrieveChat 根据自定义文档生成代码和回答问题,这些文档在 LLM 的训练数据集中不存在。RetrieveChat 使用 RetrieveAssistantAgentQdrantRetrieveUserProxyAgent,类似于其他笔记本中使用 AssistantAgentUserProxyAgent 的方式(例如 Automated Task Solving with Code Generation, Execution & Debugging)。

我们将演示如何使用 RetrieveChat 和 Qdrant 进行代码生成和问答,并结合人工反馈。

需求

本笔记本需要一些额外的依赖项,可以通过 pip 安装:

pip install "pyautogen[retrievechat-qdrant]" "flaml[automl]"

更多信息,请参阅 安装指南

%pip install "pyautogen[retrievechat-qdrant]" "flaml[automl]"
huggingface/tokenizers: The current process just got forked, after parallelism has already been used. Disabling parallelism to avoid deadlocks...
To disable this warning, you can either:
- Avoid using `tokenizers` before the fork if possible
- Explicitly set the environment variable TOKENIZERS_PARALLELISM=(true | false)
Requirement already satisfied: pyautogen>=0.2.3 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from pyautogen[retrievechat]>=0.2.3) (0.2.21)
Requirement already satisfied: flaml[automl] in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (2.1.2)
Requirement already satisfied: qdrant_client[fastembed] in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (1.6.4)
Requirement already satisfied: openai>=1.3 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from pyautogen>=0.2.3->pyautogen[retrievechat]>=0.2.3) (1.12.0)
Requirement already satisfied: diskcache in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from pyautogen>=0.2.3->pyautogen[retrievechat]>=0.2.3) (5.6.3)
Requirement already satisfied: termcolor in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from pyautogen>=0.2.3->pyautogen[retrievechat]>=0.2.3) (2.3.0)
Requirement already satisfied: numpy<2,>=1.17.0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from pyautogen>=0.2.3->pyautogen[retrievechat]>=0.2.3) (1.26.4)
Requirement already satisfied: python-dotenv in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from pyautogen>=0.2.3->pyautogen[retrievechat]>=0.2.3) (1.0.0)
Requirement already satisfied: tiktoken in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from pyautogen>=0.2.3->pyautogen[retrievechat]>=0.2.3) (0.5.1)
Requirement already satisfied: pydantic!=2.6.0,<3,>=1.10 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from pyautogen>=0.2.3->pyautogen[retrievechat]>=0.2.3) (2.6.4)
Requirement already satisfied: docker in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from pyautogen>=0.2.3->pyautogen[retrievechat]>=0.2.3) (7.0.0)
Requirement already satisfied: lightgbm>=2.3.1 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from flaml[automl]) (4.1.0)
Requirement already satisfied: xgboost>=0.90 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from flaml[automl]) (2.0.1)
Requirement already satisfied: scipy>=1.4.1 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from flaml[automl]) (1.10.1)
Requirement already satisfied: pandas>=1.1.4 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from flaml[automl]) (2.2.0)
Requirement already satisfied: scikit-learn>=0.24 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from flaml[automl]) (1.3.2)
Requirement already satisfied: grpcio>=1.41.0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from qdrant_client[fastembed]) (1.60.0)
Requirement already satisfied: grpcio-tools>=1.41.0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from qdrant_client[fastembed]) (1.59.2)
Requirement already satisfied: httpx>=0.14.0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from httpx[http2]>=0.14.0->qdrant_client[fastembed]) (0.25.1)
Requirement already satisfied: portalocker<3.0.0,>=2.7.0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from qdrant_client[fastembed]) (2.8.2)
Requirement already satisfied: urllib3<2.0.0,>=1.26.14 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from qdrant_client[fastembed]) (1.26.18)
Requirement already satisfied: fastembed==0.1.1 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from qdrant_client[fastembed]) (0.1.1)
Requirement already satisfied: onnx<2.0,>=1.11 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from fastembed==0.1.1->qdrant_client[fastembed]) (1.15.0)
Requirement already satisfied: onnxruntime<2.0,>=1.15 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from fastembed==0.1.1->qdrant_client[fastembed]) (1.15.1)
Requirement already satisfied: requests<3.0,>=2.31 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from fastembed==0.1.1->qdrant_client[fastembed]) (2.31.0)
Requirement already satisfied: tokenizers<0.14,>=0.13 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from fastembed==0.1.1->qdrant_client[fastembed]) (0.13.3)
Requirement already satisfied: tqdm<5.0,>=4.65 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from fastembed==0.1.1->qdrant_client[fastembed]) (4.66.2)
Requirement already satisfied: chromadb in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from pyautogen[retrievechat]>=0.2.3) (0.4.22)
Requirement already satisfied: sentence-transformers in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from pyautogen[retrievechat]>=0.2.3) (2.3.1)
Requirement already satisfied: pypdf in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from pyautogen[retrievechat]>=0.2.3) (4.0.1)
Requirement already satisfied: ipython in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from pyautogen[retrievechat]>=0.2.3) (8.17.2)
Requirement already satisfied: protobuf<5.0dev,>=4.21.6 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from grpcio-tools>=1.41.0->qdrant_client[fastembed]) (4.23.4)
Requirement already satisfied: setuptools in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from grpcio-tools>=1.41.0->qdrant_client[fastembed]) (68.2.2)
Requirement already satisfied: anyio in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from httpx>=0.14.0->httpx[http2]>=0.14.0->qdrant_client[fastembed]) (3.7.1)
Requirement already satisfied: certifi in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from httpx>=0.14.0->httpx[http2]>=0.14.0->qdrant_client[fastembed]) (2024.2.2)
Requirement already satisfied: httpcore in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from httpx>=0.14.0->httpx[http2]>=0.14.0->qdrant_client[fastembed]) (1.0.1)
Requirement already satisfied: idna in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from httpx>=0.14.0->httpx[http2]>=0.14.0->qdrant_client[fastembed]) (3.6)
Requirement already satisfied: sniffio in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from httpx>=0.14.0->httpx[http2]>=0.14.0->qdrant_client[fastembed]) (1.3.0)
Requirement already satisfied: h2<5,>=3 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from httpx[http2]>=0.14.0->qdrant_client[fastembed]) (4.1.0)
Requirement already satisfied: distro<2,>=1.7.0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from openai>=1.3->pyautogen>=0.2.3->pyautogen[retrievechat]>=0.2.3) (1.8.0)
Requirement already satisfied: typing-extensions<5,>=4.7 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from openai>=1.3->pyautogen>=0.2.3->pyautogen[retrievechat]>=0.2.3) (4.9.0)
Requirement already satisfied: python-dateutil>=2.8.2 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from pandas>=1.1.4->flaml[automl]) (2.8.2)
Requirement already satisfied: pytz>=2020.1 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from pandas>=1.1.4->flaml[automl]) (2024.1)
Requirement already satisfied: tzdata>=2022.7 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from pandas>=1.1.4->flaml[automl]) (2024.1)
Requirement already satisfied: annotated-types>=0.4.0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from pydantic!=2.6.0,<3,>=1.10->pyautogen>=0.2.3->pyautogen[retrievechat]>=0.2.3) (0.6.0)
Requirement already satisfied: pydantic-core==2.16.3 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from pydantic!=2.6.0,<3,>=1.10->pyautogen>=0.2.3->pyautogen[retrievechat]>=0.2.3) (2.16.3)
Requirement already satisfied: joblib>=1.1.1 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from scikit-learn>=0.24->flaml[automl]) (1.3.2)
Requirement already satisfied: threadpoolctl>=2.0.0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from scikit-learn>=0.24->flaml[automl]) (3.2.0)
Requirement already satisfied: build>=1.0.3 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from chromadb->pyautogen[retrievechat]>=0.2.3) (1.0.3)
Requirement already satisfied: chroma-hnswlib==0.7.3 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from chromadb->pyautogen[retrievechat]>=0.2.3) (0.7.3)
Requirement already satisfied: fastapi>=0.95.2 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from chromadb->pyautogen[retrievechat]>=0.2.3) (0.104.1)
Requirement already satisfied: uvicorn>=0.18.3 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from uvicorn[standard]>=0.18.3->chromadb->pyautogen[retrievechat]>=0.2.3) (0.24.0)
Requirement already satisfied: posthog>=2.4.0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from chromadb->pyautogen[retrievechat]>=0.2.3) (3.0.2)
Requirement already satisfied: pulsar-client>=3.1.0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from chromadb->pyautogen[retrievechat]>=0.2.3) (3.3.0)
Requirement already satisfied: opentelemetry-api>=1.2.0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from chromadb->pyautogen[retrievechat]>=0.2.3) (1.20.0)
Requirement already satisfied: opentelemetry-exporter-otlp-proto-grpc>=1.2.0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from chromadb->pyautogen[retrievechat]>=0.2.3) (1.20.0)
Requirement already satisfied: opentelemetry-instrumentation-fastapi>=0.41b0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from chromadb->pyautogen[retrievechat]>=0.2.3) (0.41b0)
Requirement already satisfied: opentelemetry-sdk>=1.2.0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from chromadb->pyautogen[retrievechat]>=0.2.3) (1.20.0)
Requirement already satisfied: pypika>=0.48.9 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from chromadb->pyautogen[retrievechat]>=0.2.3) (0.48.9)
Requirement already satisfied: overrides>=7.3.1 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from chromadb->pyautogen[retrievechat]>=0.2.3) (7.4.0)
Requirement already satisfied: importlib-resources in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from chromadb->pyautogen[retrievechat]>=0.2.3) (6.1.1)
Requirement already satisfied: bcrypt>=4.0.1 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from chromadb->pyautogen[retrievechat]>=0.2.3) (4.0.1)
Requirement already satisfied: typer>=0.9.0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from chromadb->pyautogen[retrievechat]>=0.2.3) (0.9.0)
Requirement already satisfied: kubernetes>=28.1.0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from chromadb->pyautogen[retrievechat]>=0.2.3) (28.1.0)
Requirement already satisfied: tenacity>=8.2.3 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from chromadb->pyautogen[retrievechat]>=0.2.3) (8.2.3)
Requirement already satisfied: PyYAML>=6.0.0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from chromadb->pyautogen[retrievechat]>=0.2.3) (6.0.1)
Requirement already satisfied: mmh3>=4.0.1 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from chromadb->pyautogen[retrievechat]>=0.2.3) (4.0.1)
Requirement already satisfied: packaging>=14.0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from docker->pyautogen>=0.2.3->pyautogen[retrievechat]>=0.2.3) (23.2)
Requirement already satisfied: decorator in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from ipython->pyautogen[retrievechat]>=0.2.3) (5.1.1)
Requirement already satisfied: jedi>=0.16 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from ipython->pyautogen[retrievechat]>=0.2.3) (0.19.1)
Requirement already satisfied: matplotlib-inline in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from ipython->pyautogen[retrievechat]>=0.2.3) (0.1.6)
Requirement already satisfied: prompt-toolkit!=3.0.37,<3.1.0,>=3.0.30 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from ipython->pyautogen[retrievechat]>=0.2.3) (3.0.39)
Requirement already satisfied: pygments>=2.4.0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from ipython->pyautogen[retrievechat]>=0.2.3) (2.16.1)
Requirement already satisfied: stack-data in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from ipython->pyautogen[retrievechat]>=0.2.3) (0.6.3)
Requirement already satisfied: traitlets>=5 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from ipython->pyautogen[retrievechat]>=0.2.3) (5.14.2)
Requirement already satisfied: exceptiongroup in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from ipython->pyautogen[retrievechat]>=0.2.3) (1.1.3)
Requirement already satisfied: pexpect>4.3 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from ipython->pyautogen[retrievechat]>=0.2.3) (4.8.0)
Requirement already satisfied: transformers<5.0.0,>=4.32.0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from sentence-transformers->pyautogen[retrievechat]>=0.2.3) (4.33.3)
Requirement already satisfied: torch>=1.11.0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from sentence-transformers->pyautogen[retrievechat]>=0.2.3) (2.2.0)
Requirement already satisfied: nltk in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from sentence-transformers->pyautogen[retrievechat]>=0.2.3) (3.8.1)
Requirement already satisfied: sentencepiece in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from sentence-transformers->pyautogen[retrievechat]>=0.2.3) (0.1.99)
Requirement already satisfied: huggingface-hub>=0.15.1 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from sentence-transformers->pyautogen[retrievechat]>=0.2.3) (0.20.3)
Requirement already satisfied: Pillow in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from sentence-transformers->pyautogen[retrievechat]>=0.2.3) (10.2.0)
Requirement already satisfied: regex>=2022.1.18 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from tiktoken->pyautogen>=0.2.3->pyautogen[retrievechat]>=0.2.3) (2023.12.25)
Requirement already satisfied: pyproject_hooks in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from build>=1.0.3->chromadb->pyautogen[retrievechat]>=0.2.3) (1.0.0)
Requirement already satisfied: tomli>=1.1.0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from build>=1.0.3->chromadb->pyautogen[retrievechat]>=0.2.3) (2.0.1)
Requirement already satisfied: starlette<0.28.0,>=0.27.0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from fastapi>=0.95.2->chromadb->pyautogen[retrievechat]>=0.2.3) (0.27.0)
Requirement already satisfied: hyperframe<7,>=6.0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from h2<5,>=3->httpx[http2]>=0.14.0->qdrant_client[fastembed]) (6.0.1)
Requirement already satisfied: hpack<5,>=4.0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from h2<5,>=3->httpx[http2]>=0.14.0->qdrant_client[fastembed]) (4.0.0)
Requirement already satisfied: filelock in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from huggingface-hub>=0.15.1->sentence-transformers->pyautogen[retrievechat]>=0.2.3) (3.13.1)
Requirement already satisfied: fsspec>=2023.5.0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from huggingface-hub>=0.15.1->sentence-transformers->pyautogen[retrievechat]>=0.2.3) (2024.2.0)
Requirement already satisfied: parso<0.9.0,>=0.8.3 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from jedi>=0.16->ipython->pyautogen[retrievechat]>=0.2.3) (0.8.3)
Requirement already satisfied: six>=1.9.0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from kubernetes>=28.1.0->chromadb->pyautogen[retrievechat]>=0.2.3) (1.16.0)
Requirement already satisfied: google-auth>=1.0.1 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from kubernetes>=28.1.0->chromadb->pyautogen[retrievechat]>=0.2.3) (2.23.4)
Requirement already satisfied: websocket-client!=0.40.0,!=0.41.*,!=0.42.*,>=0.32.0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from kubernetes>=28.1.0->chromadb->pyautogen[retrievechat]>=0.2.3) (1.6.4)
Requirement already satisfied: requests-oauthlib in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from kubernetes>=28.1.0->chromadb->pyautogen[retrievechat]>=0.2.3) (1.3.1)
Requirement already satisfied: oauthlib>=3.2.2 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from kubernetes>=28.1.0->chromadb->pyautogen[retrievechat]>=0.2.3) (3.2.2)
Requirement already satisfied: coloredlogs in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from onnxruntime<2.0,>=1.15->fastembed==0.1.1->qdrant_client[fastembed]) (15.0.1)
Requirement already satisfied: flatbuffers in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from onnxruntime<2.0,>=1.15->fastembed==0.1.1->qdrant_client[fastembed]) (23.5.26)
Requirement already satisfied: sympy in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from onnxruntime<2.0,>=1.15->fastembed==0.1.1->qdrant_client[fastembed]) (1.12)
Requirement already satisfied: deprecated>=1.2.6 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from opentelemetry-api>=1.2.0->chromadb->pyautogen[retrievechat]>=0.2.3) (1.2.14)
Requirement already satisfied: importlib-metadata<7.0,>=6.0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from opentelemetry-api>=1.2.0->chromadb->pyautogen[retrievechat]>=0.2.3) (6.11.0)
Requirement already satisfied: backoff<3.0.0,>=1.10.0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from opentelemetry-exporter-otlp-proto-grpc>=1.2.0->chromadb->pyautogen[retrievechat]>=0.2.3) (2.2.1)
Requirement already satisfied: googleapis-common-protos~=1.52 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from opentelemetry-exporter-otlp-proto-grpc>=1.2.0->chromadb->pyautogen[retrievechat]>=0.2.3) (1.61.0)
Requirement already satisfied: opentelemetry-exporter-otlp-proto-common==1.20.0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from opentelemetry-exporter-otlp-proto-grpc>=1.2.0->chromadb->pyautogen[retrievechat]>=0.2.3) (1.20.0)
Requirement already satisfied: opentelemetry-proto==1.20.0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from opentelemetry-exporter-otlp-proto-grpc>=1.2.0->chromadb->pyautogen[retrievechat]>=0.2.3) (1.20.0)
Requirement already satisfied: opentelemetry-instrumentation-asgi==0.41b0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from opentelemetry-instrumentation-fastapi>=0.41b0->chromadb->pyautogen[retrievechat]>=0.2.3) (0.41b0)
Requirement already satisfied: opentelemetry-instrumentation==0.41b0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from opentelemetry-instrumentation-fastapi>=0.41b0->chromadb->pyautogen[retrievechat]>=0.2.3) (0.41b0)
Requirement already satisfied: opentelemetry-semantic-conventions==0.41b0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from opentelemetry-instrumentation-fastapi>=0.41b0->chromadb->pyautogen[retrievechat]>=0.2.3) (0.41b0)
Requirement already satisfied: opentelemetry-util-http==0.41b0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from opentelemetry-instrumentation-fastapi>=0.41b0->chromadb->pyautogen[retrievechat]>=0.2.3) (0.41b0)
Requirement already satisfied: wrapt<2.0.0,>=1.0.0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from opentelemetry-instrumentation==0.41b0->opentelemetry-instrumentation-fastapi>=0.41b0->chromadb->pyautogen[retrievechat]>=0.2.3) (1.16.0)
Requirement already satisfied: asgiref~=3.0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from opentelemetry-instrumentation-asgi==0.41b0->opentelemetry-instrumentation-fastapi>=0.41b0->chromadb->pyautogen[retrievechat]>=0.2.3) (3.7.2)
Requirement already satisfied: ptyprocess>=0.5 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from pexpect>4.3->ipython->pyautogen[retrievechat]>=0.2.3) (0.7.0)
Requirement already satisfied: monotonic>=1.5 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from posthog>=2.4.0->chromadb->pyautogen[retrievechat]>=0.2.3) (1.6)
Requirement already satisfied: wcwidth in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from prompt-toolkit!=3.0.37,<3.1.0,>=3.0.30->ipython->pyautogen[retrievechat]>=0.2.3) (0.2.9)
Requirement already satisfied: charset-normalizer<4,>=2 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from requests<3.0,>=2.31->fastembed==0.1.1->qdrant_client[fastembed]) (3.3.2)
Requirement already satisfied: networkx in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from torch>=1.11.0->sentence-transformers->pyautogen[retrievechat]>=0.2.3) (3.2.1)
Requirement already satisfied: jinja2 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from torch>=1.11.0->sentence-transformers->pyautogen[retrievechat]>=0.2.3) (3.1.3)
Requirement already satisfied: nvidia-cuda-nvrtc-cu12==12.1.105 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from torch>=1.11.0->sentence-transformers->pyautogen[retrievechat]>=0.2.3) (12.1.105)
Requirement already satisfied: nvidia-cuda-runtime-cu12==12.1.105 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from torch>=1.11.0->sentence-transformers->pyautogen[retrievechat]>=0.2.3) (12.1.105)
Requirement already satisfied: nvidia-cuda-cupti-cu12==12.1.105 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from torch>=1.11.0->sentence-transformers->pyautogen[retrievechat]>=0.2.3) (12.1.105)
Requirement already satisfied: nvidia-cudnn-cu12==8.9.2.26 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from torch>=1.11.0->sentence-transformers->pyautogen[retrievechat]>=0.2.3) (8.9.2.26)
Requirement already satisfied: nvidia-cublas-cu12==12.1.3.1 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from torch>=1.11.0->sentence-transformers->pyautogen[retrievechat]>=0.2.3) (12.1.3.1)
Requirement already satisfied: nvidia-cufft-cu12==11.0.2.54 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from torch>=1.11.0->sentence-transformers->pyautogen[retrievechat]>=0.2.3) (11.0.2.54)
Requirement already satisfied: nvidia-curand-cu12==10.3.2.106 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from torch>=1.11.0->sentence-transformers->pyautogen[retrievechat]>=0.2.3) (10.3.2.106)
Requirement already satisfied: nvidia-cusolver-cu12==11.4.5.107 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from torch>=1.11.0->sentence-transformers->pyautogen[retrievechat]>=0.2.3) (11.4.5.107)
Requirement already satisfied: nvidia-cusparse-cu12==12.1.0.106 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from torch>=1.11.0->sentence-transformers->pyautogen[retrievechat]>=0.2.3) (12.1.0.106)
Requirement already satisfied: nvidia-nccl-cu12==2.19.3 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from torch>=1.11.0->sentence-transformers->pyautogen[retrievechat]>=0.2.3) (2.19.3)
Requirement already satisfied: nvidia-nvtx-cu12==12.1.105 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from torch>=1.11.0->sentence-transformers->pyautogen[retrievechat]>=0.2.3) (12.1.105)
Requirement already satisfied: triton==2.2.0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from torch>=1.11.0->sentence-transformers->pyautogen[retrievechat]>=0.2.3) (2.2.0)
Requirement already satisfied: nvidia-nvjitlink-cu12 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from nvidia-cusolver-cu12==11.4.5.107->torch>=1.11.0->sentence-transformers->pyautogen[retrievechat]>=0.2.3) (12.3.52)
Requirement already satisfied: safetensors>=0.3.1 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from transformers<5.0.0,>=4.32.0->sentence-transformers->pyautogen[retrievechat]>=0.2.3) (0.3.2)
Requirement already satisfied: click<9.0.0,>=7.1.1 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from typer>=0.9.0->chromadb->pyautogen[retrievechat]>=0.2.3) (8.1.7)
Requirement already satisfied: h11>=0.8 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from uvicorn>=0.18.3->uvicorn[standard]>=0.18.3->chromadb->pyautogen[retrievechat]>=0.2.3) (0.14.0)
Requirement already satisfied: httptools>=0.5.0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from uvicorn[standard]>=0.18.3->chromadb->pyautogen[retrievechat]>=0.2.3) (0.6.1)
Requirement already satisfied: uvloop!=0.15.0,!=0.15.1,>=0.14.0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from uvicorn[standard]>=0.18.3->chromadb->pyautogen[retrievechat]>=0.2.3) (0.19.0)
Requirement already satisfied: watchfiles>=0.13 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from uvicorn[standard]>=0.18.3->chromadb->pyautogen[retrievechat]>=0.2.3) (0.21.0)
Requirement already satisfied: websockets>=10.4 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from uvicorn[standard]>=0.18.3->chromadb->pyautogen[retrievechat]>=0.2.3) (11.0.3)
Requirement already satisfied: executing>=1.2.0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from stack-data->ipython->pyautogen[retrievechat]>=0.2.3) (2.0.1)
Requirement already satisfied: asttokens>=2.1.0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from stack-data->ipython->pyautogen[retrievechat]>=0.2.3) (2.4.1)
Requirement already satisfied: pure-eval in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from stack-data->ipython->pyautogen[retrievechat]>=0.2.3) (0.2.2)
Requirement already satisfied: cachetools<6.0,>=2.0.0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from google-auth>=1.0.1->kubernetes>=28.1.0->chromadb->pyautogen[retrievechat]>=0.2.3) (5.3.2)
Requirement already satisfied: pyasn1-modules>=0.2.1 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from google-auth>=1.0.1->kubernetes>=28.1.0->chromadb->pyautogen[retrievechat]>=0.2.3) (0.3.0)
Requirement already satisfied: rsa<5,>=3.1.4 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from google-auth>=1.0.1->kubernetes>=28.1.0->chromadb->pyautogen[retrievechat]>=0.2.3) (4.9)
Requirement already satisfied: zipp>=0.5 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from importlib-metadata<7.0,>=6.0->opentelemetry-api>=1.2.0->chromadb->pyautogen[retrievechat]>=0.2.3) (3.17.0)
Requirement already satisfied: humanfriendly>=9.1 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from coloredlogs->onnxruntime<2.0,>=1.15->fastembed==0.1.1->qdrant_client[fastembed]) (10.0)
Requirement already satisfied: MarkupSafe>=2.0 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from jinja2->torch>=1.11.0->sentence-transformers->pyautogen[retrievechat]>=0.2.3) (2.1.5)
Requirement already satisfied: mpmath>=0.19 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from sympy->onnxruntime<2.0,>=1.15->fastembed==0.1.1->qdrant_client[fastembed]) (1.3.0)
Requirement already satisfied: pyasn1<0.6.0,>=0.4.6 in /home/lijiang1/anaconda3/envs/autogen/lib/python3.10/site-packages (from pyasn1-modules>=0.2.1->google-auth>=1.0.1->kubernetes>=28.1.0->chromadb->pyautogen[retrievechat]>=0.2.3) (0.5.0)
Note: you may need to restart the kernel to use updated packages.

设置 API 端点

config_list_from_json 函数从环境变量或 json 文件中加载配置列表。

from qdrant_client import QdrantClient

import autogen
from autogen.agentchat.contrib.qdrant_retrieve_user_proxy_agent import QdrantRetrieveUserProxyAgent
from autogen.agentchat.contrib.retrieve_assistant_agent import RetrieveAssistantAgent

# 可以存储在向量数据库实例中的文件格式
from autogen.retrieve_utils import TEXT_FORMATS

config_list = autogen.config_list_from_json("OAI_CONFIG_LIST")

assert len(config_list) > 0
print("要使用的模型:", [config_list[i]["model"] for i in range(len(config_list))])
要使用的模型:  ['gpt4-1106-preview', 'gpt-35-turbo', 'gpt-35-turbo-0613']
tip

了解有关为代理配置 LLM 的更多信息,请点击这里

print("docs_path 可接受的文件格式:")
print(TEXT_FORMATS)
docs_path 可接受的文件格式:
['yml', 'ppt', 'org', 'doc', 'epub', 'rst', 'log', 'docx', 'htm', 'html', 'tsv', 'csv', 'json', 'yaml', 'xlsx', 'pptx', 'rtf', 'msg', 'odt', 'pdf', 'jsonl', 'md', 'xml', 'txt']

构建 RetrieveChat 的代理

我们首先初始化 RetrieveAssistantAgentQdrantRetrieveUserProxyAgent。对于 RetrieveAssistantAgent,系统消息需要设置为 "You are a helpful assistant."。详细的说明在用户消息中给出。稍后,我们将使用 QdrantRetrieveUserProxyAgent.generate_init_prompt 将说明和一个检索增强生成任务组合起来,作为初始提示发送给 LLM 助手。

您可以在这里找到 Qdrant 支持的所有嵌入模型的列表。

# 1. 创建一个名为“assistant”的 RetrieveAssistantAgent 实例
assistant = RetrieveAssistantAgent(
name="assistant",
system_message="你是一个乐于助人的助手。",
llm_config={
"timeout": 600,
"cache_seed": 42,
"config_list": config_list,
},
)

# 2. 创建一个名为“ragproxyagent”的 QdrantRetrieveUserProxyAgent 实例
# 默认情况下,human_input_mode 是“ALWAYS”,这意味着代理将在每一步都要求人工输入。我们在这里将其设置为“NEVER”。
# `docs_path` 是文档目录的路径。它也可以是单个文件的路径,或者是单个文件的 URL。默认情况下,
# 如果集合已经创建,则设置为 None。
#
# 在这里,我们从 FLAML 的 docstrings 生成了文档。如果您只想尝试这个笔记本而不是重现输出,这是不必要的。克隆 FLAML(https://github.com/microsoft/FLAML)存储库并导航到其网站文件夹。Pip 安装并运行 `pydoc-markdown`,它将在 `website/docs` 下生成 `reference` 文件夹。
#
# `task` 表示我们正在处理的任务类型。在这个例子中,它是一个 `code` 任务。
# `chunk_token_size` 是检索聊天的块令牌大小。默认情况下,它设置为 `max_tokens * 0.6`,这里我们将其设置为 2000。
# 我们在这里使用了一个内存中的 QdrantClient 实例。不推荐用于生产环境。
# 获取安装说明:https://qdrant.tech/documentation/guides/installation/
ragproxyagent = QdrantRetrieveUserProxyAgent(
name="ragproxyagent",
human_input_mode="NEVER",
max_consecutive_auto_reply=10,
retrieve_config={
"task": "code",
"docs_path": [
"https://raw.githubusercontent.com/microsoft/flaml/main/README.md",
"https://raw.githubusercontent.com/microsoft/FLAML/main/website/docs/Research.md",
], # 将此处更改为您自己的路径,例如 https://raw.githubusercontent.com/microsoft/autogen/main/README.md
"chunk_token_size": 2000,
"model": config_list[0]["model"],
"client": QdrantClient(":memory:"),
"embedding_model": "BAAI/bge-small-en-v1.5",
},
code_execution_config=False,
)

### 示例 1

返回目录

使用 RetrieveChat 来回答问题并请求人工反馈。

问题:FLAML 中是否有一个名为 tune_automl 的函数?

# 重置助手。在开始新对话之前,始终重置助手。
assistant.reset()

qa_problem = "是否有一个名为 tune_automl 的函数?"
ragproxyagent.initiate_chat(assistant, message=ragproxyagent.message_generator, problem=qa_problem)
正在尝试创建集合。
2024-04-07 18:30:12,489 - autogen.agentchat.contrib.qdrant_retrieve_user_proxy_agent - INFO - 找到 3 个块。
找不到模型 gpt4-1106-preview。使用 cl100k_base 编码。
将文档 0 的内容添加到上下文中。
找不到模型 gpt4-1106-preview。使用 cl100k_base 编码。
ragproxyagent(对助手说):

你是一个带有检索增强的编码助手。你根据自己的知识和用户提供的上下文来回答用户的问题。
如果你无法根据当前上下文回答问题,你应该回复 `UPDATE CONTEXT`。
对于代码生成,你必须遵守以下规则:
规则 1. 你绝对不能安装任何包,因为所有需要的包都已经安装好了。
规则 2. 你必须按照以下格式编写你的代码:
```language
# 你的代码
用户的问题是:是否有一个名为tune_automl的函数?

上下文是:[![PyPI版本](https://badge.fury.io/py/FLAML.svg)](https://badge.fury.io/py/FLAML)
![Conda版本](https://img.shields.io/conda/vn/conda-forge/flaml)
[![构建](https://github.com/microsoft/FLAML/actions/workflows/python-package.yml/badge.svg)](https://github.com/microsoft/FLAML/actions/workflows/python-package.yml)
![Python版本](https://img.shields.io/badge/3.8%20%7C%203.9%20%7C%203.10-blue)
[![下载量](https://pepy.tech/badge/flaml)](https://pepy.tech/project/flaml)
[![](https://img.shields.io/discord/1025786666260111483?logo=discord&style=flat)](https://discord.gg/Cppx2vSPVP)

<!-- [![加入聊天 https://gitter.im/FLAMLer/community](https://badges.gitter.im/FLAMLer/community.svg)](https://gitter.im/FLAMLer/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -->

# 一个快速的自动化机器学习和调参库

<p align="center">
<img src="https://github.com/microsoft/FLAML/blob/main/website/static/img/flaml.svg" width=200>
<br>
</p>

:fire: 注意:我们已经将[AutoGen](https://microsoft.github.io/autogen/)迁移到了一个专门的[github仓库](https://github.com/microsoft/autogen)。同时,我们还推出了一个专门的[Discord](https://discord.gg/pAbnFJrkgZ)服务器和一个[网站](https://microsoft.github.io/autogen/),提供全面的文档。

:fire: [AutoGen](https://microsoft.github.io/autogen/)中的自动化多代理聊天框架从v2.0.0开始处于预览状态。

:fire: FLAML在OpenAI的[菜谱](https://github.com/openai/openai-cookbook#related-resources-from-around-the-web)中受到了关注。

:fire: [autogen](https://microsoft.github.io/autogen/)发布,支持ChatGPT和GPT-4,基于[成本效益的大型语言模型生成推理的超参数优化](https://arxiv.org/abs/2303.04673)。

:fire: FLAML支持代码优先的自动机器学习和调参 - 在[Microsoft Fabric Data Science](https://learn.microsoft.com/en-us/fabric/data-science/)中进行私有预览。

## FLAML是什么

FLAML是一个轻量级的Python库,用于高效自动化机器学习和人工智能操作。它基于大型语言模型、机器学习模型等自动化工作流程,并优化它们的性能。

- FLAML使构建基于多代理对话的下一代GPT-X应用变得简单。它简化了复杂GPT-X工作流程的编排、自动化和优化。它最大化了GPT-X模型的性能,并增强了它们的弱点。
- 对于常见的机器学习任务,如分类和回归,它可以在低计算资源下快速找到用户提供数据的优质模型。它易于定制或扩展。用户可以从平滑的范围中找到他们想要的可定制性。
- 它支持快速经济的自动调参(例如,基础模型的推理超参数、MLOps/LMOps工作流程中的配置、管道、数学/统计模型、算法、计算实验、软件配置),能够处理具有异构评估成本和复杂约束/指导/提前停止的大搜索空间。

FLAML由一系列来自微软研究和合作伙伴(如宾夕法尼亚州立大学、史蒂文斯理工学院、华盛顿大学和滑铁卢大学)的[研究研究](https://microsoft.github.io/FLAML/docs/Research/)支持。

FLAML在[ML.NET](http://dot.net/ml)中有一个.NET实现,它是一个开源的、跨平台的.NET机器学习框架。

## 安装

FLAML需要**Python版本 >= 3.8**。可以通过pip安装:

```bash
```
pip install flaml
```

最小化的依赖项被安装,没有额外的选项。您可以根据您需要的功能安装额外的选项。例如,使用以下命令安装 [`autogen`](https://microsoft.github.io/autogen/) 包所需的依赖项。

```bash
pip install "flaml[autogen]"
```

在 [Installation](https://microsoft.github.io/FLAML/docs/Installation) 中找到更多选项。每个 [`notebook examples`](https://github.com/microsoft/FLAML/tree/main/notebook) 可能需要安装特定的选项。

## 快速入门

- (新功能) [autogen](https://microsoft.github.io/autogen/) 包通过通用的多代理对话框架实现了下一代 GPT-X 应用。
它提供了可定制和可对话的代理,集成了 LLMs、工具和人类。
通过自动化多个能力代理之间的聊天,可以轻松地使它们集体自主地执行任务或与人类反馈一起执行任务,包括需要通过代码使用工具的任务。例如,

```python
from flaml import autogen

assistant = autogen.AssistantAgent("assistant")
user_proxy = autogen.UserProxyAgent("user_proxy")
user_proxy.initiate_chat(
assistant,
message="Show me the YTD gain of 10 largest technology companies as of today.",
)
# 这将在两个代理之间启动一个自动化的对话来解决任务
```

Autogen 还有助于最大化昂贵的 LLMs(如 ChatGPT 和 GPT-4)的效用。它提供了 `openai.Completion` 或 `openai.ChatCompletion` 的替代方案,具有强大的功能,如调优、缓存、模板化、过滤等。例如,您可以通过自己的调优数据、成功指标和预算来优化 LLM 的生成。

```python
# 进行调优
config, analysis = autogen.Completion.tune(
data=tune_data,
metric="success",
mode="max",
eval_func=eval_func,
inference_budget=0.05,
optimization_budget=3,
num_samples=-1,
)
# 对测试实例进行推理
response = autogen.Completion.create(context=test_instance, **config)
```

- 只需三行代码,您就可以将这个经济高效的 AutoML 引擎作为 [scikit-learn 风格的估计器](https://microsoft.github.io/FLAML/docs/Use-Cases/Task-Oriented-AutoML) 使用。

```python
from flaml import AutoML

automl = AutoML()
automl.fit(X_train, y_train, task="classification")
```

- 您可以限制学习器的使用,并将 FLAML 作为 XGBoost、LightGBM、Random Forest 等的快速超参数调优工具,或者作为 [自定义学习器](https://microsoft.github.io/FLAML/docs/Use-Cases/Task-Oriented-AutoML#estimator-and-search-space)。

```python
automl.fit(X_train, y_train, task="classification", estimator_list=["lgbm"])
```

- 您还可以为 [自定义函数](https://microsoft.github.io/FLAML/docs/Use-Cases/Tune-User-Defined-Function) 运行通用的超参数调优。

```python
from flaml import tune
tune.run(evaluation_function, config={...}, low_cost_partial_config={...}, time_budget_s=3600)
```

- [零-shot AutoML](https://microsoft.github.io/FLAML/docs/Use-Cases/Zero-Shot-AutoML) 允许在使用 lightgbm、xgboost 等现有训练 API 的同时,利用 AutoML 在每个任务中选择高性能的超参数配置。

```python
```
从flaml.default导入LGBMRegressor

# 使用LGBMRegressor的方式与使用lightgbm.LGBMRegressor相同。
estimator = LGBMRegressor()
# 根据训练数据自动设置超参数。
estimator.fit(X_train, y_train)
```

## 文档

您可以在[这里](https://microsoft.github.io/FLAML/)找到有关FLAML的详细文档。

此外,您还可以找到:

- 关于FLAML的[研究](https://microsoft.github.io/FLAML/docs/Research)和[博客文章](https://microsoft.github.io/FLAML/blog)。

- [Discord](https://discord.gg/Cppx2vSPVP)。

- [贡献指南](https://microsoft.github.io/FLAML/docs/Contribute)。

- ML.NET的文档和教程,包括[模型构建器](https://learn.microsoft.com/dotnet/machine-learning/tutorials/predict-prices-with-model-builder),[ML.NET CLI](https://learn.microsoft.com/dotnet/machine-learning/tutorials/sentiment-analysis-cli)和[AutoML API](https://learn.microsoft.com/dotnet/machine-learning/how-to-guides/how-to-use-the-automl-api)。

## 贡献

该项目欢迎贡献和建议。大多数贡献需要您同意签署贡献者许可协议(CLA),声明您有权利并确实授予我们使用您的贡献的权利。有关详细信息,请访问<https://cla.opensource.microsoft.com>。
将文档2的内容添加到上下文中。
模型 gpt4-1106-preview 未找到。使用 cl100k_base 编码。

将文档 1 的内容添加到上下文中。
ragproxyagent(给助手):

你是一个增强型的检索编码助手。你根据自己的知识和用户提供的上下文来回答用户的问题。
如果你无法根据当前上下文回答问题,无论有无上下文,你都应该回复“UPDATE CONTEXT”。
对于代码生成,你必须遵守以下规则:
规则 1. 你绝对不可以安装任何包,因为所需的所有包都已经安装好了。
规则 2. 你必须按照以下格式编写你的代码:
```language
# 你的代码
```

用户的问题是:是否有一个名为 tune_automl 的函数?

上下文是:# 研究

有关技术细节,请查看我们的研究出版物。

- [FLAML: A Fast and Lightweight AutoML Library](https://www.microsoft.com/en-us/research/publication/flaml-a-fast-and-lightweight-automl-library/)。Chi Wang, Qingyun Wu, Markus Weimer, Erkang Zhu。MLSys 2021。

```bibtex
@inproceedings{wang2021flaml,
title={FLAML: A Fast and Lightweight AutoML Library},
author={Chi Wang and Qingyun Wu and Markus Weimer and Erkang Zhu},
year={2021},
booktitle={MLSys},
}
```

- [Frugal Optimization for Cost-related Hyperparameters](https://arxiv.org/abs/2005.01571)。Qingyun Wu, Chi Wang, Silu Huang。AAAI 2021。

```bibtex
@inproceedings{wu2021cfo,
title={Frugal Optimization for Cost-related Hyperparameters},
author={Qingyun Wu and Chi Wang and Silu Huang},
year={2021},
booktitle={AAAI},
}
```

- [Economical Hyperparameter Optimization With Blended Search Strategy](https://www.microsoft.com/en-us/research/publication/economical-hyperparameter-optimization-with-blended-search-strategy/)。Chi Wang, Qingyun Wu, Silu Huang, Amin Saied。ICLR 2021。

```bibtex
@inproceedings{wang2021blendsearch,
title={Economical Hyperparameter Optimization With Blended Search Strategy},
author={Chi Wang and Qingyun Wu and Silu Huang and Amin Saied},
year={2021},
booktitle={ICLR},
}
```

- [An Empirical Study on Hyperparameter Optimization for Fine-Tuning Pre-trained Language Models](https://aclanthology.org/2021.acl-long.178.pdf)。Susan Xueqing Liu, Chi Wang。ACL 2021。

```bibtex
@inproceedings{liuwang2021hpolm,
title={An Empirical Study on Hyperparameter Optimization for Fine-Tuning Pre-trained Language Models},
author={Susan Xueqing Liu and Chi Wang},
year={2021},
booktitle={ACL},
}
```

- [ChaCha for Online AutoML](https://www.microsoft.com/en-us/research/publication/chacha-for-online-automl/)。Qingyun Wu, Chi Wang, John Langford, Paul Mineiro and Marco Rossi。ICML 2021。

```bibtex
@inproceedings{wu2021chacha,
title={ChaCha for Online AutoML},
author={Qingyun Wu and Chi Wang and John Langford and Paul Mineiro and Marco Rossi},
year={2021},
booktitle={ICML},
}
```

- [公平的自动机器学习](https://arxiv.org/abs/2111.06495). Qingyun Wu, Chi Wang. ArXiv预印本 arXiv:2111.06495 (2021).

```
- [公平的自动机器学习](https://arxiv.org/abs/2111.06495)。Qingyun Wu和Chi Wang。ArXiv预印本arXiv:2111.06495(2021年)。

- [为资源受限的自动机器学习挖掘稳健的默认配置](https://arxiv.org/abs/2202.09927)。Moe Kayali和Chi Wang。ArXiv预印本arXiv:2202.09927(2022年)。

- [基于词典偏好的多目标超参数优化](https://openreview.net/forum?id=0Ij9_q567Ma)。Shaokun Zhang,Feiran Jia,Chi Wang,Qingyun Wu。ICLR 2023(显著-前5%)。

- [大型语言模型生成推理的经济高效超参数优化](https://arxiv.org/abs/2303.04673)。Chi Wang,Susan Xueqing Liu,Ahmed H. Awadallah。ArXiv预印本arXiv:2303.04673(2023年)。

- [使用GPT-4进行具有挑战性的数学问题求解的实证研究](https://arxiv.org/abs/2306.01337)。Yiran Wu,Feiran Jia,Shaokun Zhang,Hangyu Li,Erkang Zhu,Yue Wang,Yin Tat Lee,Richard Peng,Qingyun Wu,Chi Wang。ArXiv预印本arXiv:2306.01337(2023年)。
如果你对GitHub还不熟悉,可以参考[这里](https://help.github.com/categories/collaborating-with-issues-and-pull-requests/),这是一个详细的帮助资源,可以帮助你参与GitHub上的开发工作。

当你提交一个拉取请求时,CLA机器人会自动判断你是否需要提供CLA,并相应地装饰拉取请求(例如,状态检查,评论)。只需按照机器人提供的说明操作即可。你只需要在使用我们的CLA的所有存储库中执行一次即可。

本项目采用了[Microsoft开源行为准则](https://opensource.microsoft.com/codeofconduct/)。如需更多信息,请参阅[行为准则常见问题解答](https://opensource.microsoft.com/codeofconduct/faq/)或通过[opencode@microsoft.com](mailto:opencode@microsoft.com)与我们联系,提出任何其他问题或意见。
``` text
ChatResult(chat_id=None, chat_history=[{'content': 'TERMINATE', 'role': 'assistant'}], summary='', cost=({'total_cost': 0.19977, 'gpt-4': {'cost': 0.19977, 'prompt_tokens': 6153, 'completion_tokens': 253, 'total_tokens': 6406}}, {'total_cost': 0.19977, 'gpt-4': {'cost': 0.19977, 'prompt_tokens': 6153, 'completion_tokens': 253, 'total_tokens': 6406}}), human_input=[])
```

<a id="example-2"></a> \### 示例 2

[返回顶部](#toc)

使用 RetrieveChat 来回答一个与代码生成无关的问题。

问题:FLAML 的作者是谁?

```python
# 重置助手。在开始新对话之前,总是重置助手。
assistant.reset()

qa_problem = "FLAML 的作者是谁?"
ragproxyagent.initiate_chat(assistant, message=ragproxyagent.message_generator, problem=qa_problem)
```

``` text
找不到模型 gpt4-1106-preview。使用 cl100k_base 编码。
```

``` text
将文档 2 的内容添加到上下文中。
```

``` text
找不到模型 gpt4-1106-preview。使用 cl100k_base 编码。
```

```` text
ragproxyagent (to assistant):

你是一个检索增强的编码助手。你根据自己的知识和用户提供的上下文来回答用户的问题。
如果你无法根据当前上下文回答问题,你应该回复 `UPDATE CONTEXT`。
对于代码生成,你必须遵守以下规则:
规则 1. 你绝对不能安装任何包,因为所有需要的包都已经安装好了。
规则 2. 你必须按照以下格式编写你的代码:
```language
# 你的代码
```

用户的问题是:FLAML 的作者是谁?

上下文是:# 研究

有关技术细节,请查阅我们的研究出版物。

- [FLAML: A Fast and Lightweight AutoML Library](https://www.microsoft.com/en-us/research/publication/flaml-a-fast-and-lightweight-automl-library/)。Chi Wang, Qingyun Wu, Markus Weimer, Erkang Zhu。MLSys 2021。

```bibtex
@inproceedings{wang2021flaml,
title={FLAML: A Fast and Lightweight AutoML Library},
author={Chi Wang and Qingyun Wu and Markus Weimer and Erkang Zhu},
year={2021},
booktitle={MLSys},
}
```

- [Frugal Optimization for Cost-related Hyperparameters](https://arxiv.org/abs/2005.01571)。Qingyun Wu, Chi Wang, Silu Huang。AAAI 2021。

```bibtex
@inproceedings{wu2021cfo,
title={Frugal Optimization for Cost-related Hyperparameters},
author={Qingyun Wu and Chi Wang and Silu Huang},
year={2021},
booktitle={AAAI},
}
```

- [Economical Hyperparameter Optimization With Blended Search Strategy](https://www.microsoft.com/en-us/research/publication/economical-hyperparameter-optimization-with-blended-search-strategy/)。Chi Wang, Qingyun Wu, Silu Huang, Amin Saied。ICLR 2021。

```bibtex
@inproceedings{wang2021blendsearch,
title={Economical Hyperparameter Optimization With Blended Search Strategy},
author={Chi Wang and Qingyun Wu and Silu Huang and Amin Saied},
year={2021},
booktitle={ICLR},
}
```

- [对预训练语言模型微调的超参数优化的实证研究](https://aclanthology.org/2021.acl-long.178.pdf)。Susan Xueqing Liu, Chi Wang。ACL 2021。

```bibtex
- [超参数优化对预训练语言模型微调的实证研究](https://arxiv.org/abs/2306.01337)。Susan Xueqing Liu, Chi Wang。ArXiv预印本arXiv:2306.01337(2023年)。

```bibtex
@inproceedings{liuwang2021hpolm,
title={超参数优化对预训练语言模型微调的实证研究},
author={Susan Xueqing Liu and Chi Wang},
year={2021},
booktitle={ACL},
}
```

- [在线自动机器学习的ChaCha](https://www.microsoft.com/en-us/research/publication/chacha-for-online-automl/)。Qingyun Wu, Chi Wang, John Langford, Paul Mineiro和Marco Rossi。ICML 2021。

```bibtex
@inproceedings{wu2021chacha,
title={在线自动机器学习的ChaCha},
author={Qingyun Wu and Chi Wang and John Langford and Paul Mineiro and Marco Rossi},
year={2021},
booktitle={ICML},
}
```

- [公平的自动机器学习](https://arxiv.org/abs/2111.06495)。Qingyun Wu, Chi Wang。ArXiv预印本arXiv:2111.06495(2021年)。

```bibtex
@inproceedings{wuwang2021fairautoml,
title={公平的自动机器学习},
author={Qingyun Wu and Chi Wang},
year={2021},
booktitle={ArXiv预印本arXiv:2111.06495},
}
```

- [针对资源受限的自动机器学习挖掘稳健的默认配置](https://arxiv.org/abs/2202.09927)。Moe Kayali, Chi Wang。ArXiv预印本arXiv:2202.09927(2022年)。

```bibtex
@inproceedings{kayaliwang2022default,
title={针对资源受限的自动机器学习挖掘稳健的默认配置},
author={Moe Kayali and Chi Wang},
year={2022},
booktitle={ArXiv预印本arXiv:2202.09927},
}
```

- [基于词典偏好的多目标超参数优化](https://openreview.net/forum?id=0Ij9_q567Ma)。Shaokun Zhang, Feiran Jia, Chi Wang, Qingyun Wu。ICLR 2023(重要-前5%)。

```bibtex
@inproceedings{zhang2023targeted,
title={基于词典偏好的多目标超参数优化},
author={Shaokun Zhang and Feiran Jia and Chi Wang and Qingyun Wu},
booktitle={国际学习表示会议},
year={2023},
url={https://openreview.net/forum?id=0Ij9_q567Ma},
}
```

- [大型语言模型生成推理的成本效益超参数优化](https://arxiv.org/abs/2303.04673)。Chi Wang, Susan Xueqing Liu, Ahmed H. Awadallah。ArXiv预印本arXiv:2303.04673(2023年)。

```bibtex
@inproceedings{wang2023EcoOptiGen,
title={大型语言模型生成推理的成本效益超参数优化},
author={Chi Wang and Susan Xueqing Liu and Ahmed H. Awadallah},
year={2023},
booktitle={ArXiv预印本arXiv:2303.04673},
}
```

- [使用GPT-4进行具有挑战性的数学问题求解的实证研究](https://arxiv.org/abs/2306.01337)。Yiran Wu, Feiran Jia, Shaokun Zhang, Hangyu Li, Erkang Zhu, Yue Wang, Yin Tat Lee, Richard Peng, Qingyun Wu, Chi Wang。ArXiv预印本arXiv:2306.01337(2023年)。

```bibtex
@inproceedings{wu2023empirical,
title={使用GPT-4进行具有挑战性的数学问题求解的实证研究},
author={Yiran Wu and Feiran Jia and Shaokun Zhang and Hangyu Li and Erkang Zhu and Yue Wang and Yin Tat Lee and Richard Peng and Qingyun Wu and Chi Wang},
year={2023},
booktitle={ArXiv预印本arXiv:2306.01337},
}
```



--------------------------------------------------------------------------------
助手 (to ragproxyagent):

FLAML的作者是王驰,吴庆云,Markus Weimer和朱尔康。
``` text
ChatResult(chat_id=None, chat_history=[{'content': "You're a retrieve augmented coding assistant. You answer user's questions based on your own knowledge and the\ncontext provided by the user.\nIf you can't answer the question with or without the current context, you should reply exactly `UPDATE CONTEXT`.\nFor code generation, you must obey the following rules:\nRule 1. You MUST NOT install any packages because all the packages needed are already installed.\nRule 2. You must follow the formats below to write your code:\n```language\n# your code\n```\n\nUser's question is: Who is the author of FLAML?\n\nContext is: # Research\n\nFor technical details, please check our research publications.\n\n- [FLAML: A Fast and Lightweight AutoML Library](https://www.microsoft.com/en-us/research/publication/flaml-a-fast-and-lightweight-automl-library/). Chi Wang, Qingyun Wu, Markus Weimer, Erkang Zhu. MLSys 2021.\n\n```bibtex\n@inproceedings{wang2021flaml,\n title={FLAML: A Fast and Lightweight AutoML Library},\n author={Chi Wang and Qingyun Wu and Markus Weimer and Erkang Zhu},\n year={2021},\n booktitle={MLSys},\n}\n```\n\n- [Frugal Optimization for Cost-related Hyperparameters](https://arxiv.org/abs/2005.01571). Qingyun Wu, Chi Wang, Silu Huang. AAAI 2021.\n\n```bibtex\n@inproceedings{wu2021cfo,\n title={Frugal Optimization for Cost-related Hyperparameters},\n author={Qingyun Wu and Chi Wang and Silu Huang},\n year={2021},\n booktitle={AAAI},\n}\n```\n\n- [Economical Hyperparameter Optimization With Blended Search Strategy](https://www.microsoft.com/en-us/research/publication/economical-hyperparameter-optimization-with-blended-search-strategy/). Chi Wang, Qingyun Wu, Silu Huang, Amin Saied. ICLR 2021.\n\n```bibtex\n@inproceedings{wang2021blendsearch,\n title={Economical Hyperparameter Optimization With Blended Search Strategy},\n author={Chi Wang and Qingyun Wu and Silu Huang and Amin Saied},\n year={2021},\n booktitle={ICLR},\n}\n```\n\n- [An Empirical Study on Hyperparameter Optimization for Fine-Tuning Pre-trained Language Models](https://aclanthology.org/2021.acl-long.178.pdf). Susan Xueqing Liu, Chi Wang. ACL 2021.\n\n```bibtex\n@inproceedings{liuwang2021hpolm,\n title={An Empirical Study on Hyperparameter Optimization for Fine-Tuning Pre-trained Language Models},\n author={Susan Xueqing Liu and Chi Wang},\n year={2021},\n booktitle={ACL},\n}\n```\n\n- [ChaCha for Online AutoML](https://www.microsoft.com/en-us/research/publication/chacha-for-online-automl/). Qingyun Wu, Chi Wang, John Langford, Paul Mineiro and Marco Rossi. ICML 2021.\n\n```bibtex\n@inproceedings{wu2021chacha,\n title={ChaCha for Online AutoML},\n author={Qingyun Wu and Chi Wang and John Langford and Paul Mineiro and Marco Rossi},\n year={2021},\n booktitle={ICML},\n}\n```\n\n- [Fair AutoML](https://arxiv.org/abs/2111.06495). Qingyun Wu, Chi Wang. ArXiv preprint arXiv:2111.06495 (2021).\n\n```bibtex\n@inproceedings{wuwang2021fairautoml,\n title={Fair AutoML},\n author={Qingyun Wu and Chi Wang},\n year={2021},\n booktitle={ArXiv preprint arXiv:2111.06495},\n}\n```\n\n- [Mining Robust Default Configurations for Resource-constrained AutoML](https://arxiv.org/abs/2202.09927). Moe Kayali, Chi Wang. ArXiv preprint arXiv:2202.09927 (2022).\n\n```bibtex\n@inproceedings{kayaliwang2022default,\n title={Mining Robust Default Configurations for Resource-constrained AutoML},\n author={Moe Kayali and Chi Wang},\n year={2022},\n booktitle={ArXiv preprint arXiv:2202.09927},\n}\n```\n\n- [Targeted Hyperparameter Optimization with Lexicographic Preferences Over Multiple Objectives](https://openreview.net/forum?id=0Ij9_q567Ma). Shaokun Zhang, Feiran Jia, Chi Wang, Qingyun Wu. ICLR 2023 (notable-top-5%).\n\n```bibtex\n@inproceedings{zhang2023targeted,\n title={Targeted Hyperparameter Optimization with Lexicographic Preferences Over Multiple Objectives},\n author={Shaokun Zhang and Feiran Jia and Chi Wang and Qingyun Wu},\n booktitle={International Conference on Learning Representations},\n year={2023},\n url={https://openreview.net/forum?id=0Ij9_q567Ma},\n}\n```\n\n- [Cost-Effective Hyperparameter Optimization for Large Language Model Generation Inference](https://arxiv.org/abs/2303.04673). Chi Wang, Susan Xueqing Liu, Ahmed H. Awadallah. ArXiv preprint arXiv:2303.04673 (2023).\n\n```bibtex\n@inproceedings{wang2023EcoOptiGen,\n title={Cost-Effective Hyperparameter Optimization for Large Language Model Generation Inference},\n author={Chi Wang and Susan Xueqing Liu and Ahmed H. Awadallah},\n year={2023},\n booktitle={ArXiv preprint arXiv:2303.04673},\n}\n```\n\n- [An Empirical Study on Challenging Math Problem Solving with GPT-4](https://arxiv.org/abs/2306.01337). Yiran Wu, Feiran Jia, Shaokun Zhang, Hangyu Li, Erkang Zhu, Yue Wang, Yin Tat Lee, Richard Peng, Qingyun Wu, Chi Wang. ArXiv preprint arXiv:2306.01337 (2023).\n\n```bibtex\n@inproceedings{wu2023empirical,\n title={An Empirical Study on Challenging Math Problem Solving with GPT-4},\n author={Yiran Wu and Feiran Jia and Shaokun Zhang and Hangyu Li and Erkang Zhu and Yue Wang and Yin Tat Lee and Richard Peng and Qingyun Wu and Chi Wang},\n year={2023},\n booktitle={ArXiv preprint arXiv:2306.01337},\n}\n```\n\n", 'role': 'assistant'}, {'content': 'The authors of FLAML are Chi Wang, Qingyun Wu, Markus Weimer, and Erkang Zhu.', 'role': 'user'}], summary='The authors of FLAML are Chi Wang, Qingyun Wu, Markus Weimer, and Erkang Zhu.', cost=({'total_cost': 0.04596, 'gpt-4': {'cost': 0.04596, 'prompt_tokens': 1486, 'completion_tokens': 23, 'total_tokens': 1509}}, {'total_cost': 0.04596, 'gpt-4': {'cost': 0.04596, 'prompt_tokens': 1486, 'completion_tokens': 23, 'total_tokens': 1509}}), human_input=[])
```
# 翻译专家

## 简介

翻译专家是一位精通简体中文的专业翻译,尤其擅长将专业学术论文翻译成浅显易懂的科普文章。通过将英文段落翻译成中文,翻译专家可以帮助读者更好地理解和掌握相关知识。

## 翻译规则

为了确保翻译的准确性和完整性,翻译专家遵循以下规则:

1. 不遗漏翻译任何段落,确保传达原文的事实和背景。
2. 保留原始段落格式,包括标题、列表、引用等。
3. 保留术语和公司缩写,例如 FLAC、JPEG、Microsoft、Amazon、OpenAI等。
4. 保留图片链接,确保读者可以查看相关图片。
5. 不翻译人名,以保持原汁原味。
6. 保留论文引用,例如 [20] 这样的引用。
7. 将全角括号换成半角括号,并在左括号前面加半角空格,右括号后面加半角空格。

## 翻译策略

翻译专家采用直译的策略,根据英文内容进行翻译,力求准确传达原文的意思。同时,保持原有格式和术语,以便读者更好地理解和学习相关知识。

让翻译专家来帮助您,让专业的学术论文变成浅显易懂的科普文章!