-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Documenter.jl
committed
Nov 24, 2023
1 parent
947452c
commit 6dea4bd
Showing
9 changed files
with
4,464 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"documenter":{"julia_version":"1.9.4","generation_timestamp":"2023-11-24T09:40:49","documenter_version":"1.1.2"}} | ||
{"documenter":{"julia_version":"1.9.4","generation_timestamp":"2023-11-24T20:08:52","documenter_version":"1.1.2"}} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><title>Using AITemplates · PromptingTools.jl</title><meta name="title" content="Using AITemplates · PromptingTools.jl"/><meta property="og:title" content="Using AITemplates · PromptingTools.jl"/><meta property="twitter:title" content="Using AITemplates · PromptingTools.jl"/><meta name="description" content="Documentation for PromptingTools.jl."/><meta property="og:description" content="Documentation for PromptingTools.jl."/><meta property="twitter:description" content="Documentation for PromptingTools.jl."/><meta property="og:url" content="https://svilupp.github.io/PromptingTools.jl/examples/working_with_aitemplates/"/><meta property="twitter:url" content="https://svilupp.github.io/PromptingTools.jl/examples/working_with_aitemplates/"/><link rel="canonical" href="https://svilupp.github.io/PromptingTools.jl/examples/working_with_aitemplates/"/><script data-outdated-warner src="../../assets/warner.js"></script><link href="https://cdnjs.cloudflare.com/ajax/libs/lato-font/3.0.0/css/lato-font.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/juliamono/0.050/juliamono.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/fontawesome.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/solid.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/brands.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.8/katex.min.css" rel="stylesheet" type="text/css"/><script>documenterBaseURL="../.."</script><script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js" data-main="../../assets/documenter.js"></script><script src="../../search_index.js"></script><script src="../../siteinfo.js"></script><script src="../../../versions.js"></script><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../../assets/themes/documenter-dark.css" data-theme-name="documenter-dark" data-theme-primary-dark/><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../../assets/themes/documenter-light.css" data-theme-name="documenter-light" data-theme-primary/><script src="../../assets/themeswap.js"></script></head><body><div id="documenter"><nav class="docs-sidebar"><div class="docs-package-name"><span class="docs-autofit"><a href="../../">PromptingTools.jl</a></span></div><button class="docs-search-query input is-rounded is-small is-clickable my-2 mx-auto py-1 px-2" id="documenter-search-query">Search docs (Ctrl + /)</button><ul class="docs-menu"><li><a class="tocitem" href="../../">Home</a></li><li><a class="tocitem" href="../../getting_started/">Getting Started</a></li><li><span class="tocitem">Examples</span><ul><li><a class="tocitem" href="../readme_examples/">Various examples</a></li><li class="is-active"><a class="tocitem" href>Using AITemplates</a></li><li><a class="tocitem" href="../working_with_ollama/">Local models with Ollama.ai</a></li></ul></li><li><a class="tocitem" href="../../frequently_asked_questions/">F.A.Q.</a></li><li><a class="tocitem" href="../../reference/">Reference</a></li></ul><div class="docs-version-selector field has-addons"><div class="control"><span class="docs-label button is-static is-size-7">Version</span></div><div class="docs-selector control is-expanded"><div class="select is-fullwidth is-size-7"><select id="documenter-version-selector"></select></div></div></div></nav><div class="docs-main"><header class="docs-navbar"><a class="docs-sidebar-button docs-navbar-link fa-solid fa-bars is-hidden-desktop" id="documenter-sidebar-button" href="#"></a><nav class="breadcrumb"><ul class="is-hidden-mobile"><li><a class="is-disabled">Examples</a></li><li class="is-active"><a href>Using AITemplates</a></li></ul><ul class="is-hidden-tablet"><li class="is-active"><a href>Using AITemplates</a></li></ul></nav><div class="docs-right"><a class="docs-navbar-link" href="https://github.com/svilupp/PromptingTools.jl" title="View the repository on GitHub"><span class="docs-icon fa-brands"></span><span class="docs-label is-hidden-touch">GitHub</span></a><a class="docs-navbar-link" href="https://github.com/svilupp/PromptingTools.jl/blob/main/examples/working_with_aitemplates.jl#" title="Edit source on GitHub"><span class="docs-icon fa-solid"></span></a><a class="docs-settings-button docs-navbar-link fa-solid fa-gear" id="documenter-settings-button" href="#" title="Settings"></a><a class="docs-article-toggle-button fa-solid fa-chevron-up" id="documenter-article-toggle-button" href="javascript:;" title="Collapse all docstrings"></a></div></header><article class="content" id="documenter-page"><h1 id="Using-AITemplates"><a class="docs-heading-anchor" href="#Using-AITemplates">Using AITemplates</a><a id="Using-AITemplates-1"></a><a class="docs-heading-anchor-permalink" href="#Using-AITemplates" title="Permalink"></a></h1><p>This file contains examples of how to work with AITemplate(s).</p><p>First, let's import the package and define a helper link for calling un-exported functions:</p><pre><code class="language-julia hljs">using PromptingTools | ||
const PT = PromptingTools</code></pre><pre><code class="nohighlight hljs">PromptingTools</code></pre><p>LLM responses are only as good as the prompts you give them. However, great prompts take long time to write – AITemplate are a way to re-use great prompts!</p><p>AITemplates are just a collection of templated prompts (ie, set of "messages" that have placeholders like {{question}})</p><p>They are saved as JSON files in the <code>templates</code> directory. They are automatically loaded on package import, but you can always force a re-load with <code>PT.load_templates!()</code></p><pre><code class="language-julia hljs">PT.load_templates!();</code></pre><p>You can (create them) and use them for any ai* function instead of a prompt: Let's use a template called <code>:JuliaExpertAsk</code> alternatively, you can use <code>AITemplate(:JuliaExpertAsk)</code> for cleaner dispatch</p><pre><code class="language-julia hljs">msg = aigenerate(:JuliaExpertAsk; ask = "How do I add packages?")</code></pre><pre><code class="nohighlight hljs">AIMessage("To add packages in Julia, you can use the built-in package manager called `Pkg`. Here are the steps: | ||
|
||
1. Open the Julia REPL (Read-Eval-Print Loop). | ||
2. Press the `]` key to enter the package manager mode. | ||
3. Use the `add` command followed by the name of the package you want to install. For example, to install the `DataFrames` package, type: `add DataFrames`. | ||
4. Press the `backspace` or `ctrl + C` key to exit the package manager mode and return to the REPL. | ||
|
||
After following these steps, the specified package will be installed and available for use in your Julia environment.")</code></pre><p>You can see that it had a placeholder for the actual question (<code>ask</code>) that we provided as a keyword argument. We did not have to write any system prompt for personas, tone, etc. – it was all provided by the template!</p><p>How to know which templates are available? You can search for them with <code>aitemplates()</code>: You can search by Symbol (only for partial name match), String (partial match on name or description), or Regex (more fields)</p><pre><code class="language-julia hljs">tmps = aitemplates("JuliaExpertAsk")</code></pre><pre><code class="nohighlight hljs">1-element Vector{AITemplateMetadata}: | ||
PromptingTools.AITemplateMetadata | ||
name: Symbol JuliaExpertAsk | ||
description: String "For asking questions about Julia language. Placeholders: `ask`" | ||
version: String "1" | ||
wordcount: Int64 237 | ||
variables: Array{Symbol}((1,)) | ||
system_preview: String "You are a world-class Julia language programmer with the knowledge of the latest syntax. Your commun" | ||
user_preview: String "# Question\n\n{{ask}}" | ||
source: String "" | ||
|
||
</code></pre><p>You can see that it outputs a list of available templates that match the search - there is just one in this case.</p><p>Moreover, it shows not just the description, but also a preview of the actual prompts, placeholders available, and the length (to gauge how much it would cost).</p><p>If you use VSCode, you can display them in a nice scrollable table with <code>vscodedisplay</code>:</p><pre><code class="language-plaintext hljs">using DataFrames | ||
DataFrame(tmp) |> vscodedisplay</code></pre><p>You can also just <code>render</code> the template to see the underlying mesages:</p><pre><code class="language-julia hljs">msgs = PT.render(AITemplate(:JuliaExpertAsk))</code></pre><pre><code class="nohighlight hljs">2-element Vector{PromptingTools.AbstractChatMessage}: | ||
SystemMessage("You are a world-class Julia language programmer with the knowledge of the latest syntax. Your communication is brief and concise. You're precise and answer only when you're confident in the high quality of your answer.") | ||
UserMessage{String}("# Question\n\n{{ask}}", [:ask], :usermessage)</code></pre><p>Now, you know exactly what's in the template!</p><p>If you want to modify it, simply change it and save it as a new file with <code>save_template</code> (see the docs <code>?save_template</code> for more details).</p><p>Let's adjust the previous template to be more specific to a data analysis question:</p><pre><code class="language-julia hljs">tpl = [PT.SystemMessage("You are a world-class Julia language programmer with the knowledge of the latest syntax. You're also a senior Data Scientist and proficient in data analysis in Julia. Your communication is brief and concise. You're precise and answer only when you're confident in the high quality of your answer.") | ||
PT.UserMessage("# Question\n\n{{ask}}")]</code></pre><pre><code class="nohighlight hljs">2-element Vector{PromptingTools.AbstractChatMessage}: | ||
SystemMessage("You are a world-class Julia language programmer with the knowledge of the latest syntax. You're also a senior Data Scientist and proficient in data analysis in Julia. Your communication is brief and concise. You're precise and answer only when you're confident in the high quality of your answer.") | ||
UserMessage{String}("# Question\n\n{{ask}}", [:ask], :usermessage)</code></pre><p>Templates are saved in the <code>templates</code> directory of the package. Name of the file will become the template name (eg, call <code>:JuliaDataExpertAsk</code>)</p><pre><code class="language-julia hljs">filename = joinpath(pkgdir(PromptingTools), | ||
"templates", | ||
"persona-task", | ||
"JuliaDataExpertAsk_123.json") | ||
PT.save_template(filename, | ||
tpl; | ||
description = "For asking data analysis questions in Julia language. Placeholders: `ask`") | ||
rm(filename) # cleanup if we don't like it</code></pre><p>When you create a new template, remember to re-load the templates with <code>load_templates!()</code> so that it's available for use.</p><pre><code class="language-julia hljs">PT.load_templates!();</code></pre><p>!!! If you have some good templates (or suggestions for the existing ones), please consider sharing them with the community by opening a PR to the <code>templates</code> directory!</p><hr/><p><em>This page was generated using <a href="https://github.com/fredrikekre/Literate.jl">Literate.jl</a>.</em></p></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../readme_examples/">« Various examples</a><a class="docs-footer-nextpage" href="../working_with_ollama/">Local models with Ollama.ai »</a><div class="flexbox-break"></div><p class="footer-message">Powered by <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> and the <a href="https://julialang.org/">Julia Programming Language</a>.</p></nav></div><div class="modal" id="documenter-settings"><div class="modal-background"></div><div class="modal-card"><header class="modal-card-head"><p class="modal-card-title">Settings</p><button class="delete"></button></header><section class="modal-card-body"><p><label class="label">Theme</label><div class="select"><select id="documenter-themepicker"><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option><option value="auto">Automatic (OS)</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 1.1.2 on <span class="colophon-date" title="Friday 24 November 2023 20:08">Friday 24 November 2023</span>. Using Julia version 1.9.4.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html> |
Oops, something went wrong.