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 and exploration purposes, and is designed to be primarily used with the OpenAI API or a compatible LLM API.
See below and the wiki for instructions to build and run PromptFx and troubleshooting.
PromptFx currently supports OpenAI and Google Gemini models, though more can be added as plugins.
apikey.txt
file in the same folder you use to run PromptFx, or in a system registry variable OPENAI_API_KEY
.apikey-gemini.txt
file in the same folder you use to run PromptFx.PromptFx has views for testing AI/ML models and for a number of basic applications. These views are organized into tabs on the left side of the UI. Briefly:
Most of these panels have configuration panels (at right) for adjusting settings. For the views under the API
tab, this can be used to select the model used for the API call. For most other views, the panel will use the app's default completion model and/or embedding model. These defaults can be selected from the top toolbar.
The Document Q&A
tab is the default view. This 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 retrieval-augmented generation (RAG) to answer questions. In the view below, a question is being asked on a collection of research papers.
The view at the bottom left shows the "document snippets" that are used to find the most relevant matches in the documents in the folder. If you click on a snippet from a PDF document, a PDF viewer will show the page where the snippet comes from, as shown here:
To customize the documents used, select the Open Folder
button and browse to a folder on your local system. Add documents (.txt
, .pdf
, .doc
, or .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. The configuration panel at right can be used to adjust the settings for chunking documents, as well as the prompting strategy.
In "full screen mode" (see button on toolbar), PromptFx provides a more elegant interactive mode, additionally rendering PDF thumbnails for source documents.
This tab also contains a Text Manager
view for creating and working with collections of text.
See Documents for more information.
The API
tab contains a number of views designed for exercising the OpenAI API (or a compatible API), including completions/
, chat/
, images/
, embeddings/
, audio/
, and more. These are similar to the API playground at https://platform.openai.com/playground, and should be self-explanatory.
See API-Tab for more information.
Under Tools
, PromptFx provides:
Prompt Library
view for viewing built-in and custom promptsPrompt Template
view for experimenting with prompt templates using mustache syntaxPrompt Scripting
view for executing batches of scriptsPrompt Validator
view for experimenting with automatic validation methodsSee Tools for more information.
The Text
tab contains a number of use cases designed for natural language tasks, including translation, summarization, entity extraction, and sentiment analysis.
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.
See Text for more information.
The Fun
and Integrations
tabs are experimental with some fun applications of large language models.
See Fun and Integrations for more details.
The Audio
and Vision
tabs contain speech-to-text and speech-to-image tools, using OpenAI's Whisper and DALL-E models.
See Audio and Vision for more details.
The PromptKt library provides a number of features for working with LLM APIs, including:
Many of these features resemble features of LangChain.
System requirements:
OpenAI Client Library:
openai-kotlin
API client library from https://github.com/aallam/openai-kotlin.To build the project:
mvn clean install
from the promptkt
directory.mvn clean install
from the promptfx
directory.The libraries also contain separate integration tests requiring OpenAI
or Gemini
API keys. See the wiki for how to execute those tests and additional build/run troubleshooting.
To run the project (after compilation):
java -jar target/promptfx-0.1.0-SNAPSHOT-jar-with-dependencies.jar
from the promptfx
directory.