Metadata-Version: 2.1
Name: ollama-batch
Version: 0.1.1
Summary: Run text LLM prompts over a list of texts
Keywords: ai,llm,ollama
Author-Email: Emilio Mariscal <emilio.mariscal@hotosm.org>
License: MIT
Classifier: Topic :: Utilities
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Project-URL: homepage, https://github.com/emi420/ollama-batch
Project-URL: documentation, https://github.com/emi420/ollama-batch
Project-URL: repository, https://github.com/emi420/ollama-batch
Requires-Python: >=3.10
Requires-Dist: ollama>=0.3.3
Description-Content-Type: text/markdown

# Ollama Batch Text Processor

This simple utility will runs LLM prompts over a list of texts
and print the results as a JSON response.

### How it works? 

It contatenates your prompt with each text and call Ollama over it.

For example, if your prompt is:

`Is this recipe a sweet dessert or salty food? answer only with a hashtag #sweet or #salty`

And your texts are:

1. `Fruit salad: apple, orange, pear, grape, strawberry, sugar`
2. `Potatoes, mayonnaise, salt, black pepper, red onion, eggs`

It will run:

```
Fruit salad: apple, orange, pear, grape, strawberry, sugar

Is this recipe a sweet dessert or salty food? answer only with a hashtag #sweet or #salty
```

```
Potatoes, mayonnaise, salt, black pepper, red onion, eggs

Is this recipe a sweet dessert or salty food? answer only with a hashtag #sweet or #salty
```

## Quick start

### Install

Directly from the main branch:

`pip install git+https://github.com/emi420/ollama-batch`

### Usage

```sh
ollama-batch \
    [--directory DIRECTORY] \
    [--file FILE] [--model MODEL] \
    [--prompt PROMPT] \
    [--prompt-file PROMPT_FILE] \
    [--json-property JSON_PROPERTY] \
    [--json-append JSON_APPEND] \
    [--question-first]

options:
  -h, --help
            Show this help message and exit
  --directory DIRECTORY, -d DIRECTORY
            Directory with files you want to process
  --file FILE, -f FILE
            JSON file you want to process
  --model MODEL, -m MODEL
            Model you want to use
  --prompt PROMPT, -p PROMPT
            Prompt text
  --prompt-file PROMPT_FILE
            Text file with a prompt
  --json-property JSON_PROPERTY
            JSON property that you want to use
  --json-append JSON_APPEND
            Property that you want to append to the results
  --question-first
            First the question, then the prompt
```

### Examples

```bash
ollama-batch -d examples/recipes -p 'Is this recipe a sweet dessert or salty food?'
ollama-batch -d examples/recipes -p 'Is this recipe a sweet dessert or salty food?' --json-property=ingredients
ollama-batch -d examples/recipes -p 'Is this recipe a sweet dessert or salty food?' --json-property=title
ollama-batch -f examples/recipes.json --prompt-file examples/sweet_or_salty.txt
ollama-batch -f examples/recipes.json --prompt-file examples/sweet_or_salty.txt --json-append=title,url
```

(c) 2024 Emilio Mariscal
