Skip to main content

llm-sort

LLM plugin for semantically sorting lines. Ranking techniques are based on this paper.

Installation

Install this plugin in the same environment as LLM.

llm install llm-sort

Usage

The plugin adds a new command, llm sort. This command has an interface similar to the GNU sort command, but instead of sorting lines based on alphabetical order, it input lines based on some semantic ranking criteria.

Lines can be provided via files or standard input. For example:

# Sort lines from a file using the "sorting" method (default)
llm sort --query "Which of these names is more suitable for a pet monkey?" names.txt

# Read from standard input
cat titles.txt | llm sort --query "Which book should I read to cook better?"

# Use a different method, limit the output to the top 5 lines, and specify a custom model and prompt:
llm sort --query "Rank these slogans" --method sliding --top-k 5 --model gpt-4 \
  --prompt 'Decide which line is more compelling. Answer with "Line A" or "Line B" Query: {query} Lines: {docA} {docB}.' quotes.txt

Note: The prompt template variables are {query}, {docA}, and {docB}.

The default prompt used is:

Given the query: {query}

Compare the following two lines:

Line A: {docA}

Line B: {docB}

Which line is more relevant to the query? Please answer with "Line A" or "Line B".

Development

To set up this plugin locally, first checkout the code. Then create a new virtual environment:

cd llm-sort
python3 -m venv venv
source venv/bin/activate

Now install the dependencies and test dependencies:

pip install -e '.[test]'

To run the tests:

python -m pytest

Metadata

Release files for llm-sort 0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for llm-sort 0.3
File Size Uploaded
llm_sort-0.3.tar.gz 9.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for llm-sort 0.3
File Interpreter ABI Platform
llm_sort-0.3-py3-none-any.whl Python 3 none any Details

Total release size: 17.9 kB

Release files / llm_sort-0.3.tar.gz

Download URL llm_sort-0.3.tar.gz
Size 9.2 kB
Tags Source
SHA-256 checksum
How to use checksums
a767ce7040b78952b6b1390d38fa38993f2a97b8eef5f1d4a3ebc92a980047e5
BLAKE2b-256 checksum
How to use checksums
443325dc0c326c2d467ca6a48dafa172bdad78f4f245ef483c55052e6a81050e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.12

Release files / llm_sort-0.3-py3-none-any.whl

Download URL llm_sort-0.3-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bc2b8d91b7bf77d9a9e96507b56658657784289c8aa9f651b078bc8dbb7a0cd7
BLAKE2b-256 checksum
How to use checksums
a55dd4d9b8494c366d53797812bfe1584480c080e81633752c094fcfb5a5f574
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.12

Release history Release notifications | RSS feed

This release

0.3 This release

2 release files

0.2

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page