【Agent应用】运营数据分析与决策建议

#热门开源项目推荐#

基于ERNIE Bot Agent框架实现运营数据分析与决策建议功能。

请注意!!!填入自己的token才可运行。

可以选择上传自己的数据(Excel表格),或者直接使用示例数据演示。

demo链接:https://aistudio.baidu.com/application/detail/20310

作者:AI李健

场景

企业在做运营决策时,需要花大量的时间进行数据整理与分析,而管理者面临决策时,往往对时效要求特别高,因为机会稍纵即逝。

所以,如果能让AI进行数据分析并提供决策建议,将会大大提升决策效率。

假设你是一个APP运营,你需要对APP的运营数据进行分析,并制定对应的运营计划。最终目标是制定运营计划,在此之前,你需要通过管理后台拿到用户日活跃度(DAU)、月活跃度(MAU)、用户增长、成交转化率、商品库存等多项数据,并根据自己的运营经验对这些数据进行分析。

所以我们可以简单定义两个工具,并通过ERNIE Bot Agent去调用这两个工具,达成最终的目标。

第一个工具:定义一个获取数据,并使用文心一言对数据进行分析的工具

第二个工具:定义一个根据数据分析结果输出运营决策建议的工具

技术路径规划

想要实现这个功能,我们可以分为以下几个步骤:

1.对企业数据进行预处理;

2.让大模型根据决策需求,分析出需要用到的数据;

3.调用相应的数据进行分析,并输出决策建议。

安装agent工具

使用源码安装方式

In [13]

# 从GitHub仓库克隆最新的代码
# !git clone https://github.com/PaddlePaddle/ERNIE-SDK.git
# 有时候无法下载,所以为大家准备好了ERNIE-SDK源码。

In [1]

# 首先安装Ernie Bot
!pip install ./ERNIE-SDK/erniebot

# 然后安装ERNIE Bot Agent
!pip install ./ERNIE-SDK/erniebot-agent          # 安装核心模块
#pip install './erniebot-agent/.[all]'   # 也可以加上[all]一次性安装所有模块,包括gradio等依赖库
Looking in indexes: https://mirror.baidu.com/pypi/simple/, https://mirrors.aliyun.com/pypi/simple/
Processing ./ERNIE-SDK/erniebot
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: aiohttp in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from erniebot==0.0.0.dev0) (3.9.1)
Requirement already satisfied: bce-python-sdk in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from erniebot==0.0.0.dev0) (0.8.98)
Requirement already satisfied: colorlog in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from erniebot==0.0.0.dev0) (6.8.0)
Requirement already satisfied: jsonschema>=4.19 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from erniebot==0.0.0.dev0) (4.20.0)
Requirement already satisfied: requests>=2.20 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from erniebot==0.0.0.dev0) (2.31.0)
Collecting tenacity (from erniebot==0.0.0.dev0)
  Downloading https://mirrors.aliyun.com/pypi/packages/f4/f1/990741d5bb2487d529d20a433210ffa136a367751e454214013b441c4575/tenacity-8.2.3-py3-none-any.whl (24 kB)
Requirement already satisfied: typing-extensions>=4.8.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from erniebot==0.0.0.dev0) (4.9.0)
Requirement already satisfied: attrs>=22.2.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from jsonschema>=4.19->erniebot==0.0.0.dev0) (23.1.0)
Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from jsonschema>=4.19->erniebot==0.0.0.dev0) (2023.11.2)
Requirement already satisfied: referencing>=0.28.4 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from jsonschema>=4.19->erniebot==0.0.0.dev0) (0.32.0)
Requirement already satisfied: rpds-py>=0.7.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from jsonschema>=4.19->erniebot==0.0.0.dev0) (0.15.2)
Requirement already satisfied: charset-normalizer<4,>=2 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from requests>=2.20->erniebot==0.0.0.dev0) (3.3.2)
Requirement already satisfied: idna<4,>=2.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from requests>=2.20->erniebot==0.0.0.dev0) (3.6)
Requirement already satisfied: urllib3<3,>=1.21.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from requests>=2.20->erniebot==0.0.0.dev0) (2.1.0)
Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from requests>=2.20->erniebot==0.0.0.dev0) (2023.11.17)
Requirement already satisfied: multidict<7.0,>=4.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from aiohttp->erniebot==0.0.0.dev0) (6.0.4)
Requirement already satisfied: yarl<2.0,>=1.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from aiohttp->erniebot==0.0.0.dev0) (1.9.4)
Requirement already satisfied: frozenlist>=1.1.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from aiohttp->erniebot==0.0.0.dev0) (1.4.1)
Requirement already satisfied: aiosignal>=1.1.2 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from aiohttp->erniebot==0.0.0.dev0) (1.3.1)
Requirement already satisfied: async-timeout<5.0,>=4.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from aiohttp->erniebot==0.0.0.dev0) (4.0.3)
Requirement already satisfied: pycryptodome>=3.8.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from bce-python-sdk->erniebot==0.0.0.dev0) (3.19.0)
Requirement already satisfied: future>=0.6.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from bce-python-sdk->erniebot==0.0.0.dev0) (0.18.3)
Requirement already satisfied: six>=1.4.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from bce-python-sdk->erniebot==0.0.0.dev0) (1.16.0)
Building wheels for collected packages: erniebot
  Building wheel for erniebot (pyproject.toml) ... done
  Created wheel for erniebot: filename=erniebot-0.0.0.dev0-py3-none-any.whl size=64612 sha256=f29c48de8deb040dc06ab27c7de6d4fba4d64395ba20f5403e87ed00bc2cea1f
  Stored in directory: /tmp/pip-ephem-wheel-cache-yqjfzf91/wheels/88/b6/a2/52e38ae73556a8265691c9bc06bf832c2cd5644d1402bc654f
