Package: promptmeteo
PromptMeteo 🔥🧔Promptmeteois a Python library for Prompt Engineering built over LangChain. It simplifies the utilization of Language Model Models (LLMs) for various tasks through a low-code interface. To achieve this, Promptmeteo can employ different LLM models and dynamically generate prompts for specific tasks based on just a few configuration parameters.🤔 What is this library for?TL;DR: Industrialize projects powered by LLMs easily.LLMs have the capability to address various tasks when provided with specific instructions in the form of input prompts. They can function as a "reasoning engine" for constructing applications. However, deploying and industrializing these applications poses significant challenges for two main reasons.Firstly, prompts typically encapsulate application logic in their definition, yet they are treated merely as input arguments. This means that a poorly formulated prompt input has the potential to disrupt the application.Secondly, crafting concrete prompts for each task is not only a laborious task but also a complex one. Minor alterations in the input prompt can result in different outcomes, rendering them highly error-prone. Additionally, when composing prompts, considerations extend beyond the task itself to include factors such as the specific LLM being used, the model's capacity, and other relevant aspects.🚀 How do we solve it?TL;DR: Treating prompts and code equally!!!Promptmeteo aims to address the aforementioned issues by dividing the prompt definition into two distinct parts: the task logic, coded within prompt templates, and the concrete problem, included as argument variables. Promptmeteo incorporates high-level objects for various tasks, implemented through.pyand.promptfiles.🏠 Prebuilt tasksThe project incorporates high-level objects designed to address various NLP tasks, including text classification, Named Entity Recognition, and code generation. These objects only require configuration parameters for execution, eliminating the need to parse the output from the Language Model Models (LLMs).⚙️ Ease of DeploymentPromptmeteo modules adhere to a model interface similar to Scikit-Learn. By defining an interface with independent methods for training, predicting, saving, and loading the model, Promptmeteo enables training in a separate pipeline from prediction. This facilitates the reuse of conventional ML pipelines for LLM projects.📦 Model ArtifactsTo enhance results, LLMs can incorporate examples in their prompts. Promptmeteo supports training with examples, and for reproducibility, the training process can be stored as a binary model artifact. This allows storing and reusing training results multiple times with new data. The training process stores embeddings from the input text in a vector database, such as FAISS.⚙️ LLMs IntegrationPromptmeteo integrates different LLMs through LangChain. This includes models that can be executed locally and remote API calls from providers like OpenAI and HuggingFace.📄 Prompt TemplatingEstablishing a concrete format for creating prompts in Promptmeteo (.prompt) not only facilitates programmatic use but also enables versioning of prompts. This approach aids in understanding changes when they occur and allows for the definition of code tests oriented toward prompt testing. This testing encompasses aspects such as validating language use and ensuring the prompt size is appropriate for the model.TEMPLATE:"Ineedyoutohelpmewithatextclassificationtask.{__PROMPT_DOMAIN__}{__PROMPT_LABELS__}{__CHAIN_THOUGHT__}{__ANSWER_FORMAT__}"PROMPT_DOMAIN:"Thetextsyouwillbeprocessingarefromthe{__DOMAIN__}domain."PROMPT_LABELS:"Iwantyoutoclassifythetextsintooneofthefollowingcategories:{__LABELS__}."PROMPT_DETAIL:""CHAIN_THOUGHT:"Pleaseprovideastep-by-stepargumentforyouranswer,explainwhyyoubelieveyourfinalchoiceisjustified."ANSWER_FORMAT:"Inyourresponse,includeonlythenameoftheclassasasingleword,inlowercase,withoutpunctuation,andwithoutaddinganyotherstatementsorwords."⚡ Quick startFirst of all, do not forget to configure providers credentials. Refer to theconfigure credentials section.✨ Create the taskYou can make a prediction directly indicating the model and calling the methodpredict().frompromptmeteoimportDocumentClassifierclf=DocumentClassifier(language='en',model_provider_name='hf_pipeline',model_name='google/flan-t5-small',prompt_labels=['positive','neutral','negative'])clf.predict(['so cool!!'])[['positive']]✨ Train the taskBuy you can also include examples to improve the results by calling the methodtrain()clf=clf.train(examples=['i am happy','doesnt matter','I hate it'],annotations=['positive','neutral','negative'],)clf.predict(['so cool!!'])[['positive']]✨ Save a trained taskOne the model is trained it can be saved locallyclf.save_model("hello_world.meteo")✨ Load a trained taskand loaded again to make new predictionsfrompromptmeteoimportDocumentClassifierclf=DocumentClassifier(language='en',model_provider_name='hf_pipeline',model_name='google/flan-t5-small',).load_model("hello_world.meteo")clf.predict(['so cool!!'])[['positive']]Models can also be loaded without instantiating the class by using load_model as a function instead of a method:frompromptmeteoimportDocumentClassifierclf=DocumentClassifier.load_model("hello_world.meteo")✨ Learn moreMore examples can be seen in the directoryexamples.🚗 Usage⚙️ Configure credentialsCreate a.envwith the following variables depending on the LLM providerGoogle CloudFirst you should create aService Accountwith the role:Vertex AI User.Once created, generate a key, store it locally and reference the path in the .env file:GOOGLE_CLOUD_PROJECT_ID="MY_GOOGLE_LLM_PROJECT_ID"GOOGLE_APPLICATION_CREDENTIALS="PATH_TO_SERVICE_ACCOUNT_KEY_FILE.json"OpenAICreate your Secret API key in your User settingspage.Indicate the value of the key in your .env file:OPENAI_API_KEY="MY_OPENAI_API_KEY"You can also passopenai_api_keyas a named parameter.Hugging FaceCreate Access Token in your User settingspage.HUGGINGFACEHUB_API_TOKEN="MY_HF_API_KEY"You can also passhuggingfacehub_api_tokenas a named parameter.⚙️ Install locallymakesetup⚙️ Run with dockerdockerbuild-tpromptmeteo:latest.
dockerrun--rm-i-t-v.:/homepromptmeteo:latest⚙️ Run testsmake test📋 Current capacilities✅ Available tasksThe current available tasks in Promptmeteo are:task_typedescriptionDocumentQADocument-level question answeringDocumentClassifierDocument-level classificationCodeGeneratorCode generationApiGeneratorAPI REST generationApiFormatterAPI REST correction✅ Available ModelThe current availablemodel_nameandlanguagevalues are:model_providermodel_namelanguageopenaigpt-3.5-turbo-16kesopenaigpt-3.5-turbo-16kenazuregpt-3.5-turbo-16kesazuregpt-3.5-turbo-16kenhf_hub_apigoogle/flan-t5-xxleshf_hub_apigoogle/flan-t5-xxlenhf_pipelinegoogle/flan-t5-smalleshf_pipelinegoogle/flan-t5-smallengoogletext-bisonesgoogletext-bisonengoogletext-bison@001esgoogletext-bison@001engoogletext-bison-32kesgoogletext-bison-32ken