对于我们在开源课程中的第一个作业,我们的任务是为利用 LLM 的 CLI 工具制作 0.1 版本。它可以是任何类型的工具,只要它满足一组要求即可:它必须使用 OpenAI 的聊天完成功能,并且必须通过命令行参数处理和转换文件。
对于我的作业,我选择创建 Genereadme,这是一个 CLI 工具,可以为提供的源代码文件生成 README 文件。我选择做这个项目是因为编写自述文件不是我的强项之一,而且我也觉得这很麻烦。但考虑到文档的重要性,尤其是在大型项目中,开发过程中的这一步不容忽视。所以我想,为什么不做一些可以帮助我做到这一点的东西呢?
GENEREADME 是一个命令行工具,它接收文件、处理它并生成一个 README 文件,其中包含文件内容的解释或文档。该工具利用 OpenAI 聊天完成来分析文件并生成内容。
通过创建 .env 文件或通过 -a 或 --api-key 标志来提供有效的 API 密钥:
GROQ_API_KEY=API_KEY or genereadme -a API_KEY genereadme --api-key API_KEY
安装依赖项:
npm install
使用现有示例文件运行该工具或开始使用您自己的:
genereadme <files> genereadme examples/sum.js genereadme examples/createUser.js examples/sum.js
注意:该工具接受任何文件,但只会为包含代码作为内容的文件提供适当的生成结果。
使用的文件可以放在任何地方,只要提供适当的路径即可。
flag | description | usage |
---|---|---|
-v --version |
Displays the tool's name and the current version. |
genereadme -v genereadme --version |
Simply install the packages after cloning the repository
npm install
Run and generate!
genereadme examples/sum.js genereadme examples/createUser.js genereadme examples/sum.js examples/createUser.js genereadme examples/sum.js examples/createUser.js --output sample.md
The user can pass any number of files in the command line using the command genereadme 443f14d34bd583aaf9ed0e6bcab20511 c4b0635a269076a7a37ab9e2329f3009 .... The contents of these files will be processed individually to generate their README documentation.
The generated READMEs will be saved as filename_README.md to prevent any naming collision when processing multiple files.
export async function createUser(data) { const user = { Username: data.email, UserPoolId: process.env.AWS_COGNITO_POOL_ID, TemporaryPassword: data.temporaryPassword, UserAttributes: [ { Name: "email", Value: data.email, }, { Name: "name", Value: data.name, }, ], MessageAction: MessageActionType.SUPPRESS, DesiredDeliveryMediums: [DeliveryMediumType.EMAIL], }; const command = new AdminCreateUserCommand(user); try { const createRes = await cognitoClient.send(command); logger.info(`Created user: [${JSON.stringify(createRes)}]`); const addUserToGroupParams = { UserPoolId: process.env.AWS_COGNITO_POOL_ID, Username: data.email, GroupName: data.group, }; const addUserToGroupCommand = new AdminAddUserToGroupCommand(addUserToGroupParams); const addRes = await cognitoClient.send(addUserToGroupCommand); logger.info(`Added user to group: [${JSON.stringify(addRes)}]`); } catch (error) { logger.error(`Error creating user: ${error}`); throw new Error("Error creating user."); } }
It is my first time working directly with LLMs by myself, so it definitely took some time prompt engineering to get a somewhat satisfying result. However, I do know that there are still a lot that can be improved on and I'm already getting ideas on what to do and what else I can add to this project!
以上是Genereadme v 版本的详细内容。更多信息请关注PHP中文网其他相关文章!