Successfully built erniebot
Installing collected packages: tenacity, erniebot
Successfully installed erniebot-0.0.0.dev0 tenacity-8.2.3
Looking in indexes: https://mirror.baidu.com/pypi/simple/, https://mirrors.aliyun.com/pypi/simple/
Processing ./ERNIE-SDK/erniebot-agent
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: aiohttp in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from erniebot-agent==0.0.0.dev0) (3.9.1)
Requirement already satisfied: anyio in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from erniebot-agent==0.0.0.dev0) (3.7.1)
Collecting asyncio-atexit (from erniebot-agent==0.0.0.dev0)
  Downloading https://mirrors.aliyun.com/pypi/packages/65/10/d6abaefa57a52646651fd0383c056280b0853c0106229ece6bb38cd14463/asyncio_atexit-1.0.1-py3-none-any.whl (3.8 kB)
Requirement already satisfied: jinja2 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from erniebot-agent==0.0.0.dev0) (3.1.2)
Collecting langchain (from erniebot-agent==0.0.0.dev0)
  Downloading https://mirrors.aliyun.com/pypi/packages/cb/cc/684ac2410ad06957c17ffda787b7ff6c1595721c36c3b443c021e95cf998/langchain-0.1.11-py3-none-any.whl (807 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 807.5/807.5 kB 938.5 kB/s eta 0:00:0000:0100:01
Collecting openapi-spec-validator (from erniebot-agent==0.0.0.dev0)
  Downloading https://mirrors.aliyun.com/pypi/packages/2b/4d/e744fff95aaf3aeafc968d5ba7297c8cda0d1ecb8e3acd21b25adae4d835/openapi_spec_validator-0.7.1-py3-none-any.whl (38 kB)
Requirement already satisfied: tqdm in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from erniebot-agent==0.0.0.dev0) (4.66.1)
Requirement already satisfied: typing-extensions in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from erniebot-agent==0.0.0.dev0) (4.9.0)
Requirement already satisfied: pydantic>=2 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from erniebot-agent==0.0.0.dev0) (2.5.3)
Requirement already satisfied: PyYAML in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from erniebot-agent==0.0.0.dev0) (6.0.1)
Requirement already satisfied: annotated-types>=0.4.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from pydantic>=2->erniebot-agent==0.0.0.dev0) (0.6.0)
Requirement already satisfied: pydantic-core==2.14.6 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from pydantic>=2->erniebot-agent==0.0.0.dev0) (2.14.6)
Requirement already satisfied: attrs>=17.3.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from aiohttp->erniebot-agent==0.0.0.dev0) (23.1.0)
Requirement already satisfied: multidict<7.0,>=4.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from aiohttp->erniebot-agent==0.0.0.dev0) (6.0.4)
Requirement already satisfied: yarl<2.0,>=1.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from aiohttp->erniebot-agent==0.0.0.dev0) (1.9.4)
Requirement already satisfied: frozenlist>=1.1.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from aiohttp->erniebot-agent==0.0.0.dev0) (1.4.1)
Requirement already satisfied: aiosignal>=1.1.2 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from aiohttp->erniebot-agent==0.0.0.dev0) (1.3.1)
Requirement already satisfied: async-timeout<5.0,>=4.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from aiohttp->erniebot-agent==0.0.0.dev0) (4.0.3)
Requirement already satisfied: idna>=2.8 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from anyio->erniebot-agent==0.0.0.dev0) (3.6)
Requirement already satisfied: sniffio>=1.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from anyio->erniebot-agent==0.0.0.dev0) (1.3.0)
Requirement already satisfied: exceptiongroup in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from anyio->erniebot-agent==0.0.0.dev0) (1.2.0)
Requirement already satisfied: MarkupSafe>=2.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from jinja2->erniebot-agent==0.0.0.dev0) (2.1.3)
Collecting SQLAlchemy<3,>=1.4 (from langchain->erniebot-agent==0.0.0.dev0)
  Downloading https://mirrors.aliyun.com/pypi/packages/15/a6/ffe06d6d70ffa9e678302f11428030761b7b7e91bd9cb797701d9fdb97ad/SQLAlchemy-2.0.28-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.1 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.1/3.1 MB 1.5 MB/s eta 0:00:0000:0100:01
Collecting dataclasses-json<0.7,>=0.5.7 (from langchain->erniebot-agent==0.0.0.dev0)
  Downloading https://mirrors.aliyun.com/pypi/packages/91/ca/7219b838086086972e662c19e908694bdc6744537fb41b70392501b8b5e4/dataclasses_json-0.6.4-py3-none-any.whl (28 kB)
