Package: promptogen
PromptoGenBridging LLMs and Python Seamlessly.Documentation:https://promptogen.zawakin.devSource Code:https://github.com/zawakin/promptogenGetting Started:https://promptogen.zawakin.dev/getting-started/installationen - Englishja - 日本語PromptoGen: Achieving efficient and expandable communication with LLM🚀 Vision"Seamlessly bridge the gap between LLM and Python, ensuring efficient, future-ready communication."💡 Key Challenges in LLM Libraries:Lack of an ecosystem for prompt engineering, making prompt creation and sharing difficult.Strong dependency on specific LLM versions, making them vulnerable to LLM updates.Complex implementations, hindering customization.🎯 Why Choose PromptoGen?Seamless Conversion between LLM I/O and Python Objects: Streamlining LLM interactions.Flexible & Unique Interface: Guaranteeing user customizability and extensibility.Future-Proof Design: Stay ahead with reduced dependency on LLM evolutions.Compared to Other Libraries: Many are tied to specific LLM versions, lacking the adaptability that PromptoGen offers. With a dependency only on thePydanticdata class library, PromptoGen serves as the ideal bridge between LLM strings and Python objects.🛠️ Core Features:PromptData Class: Standardizing LLM communication and supporting prompt engineering.TextLLMInterface: Independence from LLM specifics.PromptFormatterInterface: High customizability for users.🎉 Benefits:🧩Modular & Extendable: Flexibly mix, match, and add custom components.🛡️Future-Proof: Stand strong against new model updates.🔧Maintainability: Ensuring easy debugging and minimal adjustments for different LLMs.⚠️ Unsupported Features:Direct LLM Communication: We prioritize efficient interfacing over direct LLM conversations.Prompt Version Management: To keep things streamlined, we avoid adding versioning complexities.Specific LLM Optimization: Our focus is on adaptability across LLMs rather than optimizing for any single one.📚 Learn MoreDive deep into thedocumentationfor a comprehensive understanding.RequirementsPython 3.8 or aboveInstallationpipinstallpromptogenImportingimportpromptogenaspgHow to UseCreating your Promptimportpromptogenaspgsummarizer=pg.Prompt(name="Text Summarizer and Keyword Extractor",description="Summarize text and extract keywords.",input_parameters=[pg.ParameterInfo(name="text",description="Text to be summarized"),],output_parameters=[pg.ParameterInfo(name="summary",description="Summarized text"),pg.ParameterInfo(name="keywords",description="Extracted keywords from the text"),],template=pg.IOExample(input={'text':"This is a sample text for summarization."},output={'summary':"This is a summary of the text.",'keywords':["sample","text","summarization"],},),examples=[pg.IOExample(input={'text':"One sunny afternoon, a group of friends opted to meet at the nearby park to indulge in various sports and activities. They engaged in soccer, badminton, and basketball, reveling in the joy of camaraderie and crafting unforgettable moments together."},output={'summary':"A bunch of friends relished an afternoon of sports and bonding at a neighborhood park.",'keywords':["friends","park","sports","moments"],},)],)Saving the Promptsummarizer.to_json_file("summarizer.json")Loading the Promptimportpromptogenaspgsummarizer=pg.Prompt.from_json_file("summarizer.json")For more information, please refer toPrompt.Format your Prompt as a StringTo send an instance of thePromptclass to the LLM (Large Language Model) in actual use, you need to convert it into a string. With PromptoGen, you can usepg.PromptFormatterto convert the prompt into a string in any desired format.importpromptogenaspgsummarizer=pg.Prompt(name="Text Summarizer and Keyword Extractor",# ...)formatter=pg.KeyValuePromptFormatter()input_value={"text":"In the realm of software engineering, ...",}print(formatter.format_prompt(summarizer,input_value))Console Output:Summarize text and extract keywords.Input Parameters:- text: Text to summarizeOutput Parameters:- summary: Summary of text- keywords: Keywords extracted from textTemplate:Input:text: "This is a sample text to summarize."Output:summary: "This is a summary of the text."keywords: ['sample', 'text', 'summarize']Example 1:Input:text: "One sunny afternoon, a group of friends decided to gather at the nearby park to engage in various games and activities. They played soccer, badminton, and basketball, laughing and enjoying each other's company while creating unforgettable memories together."Output:summary: "A group of friends enjoyed an afternoon playing sports and making memories at a local park."keywords: ['friends', 'park', 'sports', 'memories']--------Input:text: "In the realm of software engineering, ..."Output:Parsing Outputs from Large Language ModelsAfter receiving the prompt string as input, you obtain an output from a large language model (like GPT-3.5, GPT-4).LLM Output:summary: "This is a summary of the text."keywords: ['sample', 'text', 'summarize']You can parse this output as:importpromptogenaspgformatter=pg.KeyValuePromptFormatter()raw_resp="""summary: "This is a summary of the text."keywords: ['sample', 'text', 'summarize']"""summarized_resp=formatter.parse(summarizer,raw_resp)print(summarized_resp){'summary': 'This is a summary of the text.', 'keywords': ['sample', 'text', 'summarize']}TextLLM: Flexible LLM IntegrationThroughpg.TextLLM, PromptoGen achieves collaboration with a variety of large-scale language models (LLM).importpromptogenaspgclassYourTextLLM(pg.TextLLM):def__init__(self,model:str):self.model=modeldefgenerate(self,text:str)->str:returngenerate_by_your_text_llm(text,self.model)text_llm=YourTextLLM(model="your-model")By adopting this interface, PromptoGen can seamlessly incorporate different LLMs and their versions. Users can utilize various LLMs in a consistent manner regardless of the specific LLM.For more information, please refer toTextLLM.PromptRunner: Execute Prompts Efficientlypg.PromptRunnersupports the execution of prompts simply and efficiently.importpromptogenaspg# Prepare an LLM that implements the `pg.TextLLM` interfacetext_llm=YourTextLLM(model="your-model")formatter=pg.KeyValuePromptFormatter()runner=pg.TextLLMPromptRunner(llm=text_llm,formatter=formatter)summarizer=pg.Prompt(name="Text Summarizer and Keyword Extractor",# ...)input_value={"text":"In the realm of software engineering, ...",}output_value=runner.run_prompt(summarizer,input_value)print(output_value)pg.PromptRunneris a key tool for making prompt execution more intuitive and efficient using PromptoGen.For more information, please refer toPromptRunner.Quick Start GuidePlease refer to theQuick Start Guide.Application ExamplesRefer toApplication Examples.Translation InterceptorAuto Prompt GenerationLLM I/O Inferences GenerationDependent LibrariesPromptoGen only depends onPydanticto define the data class.LimitationsWith updates to PromptoGen, compatibility with prompts outputted in JSON may be lost.The large language models tested for operation are OpenAI'sgpt-3.5-turbo,gpt-4, and Meta'sLlama 2. Other large language models have not been tested for operation. In particular, there may be cases where the parser does not work correctly, so please be cautious.ContributionBug reports, proposals for new features, pull requests, etc., are all welcome! For more details, please seeContribution.LicenseMIT License