You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.org
+18-5
Original file line number
Diff line number
Diff line change
@@ -3,9 +3,14 @@
3
3
* Introduction
4
4
This library provides an interface for interacting with Large Language Models (LLMs). It allows elisp code to use LLMs while also giving end-users the choice to select their preferred LLM. This is particularly beneficial when working with LLMs since various high-quality models exist, some of which have paid API access, while others are locally installed and free but offer medium quality. Applications using LLMs can utilize this library to ensure compatibility regardless of whether the user has a local LLM or is paying for API access.
5
5
6
-
LLMs exhibit varying functionalities and APIs. This library aims to abstract functionality to a higher level, as some high-level concepts might be supported by an API while others require more low-level implementations. An example of such a concept is "examples," where the client offers example interactions to demonstrate a pattern for the LLM. While the GCloud Vertex API has an explicit API for examples, OpenAI's API requires specifying examples by modifying the system prompt. OpenAI also introduces the concept of a system prompt, which does not exist in the Vertex API. Our library aims to conceal these API variations by providing higher-level concepts in our API.
7
-
8
-
Certain functionalities might not be available in some LLMs. Any such unsupported functionality will raise a ~'not-implemented~ signal.
6
+
This library abstracts several kinds of features:
7
+
- Chat functionality: the ability to query the LLM and get a response, and continue to take turns writing to the LLM and receiving responses. The library supports both synchronous, asynchronous, and streaming responses.
8
+
- Chat with image and other kinda of media inputs are also supported, so that the user can input images and discuss them with the LLM.
9
+
- Function calling (aka "tool use") is supported, for having the LLM call elisp functions that it chooses, with arguments it provides.
10
+
- Embeddings: Send text and receive a vector that encodes the semantic meaning of the underlying text. Can be used in a search system to find similar passages.
11
+
- Prompt construction: Create a prompt to give to an LLM from one more sources of data.
12
+
13
+
Certain functionalities might not be available in some LLMs. Any such unsupported functionality will raise a ~'not-implemented~ signal, or it may fail in some other way. Clients are recommended to check =llm-capabilities= when trying to do something beyond basic text chat.
9
14
* Setting up providers
10
15
Users of an application that uses this package should not need to install it themselves. The llm package should be installed as a dependency when you install the package that uses it. However, you do need to require the llm module and set up the provider you will be using. Typically, applications will have a variable you can set. For example, let's say there's a package called "llm-refactoring", which has a variable ~llm-refactoring-provider~. You would set it up like so:
11
16
@@ -28,7 +33,7 @@ For embedding users. if you store the embeddings, you *must* set the embedding m
28
33
** Open AI
29
34
You can set up with ~make-llm-openai~, with the following parameters:
30
35
- ~:key~, the Open AI key that you get when you sign up to use Open AI's APIs. Remember to keep this private. This is non-optional.
31
-
- ~:chat-model~: A model name from the [[https://platform.openai.com/docs/models/gpt-4][list of Open AI's model names.]] Keep in mind some of these are not available to everyone. This is optional, and will default to a reasonable 3.5 model.
36
+
- ~:chat-model~: A model name from the [[https://platform.openai.com/docs/models/gpt-4][list of Open AI's model names.]] Keep in mind some of these are not available to everyone. This is optional, and will default to a reasonable model.
32
37
- ~:embedding-model~: A model name from [[https://platform.openai.com/docs/guides/embeddings/embedding-models][list of Open AI's embedding model names.]] This is optional, and will default to a reasonable model.
33
38
** Open AI Compatible
34
39
There are many Open AI compatible APIs and proxies of Open AI. You can set up one with ~make-llm-openai-compatible~, with the following parameter:
@@ -151,7 +156,7 @@ Conversations can take place by repeatedly calling ~llm-chat~ and its variants.
151
156
** Caution about ~llm-chat-prompt-interactions~
152
157
The interactions in a prompt may be modified by conversation or by the conversion of the context and examples to what the LLM understands. Different providers require different things from the interactions. Some can handle system prompts, some cannot. Some require alternating user and assistant chat interactions, others can handle anything. It's important that clients keep to behaviors that work on all providers. Do not attempt to read or manipulate ~llm-chat-prompt-interactions~ after initially setting it up for the first time, because you are likely to make changes that only work for some providers. Similarly, don't directly create a prompt with ~make-llm-chat-prompt~, because it is easy to create something that wouldn't work for all providers.
153
158
** Function calling
154
-
*Note: function calling functionality is currently alpha quality. If you want to use function calling, please watch the =llm= [[https://github.com/ahyatt/llm/discussions][discussions]] for any announcements about changes.*
159
+
*Note: function calling functionality is currently beta quality. If you want to use function calling, please watch the =llm= [[https://github.com/ahyatt/llm/discussions][discussions]] for any announcements about changes.*
155
160
156
161
Function calling is a way to give the LLM a list of functions it can call, and have it call the functions for you. The standard interaction has the following steps:
157
162
1. The client sends the LLM a prompt with functions it can call.
@@ -199,6 +204,14 @@ for a function than "write-email".
199
204
Examples can be found in =llm-tester=. There is also a function call to generate
200
205
function calls from existing elisp functions in
201
206
=utilities/elisp-to-function-call.el=.
207
+
** Media input
208
+
*Note: media input functionality is currently alpha quality. If you want to use it, please watch the =llm= [[https://github.com/ahyatt/llm/discussions][discussions]] for any announcements about changes.*
209
+
210
+
Media can be used in =llm-chat= and related functions. To use media, you can use
211
+
=llm-multipart= in =llm-make-chat-prompt=, and pass it an Emacs image or an
212
+
=llm-media= object for other kinds of media. Besides images, some models support
213
+
video and audio. Not all providers or models support these, with images being
214
+
the most frequently supported media type, and video and audio more rare.
202
215
** Advanced prompt creation
203
216
The =llm-prompt= module provides helper functions to create prompts that can
204
217
incorporate data from your application. In particular, this should be very
0 commit comments