Collecting jsonpatch<2.0,>=1.33 (from langchain->erniebot-agent==0.0.0.dev0)
  Downloading https://mirrors.aliyun.com/pypi/packages/73/07/02e16ed01e04a374e644b575638ec7987ae846d25ad97bcc9945a3ee4b0e/jsonpatch-1.33-py2.py3-none-any.whl (12 kB)
Collecting langchain-community<0.1,>=0.0.25 (from langchain->erniebot-agent==0.0.0.dev0)
  Downloading https://mirrors.aliyun.com/pypi/packages/8d/cc/387b93205020d23151c039e73805062c749a452a417fc578c7ea69efd469/langchain_community-0.0.27-py3-none-any.whl (1.8 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.8/1.8 MB 2.2 MB/s eta 0:00:00a 0:00:01
Collecting langchain-core<0.2,>=0.1.29 (from langchain->erniebot-agent==0.0.0.dev0)
  Downloading https://mirrors.aliyun.com/pypi/packages/53/b3/ae022560a8b104525b4ac1a97a557e3aa05dd0d233bb5284f7c63509742f/langchain_core-0.1.30-py3-none-any.whl (256 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 256.9/256.9 kB 2.3 MB/s eta 0:00:0000:0100:01
Collecting langchain-text-splitters<0.1,>=0.0.1 (from langchain->erniebot-agent==0.0.0.dev0)
  Downloading https://mirrors.aliyun.com/pypi/packages/9d/a1/aec824080111e9b4a4802b51b988032faa193828c865e11233d1b18e88fa/langchain_text_splitters-0.0.1-py3-none-any.whl (21 kB)
Collecting langsmith<0.2.0,>=0.1.17 (from langchain->erniebot-agent==0.0.0.dev0)
  Downloading https://mirrors.aliyun.com/pypi/packages/ec/cf/dccbfcf35f33dcb356b0168a851342339c7e79cec5a2e6f4e045fc3aee53/langsmith-0.1.22-py3-none-any.whl (66 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 66.6/66.6 kB 2.2 MB/s eta 0:00:00
Requirement already satisfied: numpy<2,>=1 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from langchain->erniebot-agent==0.0.0.dev0) (1.26.2)
Requirement already satisfied: requests<3,>=2 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from langchain->erniebot-agent==0.0.0.dev0) (2.31.0)
Requirement already satisfied: tenacity<9.0.0,>=8.1.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from langchain->erniebot-agent==0.0.0.dev0) (8.2.3)
Requirement already satisfied: jsonschema<5.0.0,>=4.18.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from openapi-spec-validator->erniebot-agent==0.0.0.dev0) (4.20.0)
Collecting jsonschema-path<0.4.0,>=0.3.1 (from openapi-spec-validator->erniebot-agent==0.0.0.dev0)
  Downloading https://mirrors.aliyun.com/pypi/packages/7f/5a/f405ced79c55191e460fc6d17a14845fddf09f601e39cfcab28cc1d3ff1c/jsonschema_path-0.3.2-py3-none-any.whl (14 kB)
Collecting lazy-object-proxy<2.0.0,>=1.7.1 (from openapi-spec-validator->erniebot-agent==0.0.0.dev0)
  Downloading https://mirrors.aliyun.com/pypi/packages/8b/fc/83711d743fb5aaca5747bbf225fe3b5cbe085c7f6c115856b5cce80f3224/lazy_object_proxy-1.10.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (68 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 68.3/68.3 kB 2.3 MB/s eta 0:00:00
Collecting openapi-schema-validator<0.7.0,>=0.6.0 (from openapi-spec-validator->erniebot-agent==0.0.0.dev0)
  Downloading https://mirrors.aliyun.com/pypi/packages/b3/dc/9aefae8891454130968ff079ece851d1ae9ccf6fb7965761f47c50c04853/openapi_schema_validator-0.6.2-py3-none-any.whl (8.8 kB)
Collecting marshmallow<4.0.0,>=3.18.0 (from dataclasses-json<0.7,>=0.5.7->langchain->erniebot-agent==0.0.0.dev0)
  Downloading https://mirrors.aliyun.com/pypi/packages/38/04/37055b7013dfaaf66e3a9a51e46857cc9be151476a891b995fa70da7e139/marshmallow-3.21.1-py3-none-any.whl (49 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 49.4/49.4 kB 2.6 MB/s eta 0:00:00
Collecting typing-inspect<1,>=0.4.0 (from dataclasses-json<0.7,>=0.5.7->langchain->erniebot-agent==0.0.0.dev0)
  Downloading https://mirrors.aliyun.com/pypi/packages/65/f3/107a22063bf27bdccf2024833d3445f4eea42b2e598abfbd46f6a63b6cb0/typing_inspect-0.9.0-py3-none-any.whl (8.8 kB)
