promptmeteo package#
Subpackages#
- promptmeteo.models package
- Submodules
- promptmeteo.models.azure_openai module
- promptmeteo.models.base module
- promptmeteo.models.bedrock module
- promptmeteo.models.fake_llm module
- promptmeteo.models.google_vertexai module
- promptmeteo.models.hf_hub_api module
- promptmeteo.models.hf_pipeline module
- promptmeteo.models.openai module
- Module contents
- promptmeteo.parsers package
- promptmeteo.prompts package
- promptmeteo.selector package
- Submodules
- promptmeteo.selector.base module
- promptmeteo.selector.custom_selectors module
BalancedSemanticSamplesSelector
BalancedSemanticSamplesSelector.Config
BalancedSemanticSamplesSelector.add_example()
BalancedSemanticSamplesSelector.class_key
BalancedSemanticSamplesSelector.class_list
BalancedSemanticSamplesSelector.example_keys
BalancedSemanticSamplesSelector.from_examples()
BalancedSemanticSamplesSelector.input_keys
BalancedSemanticSamplesSelector.k
BalancedSemanticSamplesSelector.select_examples()
BalancedSemanticSamplesSelector.vectorstore
BalancedSemanticSamplesSelector.vectorstore_kwargs
sorted_values()
- Module contents
- promptmeteo.tasks package
Submodules#
promptmeteo.api_formatter module#
- class promptmeteo.api_formatter.APIFormatter(language: str, model_name: str, model_provider_name: str, api_version: str, api_protocol: str, api_style_instructions: List[str] = None, **kwargs)#
Bases:
BaseUnsupervised
API Formatter Task.
This class initializes the API Formatter Task to correct and format APIs.
- Parameters:
language (str) – Language for the API descriptions.
model_name (str) – Name of the model to be used for API generation.
model_provider_name (str) – Name of the model provider.
api_version (str) – Version of the API.
api_protocol (str) – Protocol of the API.
api_style_instructions (Optional[List[str]]) – Instructions for API style.
**kwargs (dict) – Additional keyword arguments.
Raises –
------ –
ValueError – If api_protocol is not in the allowed protocols or if api_version is not in the correct format.
Example –
------- –
APIFormatter (>>> from promptmeteo import) –
APIFormatter( (>>> model =) –
language="en" (...) –
:param : :param … api_version=”3.0.3”: :param : :param … api_protocol=”REST”: :param : :param … api_style_instructions=[“Use always camel case.”: :param “Do not use acronyms.”]: :param : :param … model_provider_name=”openai”: :param : :param … model_name=”gpt-3.5-turbo-16k”: :param : :param … model_provider_token=model_token: :param : :param … external_info={: :param … “servers”: :type … “servers”: [ :param … {: :param … “url”: :type … “url”: “http://localhost:8080/”, :param … “description”: :type … “description”: “Local environment”, :param … }: :param … ]: :param : :param … }: :param : :param … ): :param >>> model.train(api_code): :param >>> model.predict(api):
- ALLOWED_PROTOCOLS = ['REST']#
- TASK_TYPE: str = 'api-correction'#
- classmethod load_model(model_path: str) Self #
Load a saved model from disk.
- model_pathstr
Path from where the model will be loaded.
- Base
Loaded model instance.
Loads a model artifact to make new predictions.
- model_pathstr
Path to the model artifact.
- APIFormatter
Returns the loaded APIFormatter object.
- predict(api_codes: List[str], external_info: dict) List[str] #
Predict over new text samples.
- examplesList[str]
List of text samples to predict.
- List[str]
List of predictions.
Receive a list of API codes and return a list with the corrected APIs.
- api_codesList[str]
List of API codes.
- external_infodict
External information to be added to the APIs.
- List[str]
List of corrected APIs.
- train(api_codes: List[str]) Self #
- Trains the model given use cases and notes on behaviour. Check the
parameters and task behaviour in each specific model training docstring.
Train the APIFormatter to extract entities and parameters.
- api_codesList[str]
List of API codes.
- APIFormatter
Returns the trained APIFormatter object.
promptmeteo.api_generator module#
- class promptmeteo.api_generator.APIGenerator(language: str, model_name: str, model_provider_name: str, api_version: str, api_protocol: str, api_style_instructions: List[str] | None, **kwargs)#
Bases:
BaseSupervised
API Generator Task.
This class initializes the APIGenerator Task to create APIs based on descriptions.
- Parameters:
language (str) – Language for the API descriptions.
model_name (str) – Name of the model to be used for API generation.
model_provider_name (str) – Name of the model provider.
api_version (str) – Version of the API.
api_protocol (str) – Protocol of the API.
api_style_instructions (Optional[List[str]]) – Instructions for API style.
**kwargs (dict) – Additional keyword arguments.
Raises –
------ –
ValueError – If api_protocol is not in the allowed protocols or if api_version is not in the correct format.
Example –
------- –
APIGenerator (>>> from promptmeteo import) –
APIGenerator( (>>> model =) –
language="en" (...) –
:param : :param … selector_k=5: :param : :param … api_version=”3.0.3”: :param : :param … api_protocol=”REST”: :param : :param … api_style_instructions=[“Use always camel case.”: :param “Do not use acronyms.”]: :param : :param … model_provider_name=”openai”: :param : :param … model_name=”gpt-3.5-turbo-16k”: :param : :param … model_provider_token=model_token: :param : :param … ): :param >>> model.train(api_description: :param api_code): :param >>> model.predict(“API for managing account access”):
- ALLOWED_PROTOCOLS = ['REST']#
- TASK_TYPE: str = 'api-generation'#
- train(api_descriptions: List[str], api_codes: List[str]) Self #
- Trains the model given use cases and notes on behaviour. Check the
parameters and task behaviour in each specific model training docstring.
Train the APIGenerator from a list of APIs descriptions and contracts.
- api_descriptionsList[str]
List of API descriptions.
- api_codesList[str]
List of API codes - contracts.
- APIGenerator
Returns the trained APIGenerator object.
promptmeteo.base module#
- class promptmeteo.base.Base(language: str, model_name: str, model_provider_name: str, model_provider_token: str | None = None, model_params: Dict | None = None, prompt_domain: str | None = '', prompt_labels: List[str] = None, prompt_detail: str | None = None, selector_k: int = 10, selector_algorithm: str = 'relevance', verbose: bool = False, **kwargs)#
Bases:
ABC
Promptmeteo is a tool powered by LLMs, capable of solving NLP tasks such as text classification and Named Entity Recognition. Its interface resembles that of a conventional ML model, making it easy to integrate into MLOps pipelines.
Notes:#
- ‘Sun is setting on the New Republic. It’s time for the ResistencIA to rise’
Padmé Amidala, mother of Leia
- SELECTOR_TYPE: str = ''#
- TASK_TYPE: str = ''#
- property builder: TaskBuilder#
Get the TaskBuilder instance for the model.
- create_builder() TaskBuilder #
Create a TaskBuilder instance for the model.
- property init_params#
Get the initialization parameters of the model.
- property is_trained: bool#
Check if the model is trained.
- classmethod load_model(model_path: str) Self #
Load a saved model from disk.
- Parameters:
model_path (str) – Path from where the model will be loaded.
Returns –
------- –
Base – Loaded model instance.
- predict(examples: List[str]) List[str] #
Predict over new text samples.
- Parameters:
examples (List[str]) – List of text samples to predict.
Returns –
------- –
List[str] – List of predictions.
- save_model(model_path: str) Self #
Save the trained model to disk.
- Parameters:
model_path (str) – Path where the model will be saved.
Returns –
------- –
Base – Instance of the saved model.
- class promptmeteo.base.BaseSupervised(**kwargs)#
Bases:
Base
Base class for supervised training tasks.
- SELECTOR_TYPE: str = 'supervised'#
- train(examples: List[str], annotations: List[str]) Self #
Trains the model given use cases and notes on behaviour. Check the parameters and task behaviour in each specific model training docstring.
- class promptmeteo.base.BaseUnsupervised(**kwargs)#
Bases:
Base
Base class for unsupervised training tasks.
- SELECTOR_TYPE: str = 'unsupervised'#
- train(examples: List[str]) Self #
Trains the model given use cases and notes on behaviour. Check the parameters and task behaviour in each specific model training docstring.
promptmeteo.code_generator module#
- class promptmeteo.code_generator.CodeGenerator(**kwargs)#
Bases:
BaseSupervised
Code Generator Task.
This class represents a model for generating code based on natural language descriptions.
- Parameters:
**kwargs (dict) – Additional keyword arguments.
Example –
------- –
CodeGenerator (>>> from promptmeteo import) –
CodeGenerator( (>>> model =) –
language="en" (...) –
:param : :param … prompt_domain=”python”: :param : :param … model_provider_name=”openai”: :param : :param … model_name=”text-davinci-003”: :param : :param … model_provider_token=model_token: :param : :param … prompt_detail=[: :param … “add docstring in function definitions”: :param : :param … “add argument typing annotations”: :param : :param … ]: :param : :param … ): :param >>> pred = model.predict(: :param … [“A function that receives the argument foo and prints it.”]: :param … ): :param Returns: :param ——-: :param None:
- TASK_TYPE: str = 'code-generation'#
promptmeteo.constants module#
promptmeteo.document_classifier module#
- class promptmeteo.document_classifier.DocumentClassifier(**kwargs)#
Bases:
BaseSupervised
DocumentClassifier Task
This class represents a model for classifying documents into predefined categories.
Example:#
>>> from promptmeteo import DocumentClassifier >>> clf = DocumentClassifier( ... model_provider_name="hf_pipeline", ... model_name="google/flan-t5-small", ... prompt_labels=["positive", "negative", "neutral"], ... )
>>> clf.train( ... examples=["estoy feliz", "me da igual", "no me gusta"], ... annotations=["positive", "neutral", "negative"], ... )
>>> clf.predict(["que guay!!"])
>>> [["positive"]]
- TASK_TYPE: str = 'classification'#
- train(examples: List[str], annotations: List[str]) Self #
- Trains the model given use cases and notes on behaviour. Check the
parameters and task behaviour in each specific model training docstring.
Trains the DocumentClassifier model.
- examplesList[str]
List of document examples.
- annotationsList[str]
List of corresponding annotations.
Self
promptmeteo.document_qa module#
- class promptmeteo.document_qa.DocumentQA(**kwargs)#
Bases:
BaseUnsupervised
Question Answering over Documents Task
This class represents a model for answering questions based on documents.
Example:#
>>> from promptmeteo import DocumentQA >>> clf = DocumentQA( ... language="en", ... model_provider_name="hf_pipeline", ... model_name="google/flan-t5-small", ... )
>>> clf.train( ... examples=[ ... "The rain in spain is always in plain", ... "The logarithm's limit is the limit's logarithm", ... "To punish oppresors is clementy. To forgive them is cruelty", ... ], ... )
>>> clf.predict(["How is the rain in spain?"])
>>> [["in plain"]]
- TASK_TYPE: str = 'qa'#
promptmeteo.exceptions module#
promptmeteo.summarizer module#
- class promptmeteo.summarizer.Summarizer(**kwargs)#
Bases:
BaseUnsupervised
Class for text summarization
This class represents a model for text summarization.
Example:#
>>> from promptmeteo import Summarizer >>> model = Summarizer( ... language="es", ... prompt_domain="A partir del siguiente texto:", ... model_name="anthropic.claude-v2", ... model_provider_name="bedrock", ... )
>>> model.predict([text])
- TASK_TYPE: str = 'summarization'#
- classmethod load_model(model_path: str) Self #
Load a saved model from disk.
- model_pathstr
Path from where the model will be loaded.
- Base
Loaded model instance.
Loads a model artifact to make new predictions.
- model_pathstr
The path to the saved model artifact.
- selfSummarizer
The loaded Summarizer model.
- train() Self #
- Trains the model given use cases and notes on behaviour. Check the
parameters and task behaviour in each specific model training docstring.
Train the Summarizer model.
- selfSummarizer
The trained Summarizer model.
promptmeteo.tools module#
- promptmeteo.tools.add_docstring_from(parent_function)#
Decorator to concatenate a docstring from another function at the beginning.
- Parameters:
parent_function (function) – The function whose docstring will be used.
Returns –
------- –
decorator (function) – The decorator function.
Example –
------- –
foo() (>>> def) –
foo''' (... '''documentation for) –
pass (...) –
@add_docstring_from(foo) (>>>) –
bar() (>>> def) –
bar''' (... '''additional notes for) –
pass –
print(bar.__doc__) (>>>) –
foo (>>> documentation for) –
bar (>>> additional notes for) –
promptmeteo.validations module#
- promptmeteo.validations.validate_version_rest(api_version)#
Validates the version number for REST protocol.
- Parameters:
api_version (str) – The version number to validate.
Returns –
------- –
bool – True if the version number is valid, False otherwise.
- promptmeteo.validations.version_validation(api_version, api_protocol)#
Validates the version based on the provided protocol.
- Parameters:
api_version (str) – The version number to validate.
api_protocol (str) – The protocol to use for validation.
Returns –
------- –
bool – True if the version number is valid for the given protocol, False otherwise.
Raises –
------ –
ValueError – If the provided protocol is not supported.