|
3 | 3 | [org.httpkit.client :as hk-client] |
4 | 4 | [cheshire.core :as json])) |
5 | 5 |
|
6 | | -;; # using Large Language Models from Clojure |
7 | | -;; LLMs often come as APIs, as they require computing power (GPUs), which most users do not have |
8 | | -;; localy. |
9 | | -;; OpenAI offers their models behind an (paid) API for example. In the following we will see three |
10 | | -;;diferent ways to use the GPT-4 model from OpenAI |
| 6 | +;;# using Large Language Models from Clojure |
| 7 | +;;LLMs often come as APIs, as they require computing power (GPUs), which most users do not have |
| 8 | +;;localy. |
| 9 | +;;OpenAI offers their models behind an (paid) API for example. In the following we will see three |
| 10 | +;;different ways to use the GPT-4 model from OpenAI |
11 | 11 |
|
12 | | -;; get the openai API key either from environemnt or a specific file |
| 12 | +;; Get the openai API key either from environemnt or a specific file |
13 | 13 | (def open-ai-key |
14 | 14 | (or (System/getenv "OPEN_AI_KEY") |
15 | 15 | (slurp "open_ai_secret.txt") |
16 | 16 | ) |
17 | 17 | ) |
18 | 18 |
|
19 | | -(or "hello" (slurp "aa")) |
20 | 19 |
|
21 | 20 | ;## Use OpenAI API directly |
22 | 21 | ;; OpenAI offers a rather simple API, text-in text-out for "chatting" with GPT |
|
42 | 41 | (json/decode keyword)) |
43 | 42 |
|
44 | 43 | ; ## use Bosquet |
45 | | -; [bosquet](https://github.com/zmedelis/bosquet) abstracts some of the concepts of LLMs |
| 44 | +; [Bosquet](https://github.com/zmedelis/bosquet) abstracts some of the concepts of LLMs |
46 | 45 | ; on a higher level API. Its has further notions of "memory" and "tools" |
47 | | -; and has feature we find for exampl in python "LangChain" |
| 46 | +; and has other features we find for exampl in python "LangChain" |
48 | 47 |
|
49 | 48 | ;; Bosque wants the API key in a config file |
50 | 49 | (spit "secrets.edn" |
|
54 | 53 |
|
55 | 54 | (require '[bosquet.llm.generator :refer [generate llm]]) |
56 | 55 |
|
| 56 | +;; Call GPT from Bosquet |
| 57 | + |
57 | 58 | (generate |
58 | 59 | [[:user "What is Clojure"] |
59 | 60 | [:assistant (llm :openai |
60 | 61 | :llm/model-params {:model :gpt-4 |
61 | 62 | })]]) |
62 | 63 |
|
63 | 64 |
|
64 | | -;# use langchain4j |
65 | | -;; We can use LLMs as well via a Java Interop and teh library |
| 65 | +;## Use langchain4j |
| 66 | +;; We can use LLMs as well via a Java Interop and the library |
66 | 67 | ;; [lnagchain4j](https://github.com/langchain4j/langchain4j) which aims |
67 | | -;; to be a copy of the pythin langcahin, and offers support or |
68 | | -;; build blcoks for several consept arround LLMs (model, vecstorstores, document loaders) |
69 | | -;; We see it used in te following chapters |
| 68 | +;; to be a copy of the python library langchain, and offers support or |
| 69 | +;; building blocks for several concepts arround LLMs (model, vectorstores, document loaders, etc.) |
| 70 | +;; We see it used in the following chapters |
70 | 71 |
|
71 | 72 | (import '[dev.langchain4j.model.openai OpenAiChatModel OpenAiChatModelName]) |
72 | 73 |
|
|
0 commit comments