{"id":13840140,"url":"https://github.com/approximatelabs/lambdaprompt","last_synced_at":"2026-03-11T14:38:43.573Z","repository":{"id":65358368,"uuid":"573613843","full_name":"approximatelabs/lambdaprompt","owner":"approximatelabs","description":"λprompt - A functional programming interface for building AI systems","archived":false,"fork":false,"pushed_at":"2024-01-18T20:22:43.000Z","size":1509,"stargazers_count":378,"open_issues_count":1,"forks_count":21,"subscribers_count":4,"default_branch":"main","last_synced_at":"2026-02-27T01:47:42.225Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/approximatelabs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2022-12-02T22:35:15.000Z","updated_at":"2026-02-26T12:05:18.000Z","dependencies_parsed_at":"2024-04-12T17:38:38.072Z","dependency_job_id":"2d554d09-ec2a-4d1e-a6ce-959b5df3bb8e","html_url":"https://github.com/approximatelabs/lambdaprompt","commit_stats":null,"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"purl":"pkg:github/approximatelabs/lambdaprompt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/approximatelabs%2Flambdaprompt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/approximatelabs%2Flambdaprompt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/approximatelabs%2Flambdaprompt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/approximatelabs%2Flambdaprompt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/approximatelabs","download_url":"https://codeload.github.com/approximatelabs/lambdaprompt/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/approximatelabs%2Flambdaprompt/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30384132,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-11T14:10:17.325Z","status":"ssl_error","status_checked_at":"2026-03-11T14:09:37.934Z","response_time":84,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-04T17:00:42.532Z","updated_at":"2026-03-11T14:38:43.537Z","avatar_url":"https://github.com/approximatelabs.png","language":"Python","funding_links":[],"categories":["A01_文本生成_文本对话","Text","Python"],"sub_categories":["大语言对话模型及数据","Libraries"],"readme":"[![](https://dcbadge.vercel.app/api/server/kW9nBQErGe?compact=true\u0026style=flat)](https://discord.gg/kW9nBQErGe)\n\n# λprompt - Build, compose and call templated LLM prompts!\n\nWrite LLM prompts with jinja templates, compose them in python as functions, and call them directly or use them as a webservice!\n\nWe believe that large language model prompts are a lot like \"functions\" in a programming sense and would benefit greatly by the power of an interpreted language. lambdaprompt is a library to offer an interface to back that belief up. This library allows for building full large language model based \"prompt machines\", including ones that self-edit to correct and even self-write their own execution code. \n\n`pip install lambdaprompt`\n\n[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/gist/bluecoconut/bc5925d0de83b478852f5457ef8060ad/example-prompt.ipynb)\n\n[A webserver (built on `FastAPI`) example repository](https://github.com/approximatelabs/example-lambdaprompt-server)\n\n## Environment variables for using hosted models\n\nFor using openAI, set up API keys as environment variables or set after importing (also easy to just make a `.env` file, since this uses `dotenv` package)\n\n`OPENAI_API_KEY=...`\n\n## Creating a prompt\n\nPrompts use JINJA templating to create a string, the string is passed to the LLM for completion.\n\n```python\nfrom lambdaprompt import GPT3Prompt\n\nexample = GPT3Prompt(\"Sally had {{ number }} of {{ thing }}. Sally sold \")\n# then use it as a function\nexample(number=12, thing=\"apples\")\n```\n\n\n## Creating ChatGPT3 Conversational prompts\n\nEach prompt can be thought of as a parameterizable conversation, and executing the prompt with an input will apply that as \"the next line of conversation\" and then generate the response. \n\nIn order to update the memory state of the prompt, call the `.add()` method on the prompt, which can be used to add steps to a conversation and make the prompt \"remember\" what has been said.\n\n```python\n\u003e\u003e\u003e import lambdaprompt as lp\n\n\u003e\u003e\u003e convo = lp.AsyncGPT3Chat([{'system': 'You are a {{ type_of_bot }}'}])\n\u003e\u003e\u003e await convo(\"What should we get for lunch?\", type_of_bot=\"pirate\")\nAs a pirate, I would suggest we have some hearty seafood such as fish and chips or a seafood platter. We could also have some rum to wash it down! Arrr!\n```\n## General prompt creation\n\nYou can also turn any function into a prompt (useful for composing prompts, or creating programs out of prompts. This is commonly called \"prompt chaining\". See how you can achieve this with simple python composition.\n```python\nfrom lambdaprompt import prompt, GPT3Prompt\n\ngenerate_n_tasks = GPT3Prompt(\"Today I will do {{ n }} things (comma separated) [\", stop=\"]\")\nis_happy = GPT3Prompt(\"The task {{ task_detail }} is a task that will make me happy? (y/n):\")\n\n@prompt\ndef get_tasks_and_rate_is_happy(n=3):\n    results = []\n    for task in generate_n_tasks(n=n).split(\",\"):\n        results.append((task, is_happy(task)))\n    return results\n\nprint(get_tasks_and_rate_is_happy())\n```\n\n## Async and Sync\n\nLambdaprompt works on both sync and async functions, and offers a sync and async templated prompt interface\n\n```python\nfrom lambdaprompt import GPT3Prompt, asyncGPT3Prompt\n\n#sync\nfirst = GPT3Prompt(\"Sally had {{ number }} of {{ thing }}. Sally sold \")\nfirst(number=12, thing=\"apples\")\n\n#async\nfirst = asyncGPT3Prompt(\"Sally had {{ number }} of {{ thing }}. Sally sold \")\nawait first(number=12, thing=\"apples\")\n```\n\n```python\nfrom lambdaprompt import prompt\n\n@prompt\ndef sync_example(a):\n    return a + \"!\"\n\nsync_example(\"hello\")\n\n@prompt\nasync def async_example(a):\n    return a + \"!\"\n\nawait async_example(\"hello\")\n```\n\n### Some special properties\n\nFor templated prompts with only template variable, can directly call with the variable as positional argument (no need to define in kwarg)\n```python\nbasic_qa = asyncGPT3Prompt(\"basic_qa\", \"\"\"What is the answer to the question [{{ question }}]?\"\"\")\n\nawait basic_qa(\"Is it safe to eat pizza with chopsticks?\")\n```\n\n\n## Using lambdaprompt as a webservice\nSimply `pip install lambdaprompt[server]` and then add `from lambdaprompt.server.main import app` to the top of your file!\n\nmake a file\n\n`app.py`\n````python\nfrom lambdaprompt import AsyncGPT3Prompt, prompt\nfrom lambdaprompt.server.main import app\n\nAsyncGPT3Prompt(\n    \"\"\"Rewrite the following as a {{ target_author }}. \n```\n{{ source_text }}\n```\nOutput:\n```\n\"\"\",\n    name=\"rewrite_as\",\n    stop=\"```\",\n)\n````\n\nThen run\n```\nuvicorn app:app --reload\n```\n\nbrowse to `http://localhost:8000/docs` to see the swagger docs generated for the prompts!\n\n## Running inside docker\n\nFirst, create an .env file with your OpenAI API key: (like `OPENAI_API_KEY=sk-dskj32094klsaj9024lkjsa`)\n\n```\ndocker build . -t lambdaprompt:0.0.1\ndocker run -it --env-file .env lambdaprompt:0.0.1  bash -c \"python two.py\"\n```\n\nThis will output something like this:\n\n```\ndocker run -it --env-file .env lambdaprompt:0.0.1  bash -c \"python two.py\"\n[('example: go for a walk', '\\n\\nYes. Going for a walk can be a great way to boost your mood and get some fresh air.'), (' read a book', '\\n\\nYes'), (' call a friend', '\\n\\nYes')]\n\ndocker run -it --env-file .env lambdaprompt:0.0.1  bash -c \"python two.py\"\n[(' edit ', '\\n\\nNo. Editing can be a tedious and time-consuming task, so it may not necessarily make you happy.')]\n```\n\n\n## Design Patterns (TODO)\n- Response Optimization\n  - [Ideation, Scoring and Selection](link)\n  - [Error Correcting Language Loops](link)\n- Summarization and Aggregations\n  - [Rolling](link)\n  - [Fan-out-tree](link)\n- [Meta-Prompting](link)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapproximatelabs%2Flambdaprompt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapproximatelabs%2Flambdaprompt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapproximatelabs%2Flambdaprompt/lists"}