Collecting jsonpointer>=1.9 (from jsonpatch<2.0,>=1.33->langchain->erniebot-agent==0.0.0.dev0)
  Downloading https://mirrors.aliyun.com/pypi/packages/12/f6/0232cc0c617e195f06f810534d00b74d2f348fe71b2118009ad8ad31f878/jsonpointer-2.4-py2.py3-none-any.whl (7.8 kB)
Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from jsonschema<5.0.0,>=4.18.0->openapi-spec-validator->erniebot-agent==0.0.0.dev0) (2023.11.2)
Requirement already satisfied: referencing>=0.28.4 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from jsonschema<5.0.0,>=4.18.0->openapi-spec-validator->erniebot-agent==0.0.0.dev0) (0.32.0)
Requirement already satisfied: rpds-py>=0.7.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from jsonschema<5.0.0,>=4.18.0->openapi-spec-validator->erniebot-agent==0.0.0.dev0) (0.15.2)
Collecting pathable<0.5.0,>=0.4.1 (from jsonschema-path<0.4.0,>=0.3.1->openapi-spec-validator->erniebot-agent==0.0.0.dev0)
  Downloading https://mirrors.aliyun.com/pypi/packages/5b/0a/acfb251ba01009d3053f04f4661e96abf9d485266b04a0a4deebc702d9cb/pathable-0.4.3-py3-none-any.whl (9.6 kB)
Collecting referencing>=0.28.4 (from jsonschema<5.0.0,>=4.18.0->openapi-spec-validator->erniebot-agent==0.0.0.dev0)
  Downloading https://mirrors.aliyun.com/pypi/packages/ec/d8/e826b3f743d97e45d3ace674a5c6f026069428e608c5fde3d08d072c87f2/referencing-0.31.1-py3-none-any.whl (25 kB)
Requirement already satisfied: packaging<24.0,>=23.2 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from langchain-core<0.2,>=0.1.29->langchain->erniebot-agent==0.0.0.dev0) (23.2)
Collecting orjson<4.0.0,>=3.9.14 (from langsmith<0.2.0,>=0.1.17->langchain->erniebot-agent==0.0.0.dev0)
  Downloading https://mirrors.aliyun.com/pypi/packages/3f/22/8b8eba5adfcb5be89c85d74fc8e08b0913ebca264cfa7cbb3ffb7d1840c6/orjson-3.9.15-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (138 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 138.5/138.5 kB 2.4 MB/s eta 0:00:00a 0:00:01
Collecting rfc3339-validator (from openapi-schema-validator<0.7.0,>=0.6.0->openapi-spec-validator->erniebot-agent==0.0.0.dev0)
  Downloading https://mirrors.aliyun.com/pypi/packages/7b/44/4e421b96b67b2daff264473f7465db72fbdf36a07e05494f50300cc7b0c6/rfc3339_validator-0.1.4-py2.py3-none-any.whl (3.5 kB)
Requirement already satisfied: charset-normalizer<4,>=2 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from requests<3,>=2->langchain->erniebot-agent==0.0.0.dev0) (3.3.2)
Requirement already satisfied: urllib3<3,>=1.21.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from requests<3,>=2->langchain->erniebot-agent==0.0.0.dev0) (2.1.0)
Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from requests<3,>=2->langchain->erniebot-agent==0.0.0.dev0) (2023.11.17)
Collecting greenlet!=0.4.17 (from SQLAlchemy<3,>=1.4->langchain->erniebot-agent==0.0.0.dev0)
  Downloading https://mirrors.aliyun.com/pypi/packages/24/35/945d5b10648fec9b20bcc6df8952d20bb3bba76413cd71c1fdbee98f5616/greenlet-3.0.3-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (616 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 616.0/616.0 kB 2.0 MB/s eta 0:00:00a 0:00:01
Collecting mypy-extensions>=0.3.0 (from typing-inspect<1,>=0.4.0->dataclasses-json<0.7,>=0.5.7->langchain->erniebot-agent==0.0.0.dev0)
  Downloading https://mirrors.aliyun.com/pypi/packages/2a/e2/5d3f6ada4297caebe1a2add3b126fe800c96f56dbe5d1988a2cbe0b267aa/mypy_extensions-1.0.0-py3-none-any.whl (4.7 kB)
Requirement already satisfied: six in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from rfc3339-validator->openapi-schema-validator<0.7.0,>=0.6.0->openapi-spec-validator->erniebot-agent==0.0.0.dev0) (1.16.0)
Building wheels for collected packages: erniebot-agent
  Building wheel for erniebot-agent (pyproject.toml) ... done
  Created wheel for erniebot-agent: filename=erniebot_agent-0.0.0.dev0-py3-none-any.whl size=114819 sha256=5673d1d77c29aa25e27d23aacc729cc62779732794244f7a929f3d7f37252572
  Stored in directory: /home/aistudio/.cache/pip/wheels/21/2a/0b/6ff4dd602862d1d8ca2c11b015c219c346a3f22b660816211c
Successfully built erniebot-agent
Installing collected packages: rfc3339-validator, referencing, pathable, orjson, mypy-extensions, marshmallow, lazy-object-proxy, jsonpointer, greenlet, asyncio-atexit, typing-inspect, SQLAlchemy, jsonschema-path, jsonpatch, langsmith, dataclasses-json, openapi-schema-validator, langchain-core, openapi-spec-validator, langchain-text-splitters, langchain-community, langchain, erniebot-agent
  Attempting uninstall: referencing
    Found existing installation: referencing 0.32.0
    Uninstalling referencing-0.32.0:
      Successfully uninstalled referencing-0.32.0
  Attempting uninstall: orjson
    Found existing installation: orjson 3.9.10
    Uninstalling orjson-3.9.10:
      Successfully uninstalled orjson-3.9.10
