0% found this document useful (0 votes)
53 views6 pages

Prompts For Large Language Models

A library for helping developers craft prompts for Large Language Models

Uploaded by

Marcos Luis
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
53 views6 pages

Prompts For Large Language Models

A library for helping developers craft prompts for Large Language Models

Uploaded by

Marcos Luis
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 6
9115124, 8:21 AM GitHub miccosofprompt-engine: A ibrar for helping developers craft prompts for Large Language Modsls B microsoft / prompt-engine rite ‘library for helping developers craft prompts for Large Language Models MIT lcense ‘fr 25kstars Y w5tfors Branches Q Tags Achy se 1 Neteations © Code © tssves 5 Th Pulleauests 3 @ Actions (E} Projects © Securty Le sights main = PSbrancher Oats PO Q Goto Goto fie ode iar erge pl quest #20 trom microsof/abhshekstreseg-and-newlne-end ansisss-2yeanago canes Roactored model conf tobe present in prom. years 390 Be se Added start sequence an neatine end lt sn years 290 me tes Added start sequence and nesting end ml tn 2 years 290 D sitgnore ina com 2yeat 399 Di rpmignore ‘cided pignore and ewed package version 2 yeas 290 D cove.oF,conouctina (CODE, OF CONDUCT nd canned 2 yeas 290 1B ucense LUCENE commits yeas 290 D rexomems Refctored model conto be present in prom. yeas 290 D secuatvina SECURITY nd consid 2yeas 290 D) suProatna SUPPORT commited years age D isstcontgis Intl comm 2yeas 90 D. packagetccison ‘Addo VAML support ko changed newline es, 2s 390 D1 packagejson reve package version to 003 2yest 350 D tscontsiton ‘dd ies fo inking te pceage yea 350 CO README © Codect conduct SB MIT lkanse oD Secuty Prompt Engine ‘This epo contains an NPM uty Roary for creating and maintaining prompts for Large Language Modal (LLM) Background Lume ike GPT-3 and Codex have continued to push the bounds of what Alis capable of - they can capably generate language and code, but ate also capable of emergent behaviorlike question answering, summarization, classification and dialog. One ofthe best techniques for ‘enabling specific behavior out of LLMs s calle prompt engineering - crafting Inputs that coax the model to produce certain kinds of outputs Few-shot promoting isthe discipline of giving examples af inputs and outputs, such thatthe model has a reference for the type of output you're looking for. Prompt engineering can be as simple as formatting a question and passing it to the model, but it Code prompts should also have examples of NL->Code interactions, exemplifying the kind of code you expect the model to produce. Ir this case, the inputs are math queries (e.g, "what 2 « 27") and code that console lags the result of the query. const examples = [ e input a plus 28°, response: “console.tog (input: “what's 18 tines 18°, response: *console-Log(t@ * 18)* Jy By default, codotngine uses JavaScript asthe programming language, but you can create prompts for diferent languages by passing 2 Aifferent Codeeronptcontig into the constructor. I for example, we wanted to produce Python prompts, we could have passed Cosoengine @ pythoncontse specifying the comment operator it should be usin: const pythencontig htps:igihub.comimicrosofiprompt-engine 9115124, 8:21 AM GitHub miccosofprompt-engine: A ibrar for helping developers craft prompts for Large Language Modsls ) onst codstnaine = now Codctneire(cescription, examples, flowiesettext, pythencontig)s [With our description and our examples, we can go ahead and create our cosatngine const codstnaine = row Codctneire(description, examples); e Now that we have our codeéngine, We can use ito create prompts: const query const pronpt ‘nats 1018 tines the ninth power of four?™s @ odetngine. but LdPronpe (query): The esuting prompt willbe a string withthe description, examples andthe latest query formatted with comment operators and line breaks: 1+ natural Langunge Contanés to Javascript Math Code, the code should log the result of the command to the console o + wats 30 plus 28 +/ ‘congole, log(18 + 18); onsale. Tog(3® * 18); {Gwen the context a capable cade generation model can take the above prompt and guess the next line: console. 2og{i018 * vath.pow(s, os Fr mul-tum scenarios, where past conversations influences the next turn, Code Engine enables Us to persist interactions ina prompt e 17 sasumes existence of cade generation mdel et code = model. genenatecoue(proapt); odetngine.sudintersction(query, code); [Now new prompts wll nclude the latest NL-> Code interaction oceéngine.bstiaProrot ("Hou about the Bt poser?")s e Produces a prompt identical to the one above, but with the NL->Code dialog history o onsale oe 8 * math. owl, 995 1+ How shout the Ath power? +) With this context, the code generation mall has the dlalog context needed to understand what we mean by the quer. In this ease, the model would crrecty generate conso2e.204(S619 * Wath.pou(, 8); Chat Engine ust ke Code Engine, Chat Engine creates prompts with descriptions and examples. The difference i that Chat Engine creates prompts for clalog scenarios, where both the user and the model use natural language. The chatengine constructor takes an optional chatconfig argument, which allows you to define the name ofa user and chatbot in a mult-turn dial: sees "Ayan", htps:igihub.comimicrosofiprompt-engine 38 9115124, 8:21 AM Github- miccosoflprompt-engine: A Ibrar fr helping developers craft prompts for Large Language Models bots “eondon* ® Chat prompts also benefit from a description that gives contest. This description helps the madel determine how the bet should respond. “const desertption « "A conversation with Gorgon the snxsous Robot. Gordon tends to reply nervously ard athe 2 lot of foltowup « | . Similarly, Chat Engine prompts can have examples interactions: const examples = [ o ‘Csnpitt "ano 4368 you?" response: °T don't krou nan! That's an awfully extstentsal question. How woulé you answer $7"), {Cinput: “Gand patnt = do you at least know what you were made for?", response: *K'm QK at riveting, but that's nat how 1 shot ‘These examples help set the tone of the bot inthis case Gordon the Anxious Robot, Now we can create out chatengine and Useitto create prompts: “const chatEngine = rou ChatEngine(desensption, examples, flowesetText, chaténginecont ig): @ const userquery = “wat are you nade of?" ‘const prompt ~ chatEngive. bul dPronpt(userquery); When passed to» large language model (eg, GPT-3}, the context of the above prompt will help coax. good answer rom the model, tke "Subatomic paticles at some level. but somehow | don't think that's what you were asking. As with Code Engine, we can persist this answer ‘and continue the dialog such thatthe model is aware ofthe conversation context ‘atinginesddinteraction(userQuery, “Subatonic particles at sone level, Sut somehow I don't think that's what you were asking.” © + Managing Prompt Overflow Prompts for Large Language Models generally have limite size, depending on the language model being used. Given that prompt-engine can persist dialog history, itis possible for dialogs to get so long that the prompt overflows. The Prompt Engine pattern handles this situation by ‘removing the oldest dialog interaction from the promt, effectively nly remembering the most recent interactions. You can specify the maximum tokens allowed in your prompt by passing a naxTokens parameter when constructing the config for any promot engine let prowptengine = nex Pronptingine( description, examples, flawfesetText, { o rnodelContig: { waxTokens: 1060 } Ds Available Functions ‘The following are the functions available on the Pranpténgine class and those that inherit from it command Param Description Returns ‘Constructs and return the contest wth parameters meorsens Nene provided tothe Prompt Engine Content string wore Pron tng Contin creator wanes 2 page ping Builds acialog based on all the past interactions butléDialog None aed to the Prompt Engine Dialog: sting ineeraction:Iteraction(input string sadexanple a response: sting) ‘Adds the given example to the examples None htps:igihub.comimicrosofiprompt-engine 5 115124, 8:21 AM GitHub microsofprompt-engine: A ibrar fr helping developers craft prompts for Largs Language Modsls command Parameters Description Returns Interaction: Interaction(input string sdaznteraction ‘Adds the given interaction tothe dials None Fesponse: string) i ? avoreirstunteraction | None Removes and retuins the fist interaction inthe Interaction dialog sting venovetas None Removes and reins the last interaction added to Interaction the dialog sting Removes al interactions fram the dialog, returin “ None ° "9 Contextstring the reset context For more examples and insights into using the prompt-engine library, have a look atthe examples folder YAML Representation Ik can be useful to represent prompts as standalone fles, versus code, This can allow easy swapping between diferent prompts, prompt versioning, and other advanced capabilites. With ths in mind, prompt-engine offers a way to represent prompts as YAML and to load that YAML into a prompt-engine class. See examples/yanl-exanples for examples of YAML prompts and how they're loaded into prompt-engine. Contributing This project welcomes contributions and suggestions. Most contributions requte you to agree to 8 Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For deta, visit hntps//la opensource microsaftcom ‘when you submit a pull request, 3 CLA bot wll automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g, status check, comment. Simply follow the instructions provided by the bot. You will only need to de this once across all repos using our cua This project has adopted the Microsoft Open Source Code of Conduct, For more information See the Code of Conduct FAQ or contact ‘opencodie@microsoft com with any additional questions or comments Statement of Purpose This library aime to simplify use of Large Language Model, and to make it easy for developers to take advantage of existing pattems, The package is released in conjunction withthe Build 2022 Al examples, as the fist three use a mult-tumm LLM patter tha this brary simplifies. This package works independently af any specific LUM ~ prompt generated by the package should be useable with various language and code ‘generating models. Trademarks Releases Packages Contributors 4 @ ricostopmsome so htps:igthub.comimicrosofiprompt-engine 56 9si24, 8:21 AM CGithub- microsofprompt-engine: A library for helping developers craft prompts for Largs Language Models nae Nar Karle Languages ritpssigthub.convmicrosafpromat-engine as

You might also like