Skip to main content

LLM plugin for semantic sorting

Project description

llm-sort

LLM plugin for semantically sorting lines.

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 line is most inspiring?" unsorted.txt

# Read from standard input
cat unsorted.txt | llm sort --query "Which line is most inspiring?"

# 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}.' unsorted.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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llm_sort-0.1.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llm_sort-0.1-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file llm_sort-0.1.tar.gz.

File metadata

  • Download URL: llm_sort-0.1.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for llm_sort-0.1.tar.gz
Algorithm Hash digest
SHA256 4b8663d2deced79d1d9ba608e2fa7edd7830cb63bcb521650c278c4144835bb9
MD5 1c7ec0de9aeda6e1c1e0014947fe7b4b
BLAKE2b-256 4799f1d3903c0cf160afb2f8ebc4418ba4b3368568aa7c9c75432db6471543ee

See more details on using hashes here.

File details

Details for the file llm_sort-0.1-py3-none-any.whl.

File metadata

  • Download URL: llm_sort-0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for llm_sort-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 24730a7e2533207e5c63939f86f037a8bbddf125861ce3c518336423e989edc4
MD5 737a3c68a6cdc1863cd8f38917d4f72a
BLAKE2b-256 6f86da5c131ed0dd1309fbac1d016a1b55c3b503934caa2bf49f21578d937d5a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page