{"id":15480967,"url":"https://github.com/pyronaur/zod-mind","last_synced_at":"2026-04-28T08:38:22.466Z","repository":{"id":165633356,"uuid":"640889897","full_name":"pyronaur/zod-mind","owner":"pyronaur","description":"Type-safe interaction with LLMs like GPT","archived":false,"fork":false,"pushed_at":"2023-10-22T07:42:01.000Z","size":731,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-23T17:07:07.533Z","etag":null,"topics":["llm","npm-package","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/zod-mind","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pyronaur.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"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-15T10:44:14.000Z","updated_at":"2024-08-19T22:26:27.130Z","dependencies_parsed_at":null,"dependency_job_id":"cb3c64e5-98ce-4adc-94c6-13cae36a8a63","html_url":"https://github.com/pyronaur/zod-mind","commit_stats":{"total_commits":108,"total_committers":1,"mean_commits":108.0,"dds":0.0,"last_synced_commit":"c67fc89a246989c1ede752cc8d265d9bd58bd67d"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyronaur%2Fzod-mind","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyronaur%2Fzod-mind/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyronaur%2Fzod-mind/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyronaur%2Fzod-mind/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pyronaur","download_url":"https://codeload.github.com/pyronaur/zod-mind/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246045588,"owners_count":20714802,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["llm","npm-package","typescript"],"created_at":"2024-10-02T05:00:54.380Z","updated_at":"2026-04-28T08:38:22.421Z","avatar_url":"https://github.com/pyronaur.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🧠 Zod Mind\n\n**OpenAI Function library with Zod and TypeScript type safety.** Built to\nfacilitate interactions with the OpenAI API in a type-safe manner. This package\nincludes a variety of tools for communicating with the OpenAI API using\ntype-safe requests and responses.\n\n## 🚀 Getting Started\n\n### Installation\n\nTo install the package, run the following command in your terminal:\n\n```bash\nnpm install zod-mind\n```\n\n## Usage\n\n`zodMind()` is the primary function for interacting with the Zod Mind library,\nwhich provides a structured interface to the OpenAI API.\n\n```typescript\n// Step 1: Create a Zod Mind instance\nconst client = zodMind( {\n\topenai: {\n\t\tmodel: \"gpt-3.5-turbo\",\n\t\ttemperature: 0.5,\n\t},\n\t// Replace this with your actual API key\n\tapi_key: \"sk-WUBbaLuBbAdUBDUBmEanSIAMInGREaTPAInp1she1PME\",\n} );\n\n// Step 2: Send a message to OpenAI\nasync function fetchAnswer() {\n\ttry {\n\t\tconst prompt = \"What is the meaning of life?\";\n\t\tconst result = await client.chat( prompt );\n\t\tconsole.log( result );\n\t} catch ( error ) {\n\t\tconsole.error( error );\n\t}\n}\n```\n\nYou can provide [OpenAI's API options](https://www.npmjs.com/package/opena)\nusing the `openai` of the `zodMind()` function.\n\nRemember to replace `'sk-WUBbaLuBbAdUBDUBmEanSIAMInGREaTPAInp1she1PME'` with\nyour actual API key. Never expose this key publicly. It is generally recommended\nto store it in an environment variable or a secure secret storage.\n\n**Environment Variable**\nZod Mind is going to attempt to read `OPENAI_API_KEY` from your environment if no key is provided to the `zodMind()` function.\n\n### Structured Chat\n\nStructured chat refers to an organized and formatted way of communicating with\nthe AI with a predefined schema to guide AI's responses. It allows you to use a chat interface that\nhandles both the instruction and the desired response format.\n\nThe `structured_chat` method takes two parameters:\n\n1. `message`: A string that serves as the instruction to the AI.\n2. `zod_schema`: A Zod schema that defines the format of the AI's response.\n\nNote: The schema should always be at the very least a Zod Object, like so:\n\n```typescript\nconst results = await client.structured_chat( \"What is the meaning of life?\", z.object( {\n\tanswer: z.string()\n} ) );\n```\n\nThe method returns a structured response from the AI that matches the given Zod\nschema or it will throw a validation error.\n\n### Invoke Functions\n\nThe `invoke` method allows the AI to call a function from a predefined list of\nfunctions based on a given message.\n\nThe `invoke` method takes three parameters:\n\n1. `message`: A string that serves as the instruction to the AI.\n2. `functions`: An object mapping function names to GPT_Function definitions.\n3. `function_call`: An optional parameter that specifies which function to call.\n   If it's not provided, the AI will decide which function to call based on the\n   message.\n\n```typescript\nconst functions = {\n\t\"random_number\": {\n\t\tdescription: \"Generate a random number between two numbers.\",\n\t\tschema: z.object( {\n\t\t\tfrom: z.number(),\n\t\t\tto: z.number()\n\t\t} )\n\t},\n\t\"random_quote\": {\n\t\tdescription: \"Generate a random quote.\",\n\t\tschema: z.object( {\n\t\t\tquote: z.string()\n\t\t} )\n\t}\n};\nconst result = await client.invoke( \"Random number between 1 and 42\", functions );\nif ( result.name === \"random_number\" ) {\n\tconst random_number = random_number_generator( result.arguments.from, result.arguments.to );\n\tapp.debug( `GPT is calling function \"${ result.name }\"` )\n\t\t.debug( \"With Arguments:\", result.arguments )\n\t\t.info( `The random number is ${ random_number }` );\n} else {\n\tapp.error( `GPT is calling function \"${ result.name }\"` ).error( \"With Arguments:\", result.arguments );\n}\n```\n\nThe `invoke` method returns an object that includes the name of the function\ncalled and its arguments, formatted according to the appropriate Zod schema.\n\n**Force Function Call**\nIf you want to force the AI to call a specific function, you can do so by passing the third argument to the `invoke` method:\n\n```typescript\nconst result = await client.invoke( \"Random number between 1 and 42\", functions, \"random_number\" );\n```\n\n### Simple Chat\n\nEven though this library is designed with type-safety in mind, you can just call\nsimple `chat` methods without type safety if you need to.\n\n```typescript\nconst result = await client.chat( \"What is the answer to life?\" );\n```\n\n### System Message\nIf you want to customize the system message, you can do so using the `set_system_message()`\nmethod:\n\n```typescript\nclient.set_system_message( \"This is a custom system message.\" );\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpyronaur%2Fzod-mind","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpyronaur%2Fzod-mind","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpyronaur%2Fzod-mind/lists"}