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 儲存庫上提出問題。