CrewAI 提供了简单的命令行工具,可以帮助用户快速创建一个 CrewAI 应用。
整个过程非常丝滑。语法结构巨巨巨很简单:
crewai[COMMAND][OPTIONS][ARGUMENTS]
创建一个全新的 CrewAI 应用,包含如下几个主要的步骤:
只需要将 Terminal 切换到 crew 环境和工作路径下,输入该指令即可。
crewaicreatecrewknowledge_example
系统显示让我们选择大模型供应商。这段时间我用惯了便宜又大碗的 DeepSeek,经过两轮选择后,惊喜的发现,CrewAI 支持 DeepSeek。
结果,当我开开心心的选择17,这家伙告诉我,没有 API keys。哎,算了, .env 文件,姐姐自己创建吧。
deepseek 大模型配置的.env文件格式参考如下,大家需要对应替换自己的 api-key。
DEEPSEEK_API_KEY="替换成您的 api-key"
DEEPSEEK_API_BASE=https://api.deepseek.com/v1不过,CrewAI 的命令行创建 Crew 项目的效率是真高!
很快的,就可以在工作文件路径下看到这样的一系列文件夹和文件。
这个项目指令自动构建了一个项目需要的几个核心部分框架。包含:
开始之间,老样子,我们用 Cursor 打开项目文件夹,点开 README.md,看一下出厂设置。
开始是一些欢迎语句和安装方法,因为这一步咱肯定是完成的了,否则,也没办法通过命令行创建项目,这些就忽略。
接下来是最实用的初始化指南,我把过程和用途备注到注释里了。
### Customizing
**Add your `OPENAI_API_KEY` into the `.env` file**#创建.env文件,配置大模型 api-key
- Modify `src/knowledge_example/config/agents.yaml` to define your agents#定义代理
- Modify `src/knowledge_example/config/tasks.yaml` to define your tasks#定义任务
- Modify `src/knowledge_example/crew.py` to add your own logic, toolsandspecific args#添加代理工作逻辑、工具和特殊的参数
- Modify `src/knowledge_example/main.py` to add custom inputsforyour agentsandtasks
#定义和修改代理的input和output然后就是运行了
## Running the Project
To kickstart your crew of AI agentsandbegin task execution, run thisfromthe root folder of your project:
```bash
$ crewai run
```
This command initializes the knowledge_example Crew, assembling the agentsandassigning them tasksasdefinedinyour configuration.
This example, unmodified, will run the create a `report.md` filewiththe output of a research on LLMsinthe root folder.
但是,模板默认配置的 main.py 只定义了几个函数(run(), train(), replay(), test()),但没有实际调用这些函数。需要添加一个入口点来执行这些函数,修改 main.py,在文件的最尾端添加代码:
if__name__ =="__main__":
# 默认执行 run() 函数
print("Starting the program...")
run()
print("
rogram finished.")好了,试着跑一下。系统提示报错。提醒 api_key 应用没有设置成功。
这说明 deepseek llm 没有配置完成。在 main.py 函数里增加这段代码:
fromlangchain_openaiimportChatOpenAI
fromdotenvimportload_dotenv
importos
# 加载环境变量
load_dotenv()
# 初始化 LLM,使用 Deepseek API
llm = ChatOpenAI(
api_key=os.getenv('DEEPSEEK_API_KEY'),
base_url=os.getenv('DEEPSEEK_API_BASE'),
model_name="deepseek/deepseek-chat",
temperature=0.7,
)好的,再执行一次。执行成功了。
以上就是使用 CrewAI 命令行创建一个完整项目框架,然后,再进行 llm 配置,实现 MultiAgents项目能成功跑通的全部介绍了。
| 欢迎光临 链载Ai (https://www.lianzai.com/) | Powered by Discuz! X3.5 |