aplpolaris / promptfx

Kotlin LLM Prompts and User Interface
Apache License 2.0
16 stars 1 forks source link

PromptFx

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.

Modules

API Key

PromptFx currently supports OpenAI and Google Gemini models, though more can be added as plugins.

PromptFx UI Features

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.

Document Q&A View

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.

image

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:

image

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.

image

This tab also contains a Text Manager view for creating and working with collections of text.

See Documents for more information.

API Views

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.

Tools Views

Under Tools, PromptFx provides:

image

See Tools for more information.

Text Views

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.

image

See Text for more information.

Beta Views

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.

PromptKt Library Features

The PromptKt library provides a number of features for working with LLM APIs, including:

Many of these features resemble features of LangChain.

Building PromptKt and PromptFx

System requirements:

OpenAI Client Library:

To build the project:

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.

Running PromptFx

To run the project (after compilation):