This project provides a prototype Kotlin module for AI prompt chaining (
promptkt) and an associated JavaFx demonstration UI (
promptfx). It is intended primarily for demonstration purposes, and is designed to be primarily used with the OpenAI API (https://platform.openai.com/docs/api-reference) or a compatible LLM API.
See below for instructions to build and run PromptFx.
PromptFx UI Features
PromptFx has views for testing the OpenAI API and for a number of basic applications.
The GUI initially presents the model view, as shown below. Clicking
Run will retrieve a list of models and is a good way to ensure the application is able to access the OpenAI API. To set the API key, you may click on the key in the toolbar. Alternately, you may save your key in an
apikey.txt file, or in a system registry variable
OpenAI API Views
OpenAI API tab contains a number of views designed for exercising the OpenAI API, including
audio/, and more. These are similar to the API playground at https://platform.openai.com/playground, and should be self-explanatory.
PromptFx has limited support for OpenAI’s
Text Application Views
Fun tabs contains a number of use cases designed for different LLM applications or testing. Many of these are similar to the examples described at https://platform.openai.com/examples. These views are designed primarily for experimentation with LLMs, so may vary in terms of feature sets and quality.
Document Question Answering
Document Q&A tab is a prototype view that lets you “ask questions” of a folder of local documents on your system, using OpenAI’s Ada embedding model to retrieve relevant document chunks, and using context-augmented prompting to answer questions. In the view below, a question is being asked based on the content of the Python Software Foundation website.
To customize the documents used, select the
Open Folder button and browse to a folder on your local system. Add documents (
.docx) to this folder, and when you ask a question PromptFx will automatically pull text from the PDF/DOC files, chunk the text into sections, calculate embeddings, lookup relevant chunks based on your question, and use OpenAI’s API to formulate a suitable response. The prompt is also designed to provide a reference to the source document.
In “demonstration mode” (see button on toolbar), PromptFx provides a more elegant interactive mode, additionally rendering PDF thumbnails for source documents.
Integration tab contains a few experimental demonstrations that integrate with external APIs. Many of these use a prompt chaining approach that may involve a series of steps to answer a question.
PromptKt Library Features
The PromptKt library provides a number of features for working with LLM APIs, including:
- document chunking tools
- a local embedding (vector) database
- command-line chat tools
- support for AI pipelines (chaining prompts and/or APIs together)
- configurable prompt templates with mustache support
- a basic tool chain execution service
Many of these features resemble features of LangChcain.
Building PromptKt and PromptFx
- Maven version 3.9.3+
- Java version 17+
OpenAI Client Library:
- PromptKt/PromptFx use the
openai-kotlinAPI client library from https://github.com/aallam/openai-kotlin.
TornadoFx library (required before you can build
- PromptFx uses a version of
tornadofxthat is not available on maven central.
- Clone the repo https://github.com/triathematician/tornadofx.
- Checkout out the
mvn clean installto install the
tornadofxlibrary in your local maven repository.
To build the project:
mvn clean install -DskipTestsfrom the
mvn clean install -DskipTestsfrom the
Note that you can run tests as part of the build, but many of these require an
apikey.txt file and use the OpenAI API. We anticipate migrating these to a separate profile and making them available as optional integration tests.
To run the project (after compilation):
java -jar target/promptfx-0.1.0-SNAPSHOT-jar-with-dependencies.jarfrom the