Skip to main content

LLM plugin for semantic sorting

Project description

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

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.3.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.3-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for llm_sort-0.3.tar.gz
Algorithm Hash digest
SHA256 a767ce7040b78952b6b1390d38fa38993f2a97b8eef5f1d4a3ebc92a980047e5
MD5 a80dbb3f986a9306ed0143da044a174f
BLAKE2b-256 443325dc0c326c2d467ca6a48dafa172bdad78f4f245ef483c55052e6a81050e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: llm_sort-0.3-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.12

File hashes

Hashes for llm_sort-0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 bc2b8d91b7bf77d9a9e96507b56658657784289c8aa9f651b078bc8dbb7a0cd7
MD5 6eea587280dcbf0383ca145469cb8809
BLAKE2b-256 a55dd4d9b8494c366d53797812bfe1584480c080e81633752c094fcfb5a5f574

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