LLMCheatsheets.jl是一个 Julia 软件包,通过从 GitHub 存储库创建备忘单,可以轻松、即时地向 AI 模型教授新软件包和存储库。该工具弥合了人类可读文档和人工智能友好的知识表示之间的差距,允许与语言模型和人工智能助手无缝集成。
默认情况下,我们获取提供的存储库中的文件夹和文件的子集,并使用 LLM 将它们汇总到单个备忘单中。
要安装 LLMCheatsheets.jl,请使用 Julia 包管理器和存储库 URL(尚未注册):
using Pkg
Pkg . add (url = " https://github.com/svilupp/LLMCheatsheets.jl " )
提示
如果您在访问 GitHub API 时遇到速率限制,您可以设置个人访问令牌并将其设置为环境变量GITHUB_API_KEY
以将请求限制提高到每小时 5000 个。
以下是如何使用 LLMCheatsheets.jl 为 GitHub 存储库创建备忘单的基本示例。
using LLMCheatsheets
repo = GitHubRepo ( " https://github.com/svilupp/PromptingTools.jl " )
create_cheatsheet (repo; save_path = true );
使用save_path = true
,备忘单将保存到当前工作目录中的llm-cheatsheets
文件夹中。
幕后发生了什么:
repo.paths
和repo.file_types
匹配的所有相关文件。对于单独生成文件并自行处理它们的低级接口,请参阅examples/create_for_promptingtools.jl
。
有时您可能只想下载文件而不对其进行汇总。您可以使用collect
功能来做到这一点。
files_str = collect (repo)
files_str
将是一个字符串,其中所有扫描的文件连接在一起。要在 ChatGPT 或 Claude.ai 中使用它,请使用clipboard
功能将其复制到剪贴板 - files_str|>clipboard
。
默认情况下,扫描和下载的文件分别是repo.paths
和repo.file_types
。
默认情况下, repo.paths
包括["src", "docs/src", "README.md"]
, repo.file_types
包括[".jl", ".md"]
。您可以在创建GitHubRepo
对象时自定义这些:
例如,添加文件夹examples
和.txt
文件来自定义我们将总结的内容:
repo = GitHubRepo ( " https://github.com/username/repository " ; paths = [ " examples " , " README.md " ], file_types = [ " .jl " , " .md " , " .txt " ])
您可以通过将model
参数传递给函数来使用不同的 LLM。
create_cheatsheet (repo; save_path = true , model = " gpt4om " )
您可以提供特殊指令来指导 AI 生成备忘单:
create_cheatsheet (repo; special_instructions = " Focus on the data structures and their interactions. " )
您还可以简单地从 PromptingTools.jl 导出 ai* 函数,以便将它们与 LLMCheatsheets.jl 一起使用。
using LLMCheatsheets
# Re-export aigenerate, pprint from PromptingTools
using LLMCheatsheets : aigenerate, pprint
# Or import PromptingTools directly
# using PromptingTools
repo = GitHubRepo ( " https://github.com/svilupp/PromptingTools.jl " ; paths = [ " docs/src " , " README.md " ])
files_str = collect (repo)
msg = aigenerate ( " Read through these files: $(files_str) nn Answer the question: What is the function for creating prompt templates? " )
pprint (msg)
The function for creating prompt templates in the `PromptingTools.jl` package is `create_template`. This function allows you to define a prompt with placeholders and save it for later use. The syntax is:
```julia
create_template(; user=<user prompt>,
system=<system prompt>, load_as=<template name>)
```
This function generates a vector of messages, which you can use directly in the `ai*` functions. If you provide the `load_as` argument, it will also register the template in the template store,
allowing you to access it later using its name.
如果您受到 LLM 提供商的速率限制,您可以通过设置较低的数字(例如ntasks=5
或ntasks=2
)来减少create_cheatsheet
中并发汇总任务的数量(取决于您的 API 层)。
设置个人访问令牌并将其设置为ENV["GITHUB_API_KEY"]
。它将自动加载到变量LLMCheatsheets.GITHUB_API_KEY
中。
您可以按照以下步骤为 GitHub API 设置个人访问令牌:
然后您可以将其设置为ENV["GITHUB_API_KEY"]
或LLMCheatsheets.GITHUB_API_KEY
。
有关使用 LLMCheatsheets.jl 的更多信息,请参阅文档。
如果您遇到任何问题或有疑问,请在 GitHub 存储库上提出问题。