### Start Mitmproxy Web Console Source: https://github.com/zmedelis/bosquet/blob/main/docs/notebook/observability/index.html Install Mitmproxy and start its web console for interactive traffic analysis. ```bash mitmweb ``` -------------------------------- ### Set up User Guide Namespace and Dependencies Source: https://github.com/zmedelis/bosquet/blob/main/docs/notebook/user_guide/index.html This code snippet sets up the Clojure namespace for the user guide and declares necessary dependencies for Bosquet's features, including caching, environment, LLM generation, and Clerk. ```clojure (ns user-guide {:nextjournal.clerk/toc true} (:require [bosquet.db.cache :as cache] [bosquet.env :as env] [bosquet.llm.generator :refer [generate llm] :as g] [bosquet.llm.oai-shaped-llm :as oai] [bosquet.llm.wkk :as k] [clojure.string :as s] [nextjournal.clerk :as clerk])) ``` -------------------------------- ### Ollama Configuration Example Source: https://github.com/zmedelis/bosquet/blob/main/docs/notebook/user_guide/index.html Example of Ollama configuration within the Bosquet environment. This shows how to set the API endpoint and associate chat and completion functions. ```clojure (:ollama env/config) ``` ```clojure { :api-endpoint "http://localhost:11434/api" :chat-fn bosquet.llm.ollama/chat :complete-fn bosquet.llm.ollama/complete } ``` -------------------------------- ### Bosquet CLI Usage Examples Source: https://context7.com/zmedelis/bosquet/llms.txt Provides examples of how to use the Bosquet Command Line Interface (CLI) for various tasks, including showing help, setting API keys and models, running inline prompts, and using prompts/data from files. The CLI simplifies running LLM generations without writing Clojure code. ```bash # Show help clojure -M -m bosquet.cli ``` ```bash # Set API key for a service clojure -M -m bosquet.cli keys set openai ``` ```bash # Set default model clojure -M -m bosquet.cli llms set --service openai --model gpt-4o --temperature 0 ``` ```bash # One-shot inline prompt clojure -M -m bosquet.cli "2 + {{x}} = ?" ``` ```bash # Prompt from file + data from file (data file may be a vector for batch mode) clojure -M -m bosquet.cli -p demo/play-writer-prompt.edn -d demo/play-writer-data.edn ``` ```bash # Enable mitmproxy for request/response logging clojure -M -m bosquet.cli "2+2=" --proxy ``` ```bash # Custom proxy host/port clojure -M -m bosquet.cli "2+2=" --proxy-host localhost --proxy-port 8080 --keystore-password changeit ``` -------------------------------- ### Bosquet Completions Example Source: https://github.com/zmedelis/bosquet/blob/main/docs/notebook/user_guide/index.html This example shows how to retrieve completions from Bosquet, including a critique and synopsis for a given title and genre. It also illustrates how Bosquet structures its output for conversation. ```clojure {:nextjournal/presented {:path [], :nextjournal/value [ {:path [0], :nextjournal/value [:bosquet/completions {:path [0 1], :nextjournal/value [:critique \"The synopsis for \\\"Mr. X\\\" offers a compelling premise for a sci-fi play, with its\" {:n 80, :path [0 1 0 1], :total 650, :offset 80, :replace-path [0 1 0 1 80]} \"synopsis\" \"In a futuristic world where technology rules all, a mysterious figure known only\" {:n 80, :path [0 1 1 1], :total 570, :offset 80, :replace-path [0 1 1 1 80]}}]} :nextjournal/value [:bosquet/conversation {:path [1 1], :nextjournal/value [:system \"You are an amazing writer.\" ]}]}]}} ``` -------------------------------- ### Get CLI Options Source: https://github.com/zmedelis/bosquet/blob/main/README.md Run this command to display available options for the Bosquet CLI. ```bash clojure -M -m bosquet.cli ``` -------------------------------- ### Define LLM Prompt with Examples Source: https://github.com/zmedelis/bosquet/blob/main/docs/notebook/examples/math_generate_code/index.html Defines a prompt structure that includes examples for few-shot learning and a calculation section for generating text. It specifies the LLM model and parameters to be used. ```clojure (def prompt {:calc ["{% for example in examples %}\"\n \"QUESTION: {{example.question}}\"\n \"CODE: {{example.code}}\"\n \"{ % endfor %}\"\n \"\"\n \"QUESTION: {{question}}\"\n \"CODE: {{answer}}\]\n :answer (g/llm :openai wkk/model-params {:model :gpt-4})}) ``` -------------------------------- ### Generate Wedding Thank You Letter - Few-Shot Example Source: https://github.com/zmedelis/bosquet/blob/main/docs/notebook/examples/writing_letters/index.html This example demonstrates how to generate a thank you letter for a wedding guest. It includes guest details, gift information, and specific instructions on tone and content, such as thanking them for traveling. ```clojure { :guest "Name: Joe, Relationship: Friend, Gift: Bar set, Hometown: New York" :step "- Joe is a friend, so the tone should be casual and friendly.\n- A bar set is a nice gift because it can be used for entertaining.\\\ ``` -------------------------------- ### Example Thank You Letter Source: https://github.com/zmedelis/bosquet/blob/main/docs/notebook/examples/writing_letters/index.html A sample thank you letter generated for a wedding guest. This serves as a concrete example of the desired output. ```text Dear Nancy, Thank you so much for attending our wedding in Puerto Rico and for the lovely gift of mixing bowls. We love to bake and will think of you every time we use them. It was so kind of you to make the trip all the way from New Jersey to celebrate with us. We are truly grateful to have such supportive and close friends like you in our lives. We will of course let you know when we're next in New Jersey, and hope to see you soon! Best, Jack and Diane ``` -------------------------------- ### LLM Caching Example Source: https://github.com/zmedelis/bosquet/blob/main/docs/notebook/user_guide/index.html Demonstrates caching behavior with multiple calls to a function. Shows cache hits and misses. ```clojure (:bosquet/time g1) (:bosquet/time g2) (:bosquet/time g3) ``` -------------------------------- ### Sentence Splitting Setup and Usage Source: https://github.com/zmedelis/bosquet/blob/main/docs/notebook/text_splitting/index.html Instructions for downloading the English sentence splitting model and an explanation of sentence-based text partitioning. This method ensures that sentences are not split across chunks, preserving meaning. ```bash bb lang:sent:en ``` ```markdown Splitting by sentences will partition the text into chunks of N sentences. This results in chunks that are natural to reader. It will also prevent cutting the meaning of the sentence into two chunks. For this reason, the need for overlap parameter is l ``` -------------------------------- ### Define Math Examples in Clojure Source: https://github.com/zmedelis/bosquet/blob/main/docs/notebook/examples/math_generate_code/index.html Examples are defined as collections containing question-code pairs. This structure is used to train a model to generate code for math problems. ```clojure (def examples [ {:question \"What is 37593 * 67?\"\n :code \"(\* 37593 67)\"} {:question (u/join-lines \n \"Janet's ducks lay 16 eggs per day.\"\n \"She eats three for breakfast every morning and bakes muffins for her friends every day with four.\"\n \"She sells the remainder at the farmers' market daily for $2 per fresh duck egg.\"\n \"How much in dollars does she make every day at the farmers' market?\\")\n :code \"(\* (- 16 3 4) 2)\"} {:question \"A robe takes 2 bolts of blue fiber and half that much white fiber. How many bolts in total does it take?\"\n :code \\\"(+ 2 (/ 2 2)\\\"}) ] ``` -------------------------------- ### Generate Code for Question 2 Source: https://github.com/zmedelis/bosquet/blob/main/docs/notebook/examples/math_generate_code/index.html This snippet demonstrates generating code to solve 'Question 2'. It uses the defined question and examples to prompt the generation, then displays the code and its evaluation. ```clojure (let [{{answer :answer} g/completions} (g/generate prompt {:examples examples :question question2}) ] (c/html [:div [:div "Code:" [:pre answer]] [:div "Eval:" [:pre (-> answer read-string eval)]]]))) ``` -------------------------------- ### Namespace and Dependencies for Prosocial Dialog Notebook Source: https://github.com/zmedelis/bosquet/blob/main/docs/notebook/memory_prosocial_dialog/index.html Defines the namespace and imports necessary libraries for the notebook, including environment setup, LLM generation, memory components, string manipulation, and Clerk for notebook rendering. It also imports Qdrant for database operations. ```clojure (ns memory-prosocial-dialog {:nextjournal.clerk/toc true} (:require [bosquet.env :as env] [bosquet.llm.generator :as gen] [bosquet.memory.long-term-memory :as long-term-memory] [bosquet.memory.retrieval :as r] [bosquet.memory.simple-memory :as simple-memory] [clojure.string :as string] [helpers :as h] [hfds-clj.core :as hfds] [bosquet.db.qdrant] [nextjournal.clerk :as clerk]) (:import [bosquet.db.qdrant Qdrant])) ``` -------------------------------- ### Define and Use Multiple Math Tools with Bosquet Source: https://context7.com/zmedelis/bosquet/llms.txt Bosquet can handle multiple tools for a single LLM call. This example demonstrates using `add` and `sub` functions for mathematical operations. ```clojure (defn ^{:desc "Add x and y"} add [^{:type "number" :desc "First number"} x ^{:type "number" :desc "Second number"} y] (+ (if (number? x) x (Float/parseFloat x)) (if (number? y) y (Float/parseFloat y)))) (defn ^{:desc "Subtract y from x"} sub [^{:type "number" :desc "Number to subtract from"} x ^{:type "number" :desc "Number to subtract"} y] (- (if (number? x) x (Float/parseFloat x)) (if (number? y) y (Float/parseFloat y)))) (generate [[:system "You are a math wizard."] [:user "What is 2 + 2 - 3?"] [:assistant (llm wkk/openai wkk/model-params {wkk/tools [#'add #'sub]} wkk/var-name :answer)])] ``` -------------------------------- ### LLM Configuration Map Source: https://github.com/zmedelis/bosquet/blob/main/docs/notebook/user_guide/index.html Defines LLM service configuration using a map. This example shows how to specify the service, enable caching, and set model parameters like temperature. ```edn {:llm/service :ollama :llm/cache true :llm/model-params {:temperature 0.3}} ``` -------------------------------- ### EDN Output Generation Source: https://github.com/zmedelis/bosquet/blob/main/docs/notebook/user_guide/index.html Example of requesting LLM to generate data in EDN format, specifically a map of planet distances. The prompt must also request EDN for reliable results. ```clojure (get-in (generate [[:system ["As a brilliant astronomer, list distances between planets and the Sun" "in the Solar System. Provide the answer in EDN map where the key is the" "planet name and the value is the string distance in millions of kilometers."]] [:user ["Generate only EDN omit any other prose and explanations."]] [:assistant (llm :gpt-3.5-turbo k/var-name :distances k/output-format :edn k/model-params {:max-tokens 300})] ]) [g/completions :distances]) ``` -------------------------------- ### Few-Shot Examples for Thank You Letters Source: https://github.com/zmedelis/bosquet/blob/main/docs/notebook/examples/writing_letters/index.html Defines a dataset for few-shot learning, including guest details, step-by-step instructions for tailoring the letter, and the final generated letter. This structure helps the LLM understand how to personalize notes. ```clojure (def thank-you-letters-few-shot-exmples {:examples [; Example for Nancy {:guest "Name: Nancy, Relationship: Friend of Jack's parents, Gift: Set of mixing bowls, Hometown: New Jersey" :step "- Nancy is a friend of Jack's parents, so the tone should be more formal and reference how important she is to Jack's parents. - New Jersey and Puerto Rico are a long distance apart, so we should thank her for making the trip. - Mixing bowls are a nice gift because they can be used for baking." :note "Dear Nancy, Thank you so much for attending our wedding in Puerto Rico and for the lovely gift of mixing bowls. We love to bake and will think of you every time we use them. It was so kind of you to make the trip all the way from New Jersey to celebrate with us. We are truly grateful to have such supportive and close friends like you in our lives. We will of course let you know when we're next in New Jersey, and hope to see you soon! Best, Jack and Diane"} ; Example for Joe Lewis {:guest "Name: Joe Lewis,Relationship: Friend of Jack's from college., Gift: Bar set, Hometown: Puerto Rico" :step "- Joe is a friend of Jack's from college, so the tone should be more casual and friendly. - Joe lives close to the wedding, so we can tell him how much we enjoyed having him there. - A ``` -------------------------------- ### Generate Code for Mathematical Problem Source: https://github.com/zmedelis/bosquet/blob/main/docs/notebook/examples/math_generate_code/index.html This snippet shows how to generate code for a mathematical problem using a prompt, examples, and the question. It then displays the generated code and its evaluated result. ```clojure (let [{{answer :answer} g/completions} (g/generate prompt {:examples examples :question question1}) ] (c/html [:div [:div "Code:" [:pre answer]] [:div "Eval:" [:pre (-> answer read-string eval)]]]))) ``` -------------------------------- ### Define Letter Writing Prompt Source: https://github.com/zmedelis/bosquet/blob/main/docs/notebook/examples/writing_letters/index.html Defines a reusable prompt structure for writing personalized letters. It includes context, few-shot examples, and specific guest information to guide the LLM. ```clojure (def letter-writter\ {:context [\"Jack and Diane just had their wedding in Puerto Rico \"\ \"and it is time to write thank you cards. For each\"\ \"guest, write a thoughtful, sincere, and personalized\"\ \"thank you note using the information provided below.\"\ ]\ :few-shot-examples [\"{% for example in examples %}\\"\ \"Guest Information:\"\ \"{{example.guest}}\"\ \"First, let's think step by step:\"\ \"{{example.step}}\"\ \"Next, let's draft the letter:\"\ \"{{example.note}}\"\ \\"{ % endfor %}\\"\ ]\ :instructions [\"{{context}}\"\ \"{{few-shot-examples}}\"\ \"Guest Information:\"\ \"Name: {{name}}\"\ \"Relationship: {{relationship}}\"\ \"Gift: {{gift}}\"\ \"Hometown: {{hometown}}\"\ \"First, let's think step by step:\"\ \"{{letter}}\"\]\ :letter (llm :gpt-3.5-turbo)}) ``` -------------------------------- ### Initialize Qdrant Storage Source: https://github.com/zmedelis/bosquet/blob/main/docs/notebook/memory_prosocial_dialog/index.html Sets up a Qdrant client for long-term memory storage. Requires specifying a collection name and embedding size. ```clojure (def storage (Qdrant. {:collection-name \"prosocial\"\ :size 384})) ``` -------------------------------- ### Example Mathematical Problem and Evaluation Source: https://github.com/zmedelis/bosquet/blob/main/docs/notebook/examples/math_generate_code/index.html A concrete example of a mathematical problem and its evaluated result. The code calculates a value based on a given formula. ```clojure (\* 2 (+ 200 (\* 0.4 200))) ``` -------------------------------- ### Include Configuration Files Source: https://github.com/zmedelis/bosquet/blob/main/docs/notebook/user_guide/index.html This snippet demonstrates how to include configuration files like `config.edn` and `secrets.edn`. It shows fallback mechanisms for loading these files from the project root or the user's home directory. ```clojure #include #or ["./config.edn" #join [#env HOME "/.bosquet/config.edn"]] #include #or ["./secrets.edn" #join [#env HOME "/.bosquet/secrets.edn"]] ``` -------------------------------- ### Activate Bosquet Proxy with Custom Host/Port (CLI) Source: https://github.com/zmedelis/bosquet/blob/main/docs/notebook/observability/index.html Use this command to activate the Bosquet proxy with custom host and port configurations, including keystore password. ```bash clojure -M -m bosquet.cli \"2+2=\" --proxy-host localhost --proxy-port 8080 --keystore-password changeit ``` -------------------------------- ### Activate Bosquet Proxy with Defaults (CLI) Source: https://github.com/zmedelis/bosquet/blob/main/docs/notebook/observability/index.html Use this command to activate the Bosquet proxy with default settings when running via the command line. ```bash clojure -M -m bosquet.cli \"2+2=\" --proxy ``` -------------------------------- ### Initialize Clerk Viewer Source: https://github.com/zmedelis/bosquet/blob/main/docs/notebook/user_guide/index.html Initializes the Clerk viewer with the provided state. This is a common setup step for Clerk notebooks. ```javascript viewer.init(viewer.read_string(state)) ``` -------------------------------- ### Character-based Text Splitting Example Source: https://github.com/zmedelis/bosquet/blob/main/docs/notebook/text_splitting/index.html Displays text split into character chunks. This is useful for visualizing how text is segmented at a granular level. ```html
Call me Ishmael. Some years ago—never mind how long precisely—having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the w
see the watery part of the world. It is a way I have of driving off the spleen and regulating the circulation. Whenever I find myself growing grim about the mouth; whenever it is a damp, drizzly Nove
izzly November in my soul; whenever I find myself involuntarily pausing before coffin warehouses, and bringing up the rear of every funeral I meet; and especially whenever my hypos get such an upper h
an upper hand of me, that it requires a strong moral principle to prevent me from deliberately stepping into the street, and methodically knocking people’s hats off—then, I account it high time to get
ime to get to sea as soon as I can.
``` -------------------------------- ### Simple Prompt Completion Source: https://github.com/zmedelis/bosquet/blob/main/README.md Perform a basic prompt completion using the `generate` function. Requires importing `bosquet.llm.generator`. ```clojure (require '[bosquet.llm.generator :refer [generate llm]]) (generate "When I was 6 my sister was half my age. Now I’m 70 how old is my sister?") => "When you were 6, your sister was half your age, which means she was 6 / 2 = 3 years old.\nSince then, there is a constant age difference of 3 years between you and your sister.\nNow that you are 70, your sister would be 70 - 6 = 64 years old." ``` -------------------------------- ### Use Selmer Templating with Loops and Defaults Source: https://context7.com/zmedelis/bosquet/llms.txt Utilizes the Selmer templating engine for prompt construction, including for-loops over collections and default values for variables. This allows for dynamic and structured prompt generation. ```clojure (require '[bosquet.llm.generator :refer [generate llm]] '[bosquet.llm.wkk :as wkk]) ;; For-loop over a collection + default filter (def sentimental {:text ["Estimate the sentiment of each {{text-type|default:tweet}} as positive, negative, or neutral:" "{% for t in tweets %}" "* {{t}}" "{% endfor %}" "Sentiments:" "{{classify}}"] :classify (llm :ollama wkk/model-params {:model :llama2})}) (generate sentimental {:tweets ["The concert was absolutely incredible!" "Stuck in traffic for two hours." "The weather is fine today."]}) ;; completions :text => "1. Positive 2. Negative 3. Neutral" ``` -------------------------------- ### LLM Prompt with Variables Source: https://github.com/zmedelis/bosquet/blob/main/docs/notebook/papers/chain_of_verification/index.html This snippet shows how to construct a prompt for a language model, incorporating variables for dynamic content generation. It defines two prompts, `:b` and `:x`, which are then used in a larger structure. ```clojure :b \"{{sys}} {{N}}-1={{y}}\\\"\n :x (g/llm :ollama k/model-params {:model :zephyr})\n :y (g/llm :ollama k/model-params {:model :zephyr})} ``` -------------------------------- ### Set Default Model via CLI Source: https://github.com/zmedelis/bosquet/blob/main/README.md Configure the default language model service, temperature, and model name using the CLI. ```bash clojure -M -m bosquet.cli llms set --service openai --temperature 0 --model gpt-4o ``` -------------------------------- ### Tailwind CSS Configuration for Bosquet Source: https://github.com/zmedelis/bosquet/blob/main/docs/notebook/examples/writing_letters/index.html Configure Tailwind CSS for Bosquet, including content paths, safelist, and theme extensions for fonts. This setup is essential for applying custom styles. ```javascript tailwind.config = { darkMode: "class", content: [ "./tw/viewer.js", "./tw/**/*.edn" ], safelist: ['dark'], theme: { extend: {}, fontFamily: { sans: ["Fira Sans", "-apple-system", "BlinkMacSystemFont", "sans-serif"], serif: ["PT Serif", "serif"], mono: ["Fira Mono", "monospace"] } }, variants: { extend: {}, }, plugins: [], } @tailwind base; @tailwind components; @tailwind utilities; @layer base { html { font-size: 18px; } @media (max-width: 600px) { html { font-size: 16px; } } .font-condensed { font-family: "Fira Sans Condensed", sans-serif; } .font-inter { font-family: "Inter", sans-serif; } body { @apply font-serif antialiased text-gray-900 sm:overscroll-y-none; } code, .code { @apply font-mono text-sm text-gray-900 bg-slate-50 px-0.5 py-px rounded dark:bg-gray-800; } code::before, code::after { @apply content-none !important; } h1, h3, h4, h5, h6 { @apply font-condensed font-bold mt-8 first:mt-0; } h2 { /*We cannot collapse margins due to nesting but we want to*/ /*keep the h2’s large margin visible*/ @apply font-condensed font-bold mt-8 first:mt-2; } h1 { @apply text-4xl; } h2 { @apply text-3xl; } h3 { @apply text-2xl; } @media print { h1 { @apply text-2xl !important; } h2 { @apply text-xl !important; } h3 { @apply text-lg !important; } } button { @apply focus:outline-none; } strong { @apply font-bold; } em { @apply italic; } pre { @apply m-0 font-mono; } table img { @apply inline-block; } } ``` -------------------------------- ### Define and Use Custom LLM Provider in Clojure Source: https://context7.com/zmedelis/bosquet/llms.txt Demonstrates how to define a custom LLM provider by implementing a specific function contract. This allows for drop-in replacement of default LLM backends. Ensure the function adheres to the `(fn [service-config params] -> {wkk/content {...} wkk/usage {...}})` signature. ```clojure (require '[bosquet.llm.generator :refer [generate llm]]) '[bosquet.llm.wkk :as wkk] '[bosquet.llm.oai-shaped-llm :as oai]) ;; Define a mock provider that prepends a prefix (def my-env {:prefixer {:chat-fn (fn [_config {:keys [prefix messages]}] {wkk/usage {:prompt 1 :completion 1 :total 2} wkk/content {oai/role oai/assistant oai/content (str prefix (-> messages first :content))}})}}) (generate my-env {:prompt "{{text}} {{gen}}" :gen (llm :prefixer wkk/model-params {:prefix ">>> "})} {:text "A fox jumps over"}) ;; completions :gen => ">>> A fox jumps over" ;; Mix custom and built-in providers in the same chat (generate (merge my-env bosquet.env/config) [[:user "{{text}}"] [:assistant (llm :prefixer wkk/var-name :gen1 wkk/model-params {:prefix "|||"})] [:user "Now summarize."] [:assistant (llm :ollama wkk/var-name :gen2 wkk/model-params {:model :mistral})]] {:text "The quick brown fox"}) ``` -------------------------------- ### LLM Output Formatting Source: https://github.com/zmedelis/bosquet/blob/main/docs/notebook/user_guide/index.html Illustrates how to specify output formats for LLM generation using the :llm/output-format parameter. Supported formats include :json, :edn, :list, :number, and :bool. ```clojure :llm/output-format ``` -------------------------------- ### Tailwind CSS Configuration Source: https://github.com/zmedelis/bosquet/blob/main/docs/notebook/observability/index.html Configuration for Tailwind CSS, including dark mode, content sources, safelist, theme extensions, and plugins. This setup defines custom fonts and base styles. ```javascript tailwind.config = { darkMode: "class", content: ["./tw/viewer.js", "./tw/**/*.edn"], safelist: ['dark'], theme: { extend: {}, fontFamily: { sans: ["Fira Sans", "-apple-system", "BlinkMacSystemFont", "sans-serif"], serif: ["PT Serif", "serif"], mono: ["Fira Mono", "monospace"] } }, variants: { extend: {}, }, plugins: [], } ``` -------------------------------- ### Run Generations with Files via CLI Source: https://github.com/zmedelis/bosquet/blob/main/README.md Use the CLI to run generations by specifying prompt and data files. ```bash clojure -M -m bosquet.cli -p demo/play-writer-prompt.edn -d demo/play-writer-data.edn ``` -------------------------------- ### Tailwind CSS Configuration Source: https://github.com/zmedelis/bosquet/blob/main/docs/index.html Configure Tailwind CSS with custom theme settings, content paths, safelist, and plugins. This setup defines font families, base styles, and utility classes. ```javascript tailwind.config = { darkMode: "class", content: ["./tw/viewer.js", "./tw/**/*.edn"], safelist: ['dark'], theme: { extend: {}, fontFamily: { sans: ["Fira Sans", "-apple-system", "BlinkMacSystemFont", "sans-serif"], serif: ["PT Serif", "serif"], mono: ["Fira Mono", "monospace"] } }, variants: { extend: {}, }, plugins: [], } @tailwind base; @tailwind components; @tailwind utilities; ``` -------------------------------- ### Chat Completion Example Source: https://github.com/zmedelis/bosquet/blob/main/docs/notebook/user_guide/index.html Construct prompts as linear chats using a vector of tuples. The LLM node definition includes an additional ':llm/var-name' parameter to specify where the generation will be stored in the result map. ```clojure (generate\n (\n [:system \"You are an amazing writer.\" ]\n [:user [\"Write a synopsis for the play:\" \"Title: {{title}}\" \"Genre: {{genre}}\" \"Synopsis:\" ]]\n [:assistant (llm :gpt-3.5-turbo\n k/model-params {:temperature 0.8 :max-tokens 120}\n k/var-name :synopsis)]\n [:user \"Now write a critique of the above synopsis:\" ]\n [:assistant (llm :gpt ``` -------------------------------- ### Coerce LLM Output to Number using Bosquet Source: https://context7.com/zmedelis/bosquet/llms.txt This example demonstrates coercing the LLM's response to a number. The prompt asks for a rating from 1-10 and to provide only the number, which is then parsed as a numeric type. ```clojure (get-in (generate {:grade "Rate this answer from 1-10: '{{text}}'. Give only the number. {{score}}" :score (llm :gpt-4o wkk/output-format :number)}) [completions :score]) ``` -------------------------------- ### Run Generations via CLI Source: https://github.com/zmedelis/bosquet/blob/main/README.md Execute language model generations directly from the CLI using a simple prompt. ```bash clojure -M -m bosquet.cli "2+{{x}}=" ``` -------------------------------- ### Generate Verification Plan Source: https://github.com/zmedelis/bosquet/blob/main/docs/notebook/papers/chain_of_verification/index.html Use the `g/generate` function to create a verification plan for a given question. This sets up the process for verifying the LLM's answer. ```clojure (def plan-result (g/generate cov-verification-plan {:question "What was the primary cause of the Mexican-American war?"})) ``` -------------------------------- ### Coerce LLM Output to EDN using Bosquet Source: https://context7.com/zmedelis/bosquet/llms.txt The `:llm/output-format` key automatically parses the LLM's text response into a Clojure data structure. This example shows how to request and parse EDN output. ```clojure (require '[bosquet.llm.generator :refer [generate llm completions]]) '[bosquet.llm.wkk :as wkk]) ;; EDN — prompt requests EDN, output-format parses it (get-in (generate [[:system "List planet distances from the Sun in EDN. Key = planet name, value = km string."] [:user "Generate only EDN, no prose."] [:assistant (llm :gpt-4o wkk/var-name :distances wkk/output-format :edn wkk/model-params {:max-tokens 300})]]) [completions :distances]) ``` -------------------------------- ### Define Prosocial Check Function Source: https://github.com/zmedelis/bosquet/blob/main/docs/notebook/memory_prosocial_dialog/index.html Defines a function `prosocial-check` that constructs a message template for potentially harmful content. It includes placeholders for safety reasons and rules of thumb to guide the generation of a cautionary response. ```clojure (def prosocial-check\n [\ ``` -------------------------------- ### Tailwind CSS Configuration Source: https://github.com/zmedelis/bosquet/blob/main/docs/notebook/papers/chain_of_verification/index.html Configure Tailwind CSS with custom theme settings, content paths, and plugins. This setup defines font families, safelist classes, and applies base, component, and utility styles. ```javascript tailwind.config = { darkMode: "class", content: ["./tw/viewer.js", "./tw/**/*.edn"], safelist: ['dark'], theme: { extend: {}, fontFamily: { sans: ["Fira Sans", "-apple-system", "BlinkMacSystemFont", "sans-serif"], serif: ["PT Serif", "serif"], mono: ["Fira Mono", "monospace"] } }, variants: { extend: {}, }, plugins: [], } @tailwind base; @tailwind components; @tailwind utilities; @layer base { html { font-size: 18px; } @media (max-width: 600px) { html { font-size: 16px; } } .font-condensed { font-family: "Fira Sans Condensed", sans-serif; } .font-inter { font-family: "Inter", sans-serif; } body { @apply font-serif antialiased text-gray-900 sm:overscroll-y-none; } code, .code { @apply font-mono text-sm text-gray-900 bg-slate-50 px-0.5 py-px rounded dark:bg-gray-800; } code::before, code::after { @apply content-none !important; } h1, h3, h4, h5, h6 { @apply font-condensed font-bold mt-8 first:mt-0; } h2 { /*We cannot collapse margins due to nesting but we want to*/ /*keep the h2’s large margin visible*/ @apply font-condensed font-bold mt-8 first:mt-2; } h1 { @apply text-4xl; } h2 { @apply text-3xl; } h3 { @apply text-2xl; } @media print { h1 { @apply text-2xl !important; } h2 { @apply text-xl !important; } h3 { @apply text-lg !important; } } button { @apply focus:outline-none; } strong { @apply font-bold; } em { @apply italic; } pre { @apply m-0 font-mono; } table img { @apply inline-block; } } ``` -------------------------------- ### Define and Use Calculator Tools for LLM Source: https://github.com/zmedelis/bosquet/blob/main/README.md This snippet shows how to define mathematical functions (add, subtract) as tools and use them with an LLM. The LLM can then perform calculations based on user requests by invoking these defined tools. ```clojure ;;Write some calculator functions (defn ^{:desc "add 'x' and 'y'"} add [^{:type "number" :desc "First number to add"} x ^{:type "number" :desc "Second number to add"} y] (prn (format "Applying add for %s %s" x y)) (+ (if (number? x) x (Float/parseFloat x) ) (if (number? y) y (Float/parseFloat y) ))) (defn ^{:desc "subtract 'y' from 'x'"} sub [^{:type "number" :desc "Number to subtract from"} x ^{:type "number" :desc "Number to subtract"} y] (prn (format "Applying sub %s %s" x y)) (- (if (number? x) x (Float/parseFloat x) ) (if (number? y) y (Float/parseFloat y) ))) (generate [[:system "You are a math wizard"] [:user "What is 2 + 2 - 3"] [:assistant (llm wkk/openai wkk/model-params {wkk/tools [#'add #'sub]} wkk/var-name :answer)]) => #:bosquet{:conversation [[:system "You are a math wizard"] [:user "What is 2 + 2 - 3"] [:assistant "2 + 2 - 3 equals 1"]], :completions {:answer "2 + 2 - 3 equals 1"}, :usage {:answer {:prompt 181, :completion 12, :total 193}, :bosquet/total {:prompt 181, :completion 12, :total 193}}, :time 1749} ``` -------------------------------- ### Tailwind CSS Configuration Source: https://github.com/zmedelis/bosquet/blob/main/docs/notebook/document_loading/index.html Configure Tailwind CSS for document styling, including content paths, safelist, theme extensions, and font families. This setup is essential for applying custom styles across your project. ```javascript tailwind.config = { darkMode: "class", content: [ "./tw/viewer.js", "./tw/**/*.edn" ], safelist: ['dark'], theme: { extend: {}, fontFamily: { sans: ["Fira Sans", "-apple-system", "BlinkMacSystemFont", "sans-serif"], serif: ["PT Serif", "serif"], mono: ["Fira Mono", "monospace"] } }, variants: { extend: {}, }, plugins: [], } ``` -------------------------------- ### Generate Text with Merged Environment Source: https://github.com/zmedelis/bosquet/blob/main/docs/notebook/user_guide/index.html Use this snippet to generate text by merging a custom user environment with the default Bosquet configuration. It demonstrates a prompt with user and assistant turns, including LLM calls with variable parameters. ```clojure (generate (merge user-env env/config) [[:user "{{text}}"] [:assistant (llm :prefixer k/var-name :gen1 k/model-params {:prefix "|||"})] [:user "Add a suffix"] [:assistant (llm :ollama k/var-name :gen2 k/model-params {:model :mistral})] ] {:text "A fox jumps over"}) ``` -------------------------------- ### Coerce LLM Output to Boolean using Bosquet Source: https://context7.com/zmedelis/bosquet/llms.txt This example demonstrates coercing the LLM's response to a boolean value. The prompt specifies answering with 'yes' or 'no', and `:bool` format ensures a true/false result. ```clojure (get-in (generate {:q "Is 2 = 2? Answer with 'yes' or 'no' only!!! {{a}}" :a (llm :gpt-4o wkk/output-format :bool)}) [completions :a]) ``` -------------------------------- ### Linked Prompt Templates for Text Generation Source: https://github.com/zmedelis/bosquet/blob/main/docs/notebook/user_guide/index.html Use linked prompt templates to define dependencies between prompt blocks, create multiple generations, pipe results, get token usage, and provide input data to fill template slots. ```clojure (generate {:question-answer "Question: {{question}} Answer: {{answer}}" :answer (llm :gpt-3.5-turbo k/model-params {:temperature 0.8 :max-tokens 120}) :self-eval ["{{question-answer}}" "" "Is this a correct answer? {{test}}"] :test (llm :mistral-small k/model-params {:temperature 0.2 :max-tokens 120})} {:question "What is the distance from Moon to Io?"}) ```