ToC | DocOverview | CGDoc | RelNotes | FAQ | Index | PermutedIndex
| Allegro CL version 11.0

# API for Large Language Models

## 1.0 Large Language Model Introduction

Functionality described in this document are included in the `:acl-llm` module. Load this module with

    (require :acl-llm)

As described below, you should also load the `:st-json` and `:net.aserve` modules.

The two acl-llm packages documented here provide Lisp operators to interact with APIs of Large Languge Models.

Currently the packages support only the OpenAI GPT models. See OpenAI API docs for API details.

This document describes the package:

- `llm.gpt` (nickname `gpt`): Lisp symbols naming operators/variables which access OpenAI Large Language Model APIs.

Use this package to access the functions described below.

Code examples in the document assume that these packages are used.

## 2.0 LLM Functional Dependencies

Operators in the `llm-gpt` module use operators/variables in the following modules, so they must be loaded when using this module:

- `:st-json` - This module (containing symbols in the `st-json` package) supports building and parsing JSON objects.
  See st-json.

- `:net.aserve` - Symbols in this module (mostly in the `net.aserve` package) implement HTTP clients and servers. Specifically `llm-gpt` package depends upon these two functions:

  - do-http-request: A multipurpose function to send HTTP requests and receive responses.
  - query-to-form-urlencoded: A function to create a URL parameter encoding from an association list.

## 3.0 LLM Quick Start

These forms will get you started:

    (require :acl-llm)
    (use-package :gpt)
    (set-openai-api-key YOUR-API-KEY)
    (ask-chat "Hello")

The call to set-openai-api-key requires a valid key. A valid key is a string formatted like this sample invalid key: `"sk-U01ABc2defGHIJKlmnOpQ3RstvVWxyZABcD4eFG5jiJKlmno"`. See the description of that function for a link to instructions for getting a key.

The last form `(ask-chat "Hello")` executes a simple chatbot function by building a JSON object to send to the OpenAI completions API and, if no errors occur, receives and parses the JSON object response. The sent object includes the input text `"Hello"` and sets all parameters to their default values. The response object contains an array of response choices, and by default the ask-chat function extracts the top ranked response as a string.

## 4.0 LLM API operators

The Large Language model API includes the following operators. Note that arguments to many of these operators are described in the OpenAI API Reference document and some searching in that document may be required to find the argument descriptions. This Allegro CL documentation assumes users are familiar with OpenAI and does not itself serve as a introduction to it.

- ask-embedding: Function, ask for JSON object containing embedding.
- ask-chat: Function, interacts with GPT-3.5 and 4 models.
- ask-for-list: Function to return a list of responses, interacts with GPT-3.5 and 4 models.
- ask-for-map: Function to return a list of key-value pairs, interacts with GPT-3.5 and 4 models.
- ask-my-documents: A Retrieval-Augmented Generation (RAG) function that combines the a query with results of the nearest-neighbor function nn into a big prompt to create a response that cites only those nearest neighbor matches that actually contribute to the response.
- call-openai: Function, Generic interface to all openai API functions.
- cancel-fine-tune: Function, cancels a running or pending fine-tune.
- chat: Function, use this function for GPT-3 model families ada, babbage, and davinci.
- delete-fine-tuned-model: Function, delete a fine-tuned model.
- delete-openai-file: Function, delete an OpenAI file.
- embed: Function, return an embedding vector for some text.
- fine-tune: Function, start a fine-tuning process.
- fine-tune-report: Function, get the report after a fine-tuning process.
- fine-tune-status: Function, get the status of fine-tuning processes.
- format-ask-my-documents-prompt: Format a prompt for ask-my-documents.
- list-openai-files: Function, prints a list of files in your OpenAI directory.
- list-openai-models: Function, returns a human readable list of file names.
- nn: Function, returns the nearest neighbors of some text based on embedding-based matching.
- read-vector-database: Function, read a vector database from the file system.
- set-openai-api-key: Function, takes a valid key as its argument and returns it after setting it as the value of *openai-api-key*.
- upload-openai-file: Function, uploads a file to your OpenAI user directory.
- upload-openai-file: Function, uploads a file to your OpenAI user directory.
- vector-database-embedding-vectors: Accesssor, get or set the embedding vectors in a vector database.
- vector-database-name: Accesssor, get or set the name of a vector database.
- vector-database-property-vectors: Accesssor, get or set the property vectors in vector database.
- write-vector-database: Function, write a vector database to the file system.

## 5.0 LLM API variables

- *openai-api-key*: value changed to the key returned by set-openai-api-key when that function is called.

- *default-vector-database-dir*: The default directory to store and retrieve vector databases.

- *default-vector-database-name*: The default name for a vector database.

- *openai-default-ask-chat-model*: The default value for the model used by ask-chat.

- *openai-default-best-of*: The default value for the OpenAI API parameter `best_of`.

- *openai-default-chat-model*: The default value for the model used by chat.

- *openai-default-echo*: The default value for the OpenAI API parameter `echo`.

- *openai-default-fine-tune-model*: The default value for the model used by (fine-tune)[gpt-ops.html#fine-tune].

- *openai-default-frequency-penalty*: The default value for the OpenAI API parameter `frequency_penalty`.

- *openai-default-function-call*: The default value for the OpenAI API parameter `function_call`.

- *openai-default-functions*: The default value for the OpenAI API parameter `functions`.

- *openai-default-initial-delay*: The default value for the call-openai key parameter `:initial-delay`.

- *openai-default-logit-bias*: The default value for the OpenAI API parameter `logit_bias`.

- *openai-default-logprobs*: The default value for the OpenAI API parameter `logprobs`.

- *openai-default-max-tokens*: The default value for the OpenAI API parameter `max_tokens`.

- *openai-default-min-score*: The default value for the key parameter `:min-score` of nn and ask-my-documents.

- *openai-default-n*: The default value for the OpenAI API parameter `n`.

- *openai-default-output-format*: The default value for the OpenAI API parameter `output_format`.

- *openai-default-presence-penalty*: The default value for the OpenAI API parameter `presence_penalty`.

- *openai-default-retries*: The default value for the call-openai key parameter `:retries`.

- *openai-default-stop*: The default value for the OpenAI API parameter `stop`.

- *openai-default-suffix*: The default value for the OpenAI API parameter `suffix`.

- *openai-default-temperature*: The default value for the OpenAI API parameter `temperature`.

- *openai-default-timeout*: The default value for the `:timeout` key parameter of call-openai.

- *openai-default-top-n*: The default value for the key parameter `:top-n` of nn and ask-my-documents.

- *openai-default-top-p*: The default value for the OpenAI API parameter `top_p`.

- *openai-default-user*: The default value for the OpenAI API parameter `user`.

## 6.0 LLM Classes

- vector-database: A class representing a vector database with slots for properties and data.

Copyright (c) Franz Inc. Lafayette, CA., USA. All rights reserved.

ToC | DocOverview | CGDoc | RelNotes | FAQ | Index | PermutedIndex
| Allegro CL version 11.0