Skip to main content

Label, clean and enrich text datasets with LLMs

Project description

PromptMeteo

Promptmeteo is a Python library build over LangChain to build prompts and LLMs by configuration parameters. The goal of this project is to be used as a template to industrialize LLM projects.

๐Ÿ”ฅ๐Ÿง”

Dammed to chains for bringing humans the light

Installation

~/promptmeteo$ make setup

Quick start

from promptmeteo import Promptmeteo

model = Promptmeteo(
        task_type           = 'classification',
        model_provider_name = 'hf_pipeline',
        model_name          = 'google/flan-t5-small',
        selector_algorithm  = 'semantic_similarity',
        selector_k          = 3
    )

model = model.train(
    examples = ['estoy feliz', 'me da igual', 'no me gusta'],
    annotations = ['positivo', 'neutral', 'negativo'],
)

model.predict(['que guay!!'])
>>> [[positive]]

Build project

Build image and run container

$ docker build -t promptmeteo .
$ docker run -it promptmeteo bash

Run example

$ python examples/getting_started.py --data_path data/classification_data.csv --prompt_path prompts/classification.yml

Run test

$ python -m pytest tests

Project Structure

promptmeteo
โ”œโ”€โ”€ data
โ”‚ย ย  โ””โ”€โ”€ classification_data.csv
โ”œโ”€โ”€ Dockerfile
โ”œโ”€โ”€ examples
โ”‚ย ย  โ””โ”€โ”€ getting_started.py
โ”œโ”€โ”€ LICENSE
โ”œโ”€โ”€ Makefile
โ”œโ”€โ”€ prompts
โ”‚ย ย  โ”œโ”€โ”€ classification.yml
โ”‚ย ย  โ””โ”€โ”€ ner_prompt.yml
โ”œโ”€โ”€ pyproject.toml
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ src
โ”‚ย ย  โ””โ”€โ”€ promptmeteo
โ”‚ย ย      โ”œโ”€โ”€ __init__.py
โ”‚ย ย      โ”œโ”€โ”€ main.py
โ”‚ย ย      โ”œโ”€โ”€ models
โ”‚ย ย      โ”‚ย ย  โ”œโ”€โ”€ base.py
โ”‚ย ย      โ”‚ย ย  โ”œโ”€โ”€ fake_llm.py
โ”‚ย ย      โ”‚ย ย  โ”œโ”€โ”€ hf_hub_api.py
โ”‚ย ย      โ”‚ย ย  โ”œโ”€โ”€ hf_pipeline.py
โ”‚ย ย      โ”‚ย ย  โ”œโ”€โ”€ __init__.py
โ”‚ย ย      โ”‚ย ย  โ””โ”€โ”€ openai.py
โ”‚ย ย      โ”œโ”€โ”€ parsers
โ”‚ย ย      โ”‚ย ย  โ”œโ”€โ”€ classification_parser.py
โ”‚ย ย      โ”‚ย ย  โ”œโ”€โ”€ dummy_parser.py
โ”‚ย ย      โ”‚ย ย  โ””โ”€โ”€ __init__.py
โ”‚ย ย      โ”œโ”€โ”€ prompts
โ”‚ย ย      โ”‚ย ย  โ”œโ”€โ”€ base.py
โ”‚ย ย      โ”‚ย ย  โ”œโ”€โ”€ classification_prompt.py
โ”‚ย ย      โ”‚ย ย  โ”œโ”€โ”€ __init__.py
โ”‚ย ย      โ”‚ย ย  โ”œโ”€โ”€ ner_prompt.py
โ”‚ย ย      โ”‚ย ย  โ””โ”€โ”€ templates
โ”‚ย ย      โ”‚ย ย      โ”œโ”€โ”€ en
โ”‚ย ย      โ”‚ย ย      โ”œโ”€โ”€ __init__.py
โ”‚ย ย      โ”‚ย ย      โ””โ”€โ”€ sp
โ”‚ย ย      โ”‚ย ย          โ”œโ”€โ”€ classification_prompt.yml
โ”‚ย ย      โ”‚ย ย          โ”œโ”€โ”€ __init__.py
โ”‚ย ย      โ”‚ย ย          โ””โ”€โ”€ ner_prompt.yml
โ”‚ย ย      โ”œโ”€โ”€ selector
โ”‚ย ย      โ”‚ย ย  โ”œโ”€โ”€ __init__.py
โ”‚ย ย      โ”‚ย ย  โ”œโ”€โ”€ length_selector.py
โ”‚ย ย      โ”‚ย ย  โ”œโ”€โ”€ marginal_relevance_selector.py
โ”‚ย ย      โ”‚ย ย  โ”œโ”€โ”€ n_gram_selector.py
โ”‚ย ย      โ”‚ย ย  โ””โ”€โ”€ semantic_similarity_selector.py
โ”‚ย ย      โ””โ”€โ”€ tasks
โ”‚ย ย          โ”œโ”€โ”€ base.py
โ”‚ย ย          โ”œโ”€โ”€ classification_task.py
โ”‚ย ย          โ”œโ”€โ”€ __init__.py
โ”‚ย ย          โ””โ”€โ”€ ner_task.py
โ””โ”€โ”€ tests
    โ”œโ”€โ”€ test_main.py
    โ”œโ”€โ”€ test_models.py
    โ”œโ”€โ”€ test_parsers.py
    โ”œโ”€โ”€ test_prompts.py
    โ”œโ”€โ”€ test_selectors.py
    โ””โ”€โ”€ test_task.py

Objects

classDiagram

Promptmeteo        ..|> TaskBuilder        : Composition
TaskBuilder        ..|> Task               : Build
ClassificationTask --|> Task               : Inheritance
Task               ..|> PromptFactory      : Composition
Task               ..|> ParserFactory      : Composition
Task               ..|> SelectorFactory    : Composition
Task               ..|> ModelFactory       : Composition
Prompt             ..|> PromptFactory      : Instanciate
Parser             ..|> ParserFactory      : Instanciate
Selector           ..|> SelectorFactory    : Instanciate
Model              ..|> ModelFactory       : Instanciate

class Promptmeteo{
  + builder : TaskBuilder
  + train(examples : List[str], annotations : List[str])
  + predict(examples : List[str])
}
class TaskBuilder{
  + task : Task
  - _build_model()
  - _build_pormpt()
  - _build_parser()
  - _build_selector()
}
class Task{
  + model : Model
  + prompt : Prompt
  + parser : Parser
  + selector : Selector
  + run(prompt: str)
}
class ClassificationTask{
  + model : Model
  + prompt : Prompt
  + parser : Parser
  + selector : Selector
  + run(prompt: str)
}
class PromptFactory{
  + factory_method() -> Prompt
}
class ParserFactory{
  + factory_method() -> Parser
}
class ModelFactory{
  + factory_method() -> Model
}
class SelectorFactory{
  + factory_method() -> Selector
}
class Prompt{
  + PROMPT_EXAMPLE
  + run()
}
class Parser{
  + run()
}
class Model{
  + llm
  + run(prompt: str)
}
class Selector{
  + example_selector
  + run(prompt: str)
}

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

promptmeteo-0.0.0.tar.gz (19.3 kB view hashes)

Uploaded Source

Built Distribution

promptmeteo-0.0.0-py3-none-any.whl (36.2 kB view hashes)

Uploaded Python 3

Supported by

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