{"id":19580463,"url":"https://github.com/vinpac/pipr","last_synced_at":"2026-05-27T16:32:19.745Z","repository":{"id":161755468,"uuid":"636407023","full_name":"vinpac/pipr","owner":"vinpac","description":null,"archived":false,"fork":false,"pushed_at":"2023-05-04T19:36:55.000Z","size":129,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-26T12:15:02.294Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/vinpac.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,"publiccode":null,"codemeta":null}},"created_at":"2023-05-04T19:27:39.000Z","updated_at":"2023-05-04T19:28:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"893f5c15-c622-4660-94b1-1f2647b7198e","html_url":"https://github.com/vinpac/pipr","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/vinpac/pipr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vinpac%2Fpipr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vinpac%2Fpipr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vinpac%2Fpipr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vinpac%2Fpipr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vinpac","download_url":"https://codeload.github.com/vinpac/pipr/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vinpac%2Fpipr/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33575511,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-27T02:00:06.184Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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-11-11T07:26:10.423Z","updated_at":"2026-05-27T16:32:19.726Z","avatar_url":"https://github.com/vinpac.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PIPR - Prepare Input to Prompt and Resolve\n\nPIPR is a library that helps you generate conversational AI prompts with ease. Pipr can be used to generate natural language responses to specific prompts by calling the OpenAI GPT-3 API. Pipr is designed to give better DX on writing prompt functions\n\n## Installation\n\nInstall `pipr` using npm or yarn:\n\n```bash\nnpm install @pipr/core\n```\n\n```bash\nyarn add @pipr/core\n```\n\n## Usage\n\nHere is an example usage of Pipr:\n\n```tsx\nconst getAge = createPipr()\n  .input(\n    z.object({\n      name: z.string(),\n      age: z.number(),\n    })\n  )\n  .prepare(({ age }) =\u003e {\n    return {\n      ...input,\n      age: age + 1,\n    };\n  })\n  .prompt({\n    system: 'You will remember everythin I say',\n    user: ({ name }) =\u003e `The age of ${input.name} is:`,\n  })\n  .history(({ input }) =\u003e [\n    {\n      user: `John is ${input.age - 1} years old`,\n      assistant: 'Nice to meet you, John!',\n    },\n    { user: `Alice is ${input.age + 1} years.`, assistant: 'Hello Alice!' },\n  ])\n  .resolve(ctx =\u003e {\n    return ctx.blocks[0].content;\n  });\n\nconst age = await getAge({ name: 'Alice', age: 44 });\nconsole.log(age); // 46\n```\n\n## `.input`\n\nThe `.input` method sets the schema for the input data. The schema should be defined using the `zod` library. The method returns a prompter instance that can be used to set the prompt configuration.\n\n```tsx\npipr.input(z.object({ name: z.string(), age: z.number() }));\n```\n\n## `.prepare`\n\nThe `.prepare` method sets a preparer function that will be called before the prompt is generated. The preparer function takes the raw input data as a parameter and returns a prepared input data that will be used to generate the prompt. This method can be used to fetch async data needed to add to the prompt.\n\n```tsx\npipr.input(schema).prepare(async rawInput =\u003e {\n  return {\n    name: rawInput.name.toUpperCase(),\n    age: rawInput.age * 2,\n  };\n});\n```\n\n## `.prompt`\n\nThe `.prompt` method sets the prompt configuration. The configuration is an object with `user` and `system` properties that represent the user's input and the AI's response, respectively. The properties can be set to a string or a function that returns a string.\n\n```tsx\npipr.input(schema).prompt({\n  user: 'What is your name?',\n  system: \"You're best greater\",\n});\n```\n\n## `.history`\n\nThe `.history` method sets a function that will be called to generate a history for the prompt. The function takes a `promptify` and `input` as a parameter and should return an array of prompt examples. Prompt examples are objects with a `user` and an `assistant` property that represent the user's input and the AI's response, respectively.\n\n```tsx\npipr\n  .input(schema)\n  .prompt({\n    system: 'Hi there! What can I do for you today?',\n    user: ({ name }) =\u003e `My name is ${name}. What is your name?`,\n  })\n  .history(async ({ promptify, prepare }) =\u003e {\n    const prepared = await prepare({\n      name: 'John',\n      age: 30,\n    });\n\n    return [\n      {\n        user: promptify(prepared).user, // My name is John. What is your name?\n        assistant: 'Hello John! My name is ChatGPT. How can I help you today?',\n      },\n    ];\n  });\n```\n\n## `.resolve`\n\nThe `.resolve` method is called after the request is sent to the Open AI API. It takes the OpenAI API responded and resolves the value to return.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvinpac%2Fpipr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvinpac%2Fpipr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvinpac%2Fpipr/lists"}