Successfully installed SQLAlchemy-2.0.28 asyncio-atexit-1.0.1 dataclasses-json-0.6.4 erniebot-agent-0.0.0.dev0 greenlet-3.0.3 jsonpatch-1.33 jsonpointer-2.4 jsonschema-path-0.3.2 langchain-0.1.11 langchain-community-0.0.27 langchain-core-0.1.30 langchain-text-splitters-0.0.1 langsmith-0.1.22 lazy-object-proxy-1.10.0 marshmallow-3.21.1 mypy-extensions-1.0.0 openapi-schema-validator-0.6.2 openapi-spec-validator-0.7.1 orjson-3.9.15 pathable-0.4.3 referencing-0.31.1 rfc3339-validator-0.1.4 typing-inspect-0.9.0

pip安装方式

In [15]

# 安装agent核心模块
# !pip install --upgrade erniebot-agent
# 安装文心agent所有模块
# !pip install --upgrade erniebot-agent[all]

引入相关包并配置自己的token

In [6]

import os

os.environ["EB_AGENT_LOGGING_LEVEL"] = "INFO"  #  这个是日志包
os.environ["EB_AGENT_ACCESS_TOKEN"] = "输入你自己的token"  #  这是星河社区的token(令牌)输入你自己的token

import asyncio

from pydantic import Field
from typing import Dict, Type, Any

from erniebot_agent.chat_models import ERNIEBot
from erniebot_agent.memory import HumanMessage, SlidingWindowMemory, WholeMemory
from erniebot_agent.tools.base import Tool
from erniebot_agent.tools.schema import ToolParameterView
from erniebot_agent.agents import FunctionAgent
from erniebot_agent.tools import RemoteToolkit
from erniebot_agent.file import GlobalFileManagerHandler

数据预处理:以Excel表格为示例

演示使用的表格处理方式有上下文长度限制,仅支持大模型的输入长度。

如果要取消限制,需要更复杂的操作。

In [3]

# 安装必要库
!pip install pandas openpyxl
Looking in indexes: https://mirror.baidu.com/pypi/simple/, https://mirrors.aliyun.com/pypi/simple/
Requirement already satisfied: pandas in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (2.1.4)
Requirement already satisfied: openpyxl in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (3.1.2)
Requirement already satisfied: numpy<2,>=1.22.4 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from pandas) (1.26.2)
Requirement already satisfied: python-dateutil>=2.8.2 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from pandas) (2.8.2)
Requirement already satisfied: pytz>=2020.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from pandas) (2023.3.post1)
Requirement already satisfied: tzdata>=2022.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from pandas) (2023.3)
Requirement already satisfied: et-xmlfile in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from openpyxl) (1.1.0)
Requirement already satisfied: six>=1.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from python-dateutil>=2.8.2->pandas) (1.16.0)

In [4]

# 处理数据
import pandas as pd  

def get_data(excel_file):  
    # 读取Excel文件  
    df = pd.read_excel(excel_file)  
      
    # 初始化一个空列表来存储拼接后的数据  
    concatenated_data = []  
      
    # 获取标题(列名)  
    headers = df.columns.tolist()  
      
    # 遍历数据帧的每一行  
    for index, row in df.iterrows():  
        # 初始化一个空列表来存储当前行的拼接数据  
        row_data = []  
          
        # 拼接当前行的数据与标题  
        for header, value in zip(headers, row):  
            row_data.append(f"{header}:{value}")  
          
        # 将当前行的拼接数据添加到总列表中  
        concatenated_data.append(row_data)  
      
    # 返回拼接好的数据列表  
    return concatenated_data  
  
# 使用函数并打印结果  
excel_file = '运营数据演示.xlsx'  
data = get_data(excel_file)  
for row in data:  
    print('\n'.join(row))  
    print()  # 打印空行分隔不同行的数据
日期:2024-03-01 00:00:00
用户总数:153001
日活跃用户:12580
成交用户数:998
商品库存:5213

日期:2024-03-02 00:00:00
用户总数:153225
日活跃用户:10086
成交用户数:888
商品库存:4325

日期:2024-03-03 00:00:00
用户总数:153319
日活跃用户:9988
成交用户数:666
商品库存:3659

日期:2024-03-04 00:00:00
用户总数:153400
日活跃用户:9527
成交用户数:555
商品库存:3104

日期:2024-03-05 00:00:00
用户总数:153426
日活跃用户:9319
成交用户数:501
商品库存:2603

日期:2024-03-06 00:00:00
用户总数:153499
日活跃用户:9268
成交用户数:408
商品库存:2195

日期:2024-03-07 00:00:00
用户总数:153666
日活跃用户:9528
成交用户数:525
商品库存:1670

定义agent工具

第一个工具:定义一个获取数据,并使用文心一言对数据进行分析的工具

In [7]

# 第一个类其实就是描述这个工具接受的参数。需要注意的是,咱们需要继承官方给的类:ToolParameterView
class GetDataInputView(ToolParameterView):
    need: str = Field(description="数据分析需求")

# 第二个类就是描述response这个变量,这是这个工具输出的参数。
class GetDataOutputView(ToolParameterView):
    response: str = Field(description="数据分析结果")

