{"bugs":{"url":"https://github.com/propology/hopfield/issues"},"dist":{"shasum":"8c9739731e2ca6a2f5144b7b191cb7f6bd792df5","tarball":"https://registry.npmjs.org/hopfield/-/hopfield-0.2.0-canary.20230929T223717.tgz","fileCount":226,"integrity":"sha512-U44meOkU6hVhuXy7MlzRtDC1eNrNvlI86tLMmwnBngOT3j1VTyudAoEHELu9sR47RdoDC7K3gBPoPEtOoJEAuw==","signatures":[{"sig":"MEUCIQDAqcAGToZHyr9sxY8HmUiU3KrHr0pWtX1cWIT38GazLgIgcEJyOASTzjTa4GXLxfLriOxtNO+DJ6sUvp3bqmBMJu8=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1895650},"main":"./dist/cjs/index.js","name":"hopfield","types":"./dist/types/index.d.ts","module":"./dist/esm/index.js","readme":"<br/>\n\n<p align=\"center\">\n  <a href=\"https://hopfield.ai\">\n    <picture>\n      <source media=\"(prefers-color-scheme: dark)\" srcset=\"https://raw.githubusercontent.com/propology/hopfield/main/.github/hopfield-w-text.png\">\n      <img alt=\"Hopfield logo\" src=\"https://raw.githubusercontent.com/propology/hopfield/main/.github/hopfield-white-w-text.png\" width=\"auto\" height=\"120\">\n    </picture>\n  </a>\n</p>\n\n<div align=\"center\">\n  <a href=\"https://www.npmjs.com/package/hopfield\">\n    <picture>\n      <source media=\"(prefers-color-scheme: dark)\" srcset=\"https://img.shields.io/npm/v/hopfield?colorA=21262d&colorB=21262d&style=flat\">\n      <img src=\"https://img.shields.io/npm/v/hopfield?colorA=f6f8fa&colorB=f6f8fa&style=flat\" alt=\"Version\">\n    </picture>\n  </a>\n  <a href=\"https://www.npmjs.com/package/hopfield\">\n    <picture>\n      <source media=\"(prefers-color-scheme: dark)\" srcset=\"https://img.shields.io/npm/dm/hopfield?colorA=21262d&colorB=21262d&style=flat\">\n      <img src=\"https://img.shields.io/npm/dm/hopfield?colorA=f6f8fa&colorB=f6f8fa&style=flat\" alt=\"Downloads per month\">\n    </picture>\n  </a>\n  <a href=\"https://github.com/propology/hopfield/blob/main/LICENSE\">\n    <picture>\n      <source media=\"(prefers-color-scheme: dark)\" srcset=\"https://img.shields.io/npm/l/hopfield?colorA=21262d&colorB=21262d&style=flat\">\n      <img src=\"https://img.shields.io/npm/l/hopfield?colorA=f6f8fa&colorB=f6f8fa&style=flat\" alt=\"MIT License\">\n    </picture>\n  </a>\n</div>\n\n---\n\nTypescript-first LLM framework with static type inference, testability, and composability.\n\n```ts\nimport hop from \"hopfield\";\nimport openai from \"hopfield/openai\";\nimport OpenAI from \"openai\";\nimport z from \"zod\";\n\n// create an OpenAI hopfield client\nconst hopfield = hop.client(openai).provider(new OpenAI());\n\n// use description templates with Typescript string literal types\nconst categoryDescription = hopfield\n  .template()\n  .enum(\"The category of the message.\");\n\n// define functions for LLMs to call, with Zod validations\nconst classifyMessage = hopfield.function({\n  name: \"classifyMessage\",\n  description: \"Triage an incoming support message.\",\n  parameters: z.object({\n    summary: z.string().describe(\"The summary of the message.\"),\n    category: z\n      .enum([\n        \"ACCOUNT_ISSUES\",\n        \"BILLING_AND_PAYMENTS\",\n        \"TECHNICAL_SUPPORT\",\n        \"OTHERS\",\n      ])\n      .describe(categoryDescription),\n  }),\n});\n\n// create a client with function calling\nconst chat = hopfield.chat().functions([classifyMessage]);\n\nconst incomingUserMessage = \"How do I reset my password?\";\n\n// use utility types to infer inputs for a simple devex\nconst messages: hop.inferMessageInput<typeof chat>[] = [\n  {\n    content: incomingUserMessage,\n    role: \"user\",\n  },\n];\n\n// use the built-in LLM API calls (or just use the input/output Zod validations)\nconst parsed = await chat.get({\n  messages,\n});\n\n// get type-strong responses with `__type` helpers\nif (parsed.choices[0].__type === \"function_call\") {\n  // automatically validate the arguments returned from the LLM\n  // we use the Zod schema you passed, for maximum flexibility in validation\n  const category = parsed.choices[0].message.function_call.arguments.category;\n  await handleMessageWithCategory(category, incomingUserMessage);\n}\n```\n\n## TL;DR\n\nHopfield might be a good fit for your project if:\n\n- 🏗️ You build with Typescript/Javascript, and have your database schemas in these languages (e.g. [Prisma](https://www.prisma.io/) and/or [Next.js](https://nextjs.org/)).\n- 🪨 You don't need a heavyweight LLM orchestration framework that ships with a ton of dependencies you'll never use.\n- 🤙 You're using OpenAI function calling and/or custom tools, and want Typescript-native features for them (e.g. validations w/ [Zod](https://github.com/colinhacks/zod)).\n- 💬 You're building complex LLM interactions which use memory & [RAG](https://www.promptingguide.ai/techniques/rag), evaluation, and orchestration (_Coming Soon™_).\n- 📝 You want best-practice, extensible templates, which use [string literal types](https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html)\n  under the hood for transparency.\n\nOh, and liking Typescript is a nice-to-have.\n\n## Guiding principles\n\n- 🌀 We are Typescript-first, and only support TS (or JS) - with services like [Replicate](https://replicate.com/) or [OpenAI](https://platform.openai.com/docs/introduction), why do you need Python?\n- 🤏 We provide a simple, ejectable interface with common LLM use-cases. This is aligned 1-1 with LLM provider abstractions, like OpenAI's.\n- 🪢 We explicitly _don't_ provide a ton of custom tools (please don't ask for too many 😅) outside of the building blocks and simple examples provided. Other frameworks provide these, but when you use them, you soon realize the tool you want is very use-case specific.\n- 🧪 We (will) provide evaluation frameworks which let you simulate user scenarios and backend interactions with the LLM, including multi-turn conversations and function calling.\n- 🐶 We support Node.js, Vercel Edge Functions, Cloudflare Workers, and more (oh and even web, if you like giving away API keys).\n\n## Install\n\n```bash\npnpm add hopfield\n```\n\n```bash\nnpm i hopfield\n```\n\n```bash\nyarn add hopfield\n```\n\n## Documentation\n\nFor full documentation, visit [hopfield.ai](https://hopfield.ai).\n\n## Community\n\nIf you have questions or need help, reach out to the community at the [Hopfield GitHub Discussions](https://github.com/propology/hopfield/discussions)\nor join the [Propology Discord](https://discord.gg/2hag5fc6) and check out the `🐇-hopfield` channel.\n\n## Inspiration\n\nShoutout to these projects which inspired us:\n\n- [Zod](https://github.com/colinhacks/zod)\n- [zod-to-json-schema](https://github.com/StefanTerdell/zod-to-json-schema)\n- [Autochain](https://github.com/Forethought-Technologies/AutoChain)\n- [Langchain.js](https://github.com/hwchase17/langchainjs)\n- [simpleaichat](https://github.com/minimaxir/simpleaichat)\n- [Auto-GPT](https://github.com/Significant-Gravitas/Auto-GPT)\n- [abitype](https://github.com/wagmi-dev/abitype)\n\nIf you like Hopfield, go star them on Github too.\n\n## Contributing\n\nIf you're interested in contributing to Hopfield, please read our [contributing docs](https://github.com/propology/hopfield/blob/main/.github/CONTRIBUTING.md) **before submitting a pull request**.\n","exports":{".":{"types":"./dist/types/index.d.ts","import":"./dist/esm/index.js","require":"./dist/cjs/index.js"},"./openai":{"types":"./dist/types/openai/index.d.ts","import":"./dist/esm/openai/index.js","require":"./dist/cjs/openai/index.js"},"./package.json":"./package.json"},"gitHead":"24b5bdcb8f9b3faaceaf99f58fe1e171e4422764","license":"MIT","typings":"./dist/types/index.d.ts","_npmUser":{"name":"0xcadams","email":"me@0xcadams.com"},"homepage":"https://github.com/propology/hopfield#readme","keywords":["ai","openai","gpt","ai-tools"],"repository":{"url":"git+https://github.com/propology/hopfield.git","type":"git"},"_npmVersion":"9.8.1","description":"Typescript-first LLM framework with static type inference, testability, and composability.","directories":{},"maintainers":[{"name":"0xcadams","email":"me@0xcadams.com"}],"sideEffects":false,"_nodeVersion":"18.18.0","dependencies":{"zod-to-json-schema":"^3.21.4"},"typesVersions":{"*":{"openai":["./dist/types/openai/index.d.ts"]}},"_hasShrinkwrap":false,"readmeFilename":"README.md","peerDependencies":{"zod":"^3 >=3.21.4","openai":">=4.0.0","typescript":">=5.1.3"},"peerDependenciesMeta":{"openai":{"optional":true},"typescript":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/hopfield_0.2.0-canary.20230929T223717_1696027068933_0.5984082461304479","host":"s3://npm-registry-packages"},"_id":"hopfield@0.2.0-canary.20230929T223717","version":"0.2.0-canary.20230929T223717"}