$git clone https://github.com/zmedelis/bosquetBosquet is on a mission to make building AI applications simple. All nontrivial AI applications need to work with prompt templates that quickly grow in complexity, limited LLM context windows require memory management, and agents are needed for AI applications to interact with th
| 1 | [](https://clojars.org/io.github.zmedelis/bosquet) |
| 2 | |
| 3 | # LLMOps for Large Language Model-based applications |
| 4 | |
| 5 | Bosquet is on a mission to make building AI applications simple. All nontrivial AI applications need to work with prompt templates that quickly grow in complexity, limited LLM context windows require memory management, and agents are needed for AI applications to interact with the outside world. |
| 6 | |
| 7 | Bosquet provides instruments to work with those AI application concepts: |
| 8 | |
| 9 | - LLM and Tool service management |
| 10 | - Prompt templating via integration with the excellent [Selmer](https://github.com/yogthos/Selmer) templating library |
| 11 | - Prompt chaining and composition via a powerful [Pathom](https://pathom3.wsscode.com/) graph processing machine |
| 12 | - Agent and tools definition abstractions for the interactions with external APIs |
| 13 | - LLM memory handling |
| 14 | - Other instruments like call response caching (see documentation) |
| 15 | |
| 16 | ## Documentation |
| 17 | |
| 18 | [Full project documentation](https://zmedelis.github.io/bosquet/) (WIP) |
| 19 | |
| 20 | ## Use |
| 21 | |
| 22 | Secrets like keys are stored in `secrets.edn` file and local parameters are kept in `config.edn`. Make a copy of `config.edn.sample` and `config.edn.sample` files. Change as needed. |
| 23 | |
| 24 | ### CLI |
| 25 | |
| 26 | Command line interface demo |
| 27 | |
| 28 | [](https://www.youtube.com/watch?v=ywlNGiD9gCg) |
| 29 | |
| 30 | Run the following command to get CLI options |
| 31 | |
| 32 | ``` |
| 33 | clojure -M -m bosquet.cli |
| 34 | ``` |
| 35 | |
| 36 | Set the default model with |
| 37 | |
| 38 | ``` |
| 39 | clojure -M -m bosquet.cli llms set --service openai --temperature 0 --model gpt-4o |
| 40 | ``` |
| 41 | |
| 42 | Do not forget to set the API KEY for your service (change 'openai' to a different name if needed) |
| 43 | |
| 44 | ``` |
| 45 | clojure -M -m bosquet.cli keys set openai |
| 46 | ``` |
| 47 | |
| 48 | With that set, you can run generations: |
| 49 | |
| 50 | ``` |
| 51 | clojure -M -m bosquet.cli "2+{{x}}=" |
| 52 | ``` |
| 53 | |
| 54 | Or using files |
| 55 | |
| 56 | ``` |
| 57 | clojure -M -m bosquet.cli -p demo/play-writer-prompt.edn -d demo/play-writer-data.edn |
| 58 | ``` |
| 59 | |
| 60 | ### Prompt completion |
| 61 | |
| 62 | Simple prompt completion can be done like this. |
| 63 | |
| 64 | ```colojure |
| 65 | (require '[bosquet.llm.generator :refer [generate llm]]) |
| 66 | |
| 67 | (generate "When I was 6 my sister was half my age. Now I’m 70 how old is my sister?") |
| 68 | => |
| 69 | "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."} |
| 70 | ``` |
| 71 | |
| 72 | ### Completion from the prompt map |
| 73 | |
| 74 | ```clojure |
| 75 | (require '[bosquet.llm :as llm]) |
| 76 | (require '[bosquet.llm.generator :refer [generate llm]]) |
| 77 | |
| 78 | (generate |
| 79 | llm/default-services |
| 80 | {:question-answer "Question: {{question}} Answer: {{answer}}" |
| 81 | :answer (llm :openai) |
| 82 | :self-eval ["Question: {{question}}" |
| 83 | "Answer: {{answer}}" |
| 84 | "" |
| 85 | "Is this a correct answer?" |
| 86 | "{{test}}"] |
| 87 | :test (llm :openai)} |
| 88 | {:question "What is the distance from Moon to Io?"}) |
| 89 | => |
| 90 | |
| 91 | {:question-answer |
| 92 | "Question: What is the distance from Moon to Io? Answer:", |
| 93 | :answer |
| 94 | "The distance from the Moon to Io varies, as both are orbiting different bodies. On average, the distance between the Moon and Io is approximately 760,000 kilometers (470,000 miles). However, this distance can change due to the elliptical nature of their orbits.", |
| 95 | :self-eval |
| 96 | "Question: What is the distance from Moon to Io?\nAnswer: The distance from the Moon to Io varies, as both are orbiting different bodies. On average, the distance between the Moon and Io is approximately 760,000 kilometers (470,000 miles). However, this distance can change due to the elliptical nature of their orbits.\n\nIs this a correct answer?", |
| 97 | :test |
| 98 | "No, the answer provided is incorrect. The Moon is Earth's natural satellite, while Io is one of Jupiter's moons. Therefore, the distance between the Moon and Io can vary significantly depending on their relative positions in their respective orbits around Earth and Jupiter." |