# 第三个类将输入和输出,以及工具的描述组合起来,调用文心大模型实现对数据的分析等
# 这里也可以不调用大模型,而是调用传统的业务代码,可以任意组合,输出结果由自己控制
class GetData(Tool):
    description: str = "GetData是一款分析运营数据的工具"
    input_type: Type[ToolParameterView] = GetDataInputView
    ouptut_type: Type[ToolParameterView] = GetDataOutputView

    def __init__(self, llm: ERNIEBot):
        self.llm = llm

    async def __call__(self, need: str) -> Dict[str, str]:
        form = data
        prompt = f"请根据{need}对{form}中的运营数据进行分析,请一步一步认真思考,给出专业的数据分析结果。"
        response = await self.llm.chat([HumanMessage(prompt)])
        return {"response": response.content}

# 这是设置大模型的角色,按官方的方式设置就行了,没啥可多讲的
SYSTEM_MESSAGE = "你是一个数据分析专家,请根据数据分析需求,输出专业的数据分析结果。"
llm = ERNIEBot(model="ernie-4.0", system=SYSTEM_MESSAGE)
# 将这个工具实例化,等待调用
data_tool = GetData(llm)

第二个工具:定义一个根据数据分析结果输出运营决策建议的工具

In [14]

# 和第一个工具一样的方法,在此不赘述
class GetPlanInputView(ToolParameterView):
    recommendation: str = Field(description="数据分析结果")

class GetPlanOutputView(ToolParameterView):
    response: str = Field(description="运营决策建议")

class GetPlan(Tool):
    description: str = "GetPlan是一款根据数据分析结果输出运营决策建议的工具"
    input_type: Type[ToolParameterView] = GetPlanInputView
    ouptut_type: Type[ToolParameterView] = GetPlanOutputView

    def __init__(self, llm: ERNIEBot):
        self.llm = llm

    async def __call__(self, recommendation: str) -> Dict[str, str]:
        prompt = f"请根据数据分析结果:\n{recommendation}\n输出运营决策建议,请一步一步思考后输出结果。"
        response = await self.llm.chat([HumanMessage(prompt)])
        return {"response": response.content}

SYSTEM_MESSAGE = "你是一个运营专家,你的任务是根据用户需求和数据分析结果输出运营决策建议。请注意,你只需要输出运营决策建议,不要输出多余的解释。"
llm = ERNIEBot(model="ernie-4.0", system=SYSTEM_MESSAGE)
# 将这个工具实例化,等待调用
plan_tool = GetPlan(llm)

创建Agent

In [12]

# 参数解释:
# model是你想调用的模型,比如ernie-4.0就是调用文心4.0,需要注意的是,EB-SDK更新后,模型名称也发生了变化,以前调用文心4.0是ernie-bot-4

# llm就是你刚才定义的模型

# tools就是上面定义的三个工具,需要以列表格式传入

# memory就是管理对话记录的包(也叫大模型的记忆体),ERNIE Bot Agen目前提供了3种记忆管理方式:
# WholeMemory:全量记忆功能,存储所有消息。
# SlidingWindowMemory:滑窗截断消息,限制对话轮数。 max_round就是你想保留的对话记录轮数
# LimitTokensMemory:Token限制memory,限制对话memory中的token数量。

# max_steps就是控制agent的最大执行轮数,万一遇到一个问题大模型解决不了,不至于一直循环

memory = SlidingWindowMemory(max_round=5)
llm_final = ERNIEBot(model="ernie-4.0", api_type="aistudio", enable_multi_step_tool_call=True)
agent_all = FunctionAgent(llm=llm_final, tools=[data_tool, plan_tool], memory=memory, max_steps=5)

调用Agent

发出指令,文心大模型会自动调用之前定义好的工具,获得想要的结果

In [13]

response = await agent_all.run("请根据3月7号的运营数据制定运营计划")
print(response.text)
INFO - [Run][Start] FunctionAgent is about to start running with input:
请根据3月7号的运营数据制定运营计划
INFO - [LLM][Start] ERNIEBot is about to start running with input:
 role: user 
 content: 请根据3月7号的运营数据制定运营计划 
INFO - [LLM][End] ERNIEBot finished running with output:
 role: assistant 
 function_call: 
{
  "name": "GetData",
  "thoughts": "用户需要我根据3月7号的运营数据制定运营计划,我需要先获取到3月7号的运营数据,然后根据运营数据制定运营计划。任务拆解:[sub-task1: 使用[GetData]工具获取3月7号的运营数据,sub-task2: 使用[GetPlan]工具根据获取的运营数据制定运营计划]。接下来我需要调用[GetData]工具来获取3月7号的运营数据。",
  "arguments": "{\"need\":\"3月7号的运营数据\"}"
} 
INFO - [Tool][Start] GetData is about to start running with input:
{
  "need": "3月7号的运营数据"
}
INFO - [Tool][End] GetData finished running with output:
{
  "response": "首先,我们来看看给出的数据集,它包含了从2024年3月1日到2024年3月7日的运营数据,主要包括用户总数、日活跃用户、成交用户数和商品库存四个关键指标。\n\n第一步,我们先对这些数据进行一个简单的概述。在这七天内,用户总数从153001增长到153666,日活跃用户数在9000-13000之间波动,成交用户数从998下降到408后又回升到525,商品库存则从5213下降到1670。\n\n第二步,我们进一步分析这些数据的变化趋势。用户总数在这七天内持续增长,但增长速度逐渐放缓。日活跃用户数在前五天持续下滑,但在3月7日有所回升。成交用户数的变化趋势与日活跃用户数相似,也是在下滑后出现了回升。商品库存则在这七天内持续下降,且下降速度逐渐加快。\n\n第三步,我们尝试找出这些数据变化的可能原因。用户总数的持续增长可能说明我们的产品或服务在这段时间内有一定的吸引力,不断有新的用户加入。日活跃用户数和成交用户数的下滑可能说明我们的产品或服务在这段时间内对用户的吸引力有所下降,或者存在竞争对手的影响。而这两者在3月7日的回升可能说明我们采取的一些改进措施开始产生效果。商品库存的持续下降可能说明我们的销售情况良好,但也需要注意及时补充库存,以避免影响后续的销售。\n\n第四步,基于以上的分析,我们可以提出一些建议。首先,我们需要继续提升产品或服务的吸引力,以吸引更多的新用户并保持老用户的活跃度。其次,我们需要关注竞争对手的动态,及时调整我们的策略以应对可能的竞争压力。再次,我们需要根据销售情况及时调整库存,以确保后续的销售不受影响。最后,我们需要继续监控这些数据的变化趋势,以便及时发现问题并采取相应的措施。\n\n以上就是对这七天运营数据的专业分析结果。希望这些信息能对你有所帮助。"
}
INFO - [LLM][Start] ERNIEBot is about to start running with input:
 role: function 
 name: GetData 
 content: {"response": "首先,我们来看看给出的数据集,它包含了从2024年3月1日到2024年3月7日的运营数据,主要包括用户总数、日活跃用户、成交用户数和商品库存四个关键指标。\n\n第一步,我... 
INFO - [LLM][End] ERNIEBot finished running with output:
 role: assistant 
 function_call: 
{
  "name": "GetPlan",
  "thoughts": "我已经获取到了3月7号的运营数据,接下来我需要根据这些运营数据制定运营计划。现在我需要调用[GetPlan]工具来生成运营计划。",
  "arguments": "{\"recommendation\":\"首先,我们来看看给出的数据集,它包含了从2024年3月1日到2024年3月7日的运营数据,主要包括用户总数、日活跃用户、成交用户数和商品库存四个关键指标。\\n\\n第一步,我们先对这些数据进行一个简单的概述。在这七天内,用户总数从153001增长到153666,日活跃用户数在9000-13000之间波动,成交用户数从998下降到408后又回升到525,商品库存则从5213下降到1670。\\n\\n第二步,我们进一步分析这些数据的变化趋势。用户总数在这七天内持续增长,但增长速度逐渐放缓。日活跃用户数在前五天持续下滑,但在3月7日有所回升。成交用户数的变化趋势与日活跃用户数相似,也是在下滑后出现了回升。商品库存则在这七天内持续下降,且下降速度逐渐加快。\\n\\n第三步,我们尝试找出这些数据变化的可能原因。用户总数的持续增长可能说明我们的产品或服务在这段时间内有一定的吸引力,不断有新的用户加入。日活跃用户数和成交用户数的下滑可能说明我们的产品或服务在这段时间内对用户的吸引力有所下降,或者存在竞争对手的影响。而这两者在3月7日的回升可能说明我们采取的一些改进措施开始产生效果。商品库存的持续下降可能说明我们的销售情况良好,但也需要注意及时补充库存,以避免影响后续的销售。\\n\\n第四步,基于以上的分析,我们可以提出一些建议。首先,我们需要继续提升产品或服务的吸引力,以吸引更多的新用户并保持老用户的活跃度。其次,我们需要关注竞争对手的动态,及时调整我们的策略以应对可能的竞争压力。再次,我们需要根据销售情况及时调整库存,以确保后续的销售不受影响。最后,我们需要继续监控这些数据的变化趋势,以便及时发现问题并采取相应的措施。\\n\\n以上就是对这七天运营数据的专业分析结果。希望这些信息能对你有所帮助。\"}"
} 
INFO - [Tool][Start] GetPlan is about to start running with input:
{
  "recommendation": "首先,我们来看看给出的数据集,它包含了从2024年3月1日到2024年3月7日的运营数据,主要包括用户总数、日活跃用户、成交用户数和商品库存四个关键指标。\n\n第一步,我们先对这些数据进行一个简单的概述。在这七天内,用户总数从153001增长到153666,日活跃用户数在9000-13000之间波动,成交用户数从998下降到408后又回升到525,商品库存则从5213下降到1670。\n\n第二步,我们进一步分析这些数据的变化趋势。用户总数在这七天内持续增长,但增长速度逐渐放缓。日活跃用户数在前五天持续下滑,但在3月7日有所回升。成交用户数的变化趋势与日活跃用户数相似,也是在下滑后出现了回升。商品库存则在这七天内持续下降,且下降速度逐渐加快。\n\n第三步,我们尝试找出这些数据变化的可能原因。用户总数的持续增长可能说明我们的产品或服务在这段时间内有一定的吸引力,不断有新的用户加入。日活跃用户数和成交用户数的下滑可能说明我们的产品或服务在这段时间内对用户的吸引力有所下降,或者存在竞争对手的影响。而这两者在3月7日的回升可能说明我们采取的一些改进措施开始产生效果。商品库存的持续下降可能说明我们的销售情况良好,但也需要注意及时补充库存,以避免影响后续的销售。\n\n第四步,基于以上的分析,我们可以提出一些建议。首先,我们需要继续提升产品或服务的吸引力,以吸引更多的新用户并保持老用户的活跃度。其次,我们需要关注竞争对手的动态,及时调整我们的策略以应对可能的竞争压力。再次,我们需要根据销售情况及时调整库存,以确保后续的销售不受影响。最后,我们需要继续监控这些数据的变化趋势,以便及时发现问题并采取相应的措施。\n\n以上就是对这七天运营数据的专业分析结果。希望这些信息能对你有所帮助。"
}
INFO - [Tool][End] GetPlan finished running with output:
{
  "response": "运营决策建议:\n\n1. **用户增长策略**:\n   - 鉴于用户总数持续增长但速度放缓,建议启动新一轮的用户获取活动,如优惠促销、推荐奖励等,以加速用户增长。\n   - 同时,考虑通过用户调研了解新用户加入的主要动机,优化产品或服务以满足这些需求。\n\n2. **活跃度和成交提升**:\n   - 针对日活跃用户数和成交用户数的下滑及后续回升,建议深入分析回升原因,并扩大这些有效措施的影响。\n   - 推出面向不活跃用户的召回活动,如定向推送优惠券、内容更新通知等。\n   - 优化购物流程,减少用户从浏览到成交的摩擦,提升转化率。\n\n3. **库存管理**:\n   - 鉴于商品库存持续下降,建议建立更为精确的库存预测模型,以便及时补充库存,防止缺货情况发生。\n   - 考虑与供应商建立更紧密的合作关系,确保在库存低位时能够快速补货。\n\n4. **竞争策略调整**:\n   - 加强对竞争对手的监测和分析,了解其产品、价格、促销等策略,以便及时调整自身策略保持竞争优势。\n   - 根据竞争对手的动态,考虑是否启动价格战、增值服务提供等策略来应对。\n\n5. **数据持续监控**:\n   - 建立数据监控仪表盘,实时监控关键指标的变化,并设置预警机制,以便在数据出现异常时能够迅速响应。\n   - 定期进行数据复盘和分析,不断优化运营策略,确保与业务目标保持一致。"
}
INFO - [LLM][Start] ERNIEBot is about to start running with input:
 role: function 
 name: GetPlan 
 content: {"response": "运营决策建议:\n\n1. **用户增长策略**:\n   - 鉴于用户总数持续增长但速度放缓,建议启动新一轮的用户获取活动,如优惠促销、推荐奖励等,以加速用户增长。\n ... 
INFO - [LLM][End] ERNIEBot finished running with output:
 role: assistant 
 content: 根据您提供的3月7号的运营数据,我们为您制定了以下运营决策建议:

1. **用户增长策略**:
   - 鉴于用户总数持续增长但速度放缓,我们建议启动新一轮的用户获取活动,例如优惠促销和推荐奖励等,... 
INFO - [Run][End] FunctionAgent finished running.
根据您提供的3月7号的运营数据,我们为您制定了以下运营决策建议:

1. **用户增长策略**:
   - 鉴于用户总数持续增长但速度放缓,我们建议启动新一轮的用户获取活动,例如优惠促销和推荐奖励等,这些措施将有助于加速用户增长。
   - 同时,我们建议您通过用户调研了解新用户的主要需求,并据此优化产品或服务,以确保新用户能够更好地满足他们的期望。

2. **活跃度和成交提升**:
   - 对于日活跃用户数和成交用户数的先下滑后回升的情况,我们建议深入分析导致回升的因素,并进一步扩大这些有效措施的影响范围。
   - 您可以考虑推出一些面向不活跃用户的召回活动,比如发送定向的优惠券和内容更新通知等,以重新激活这部分用户。
   - 优化购物流程以减少用户从浏览到成交的摩擦也是提升成交用户数的有效手段。

3. **库存管理**:
   - 鉴于商品库存的持续下降情况,我们建议您建立一个更为精确的库存预测模型来预测未来的需求,并及时补充库存以避免缺货的风险。
   - 此外,与供应商建立更紧密的合作关系也将有助于确保在库存低位时能够及时补货。

4. **竞争策略调整**:
   - 我们建议您加强对竞争对手的监测和分析工作,了解其产品、价格、促销等策略,并根据这些信息及时调整自身的运营策略以保持竞争优势。
   - 根据竞争对手的动态变化,您可以考虑是否采取价格战、增值服务提供等策略来应对竞争压力。

5. **数据持续监控**:
   - 最后,建立一个数据监控仪表盘来实时监控关键指标的变化情况是非常重要的。设置预警机制可以帮助您在数据出现异常时迅速作出反应。
   - 定期进行数据复盘和分析也是必不可少的环节,它可以帮助您不断优化运营策略并确保与业务目标保持一致。


  • 12
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

军哥说AI

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值