{"id":26923816,"url":"https://github.com/galiprandi/fastify-lm","last_synced_at":"2026-03-06T04:31:51.566Z","repository":{"id":280560691,"uuid":"942405190","full_name":"galiprandi/fastify-lm","owner":"galiprandi","description":"Use OpenAI, Claude, Google, Deepseek, and others LMs with one Fastify plugin.","archived":false,"fork":false,"pushed_at":"2025-04-24T11:57:53.000Z","size":370,"stargazers_count":6,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-19T11:59:06.273Z","etag":null,"topics":["claude","deepseek","fastify","gemini","mistral","openai","plugin","typescript"],"latest_commit_sha":null,"homepage":"https://github.com/galiprandi/fastify-lm#readme","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/galiprandi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":"docs/support-bot.md","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-03-04T04:00:53.000Z","updated_at":"2025-05-30T15:52:58.000Z","dependencies_parsed_at":null,"dependency_job_id":"2ac3b1d7-5da9-4ded-af95-c6059c08d228","html_url":"https://github.com/galiprandi/fastify-lm","commit_stats":null,"previous_names":["galiprandi/fastify-lm"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/galiprandi/fastify-lm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/galiprandi%2Ffastify-lm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/galiprandi%2Ffastify-lm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/galiprandi%2Ffastify-lm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/galiprandi%2Ffastify-lm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/galiprandi","download_url":"https://codeload.github.com/galiprandi/fastify-lm/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/galiprandi%2Ffastify-lm/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30161743,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-06T04:22:03.816Z","status":"ssl_error","status_checked_at":"2026-03-06T04:22:00.183Z","response_time":250,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5: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":["claude","deepseek","fastify","gemini","mistral","openai","plugin","typescript"],"created_at":"2025-04-02T01:42:46.957Z","updated_at":"2026-03-06T04:31:51.546Z","avatar_url":"https://github.com/galiprandi.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fastify-lm  \n\n## What is fastify-lm?  \n\n`fastify-lm` is a **Fastify plugin** that simplifies integration with multiple **language model (LM) providers**, such as:  \n\n| Provider  | Description                          |\n|-----------|--------------------------------------|\n| **Test**  | Test provider, always returns \"test\" and the input parameters |\n| **OpenAI**  | GPT models, including GPT-4o, GPT-3.5 |\n| **Google**  | Gemini models, such as Gemini 1.5  |\n| **Claude**  | Anthropic’s Claude models (Claude 3, etc.) |\n| **Deepseek** | Deepseek AI language models        |\n| **Llama** | Llama AI language models            |\n| **Mistral** | Mistral AI language models         |\n\nIt provides a **unified interface**, allowing you to switch providers without modifying your application code.  \n\n### 🔥 **Why use fastify-lm?**  \nDeveloping applications that interact with language models usually requires direct API integration, which can lead to:  \n- 🔗 **Dependency on a single provider**  \n- 🔄 **Difficulty switching models without refactoring code**  \n- ❌ **Inconsistencies in how different APIs are used**  \n\nWith `fastify-lm`, you can:  \n✅ Define multiple providers in a single configuration  \n✅ Switch models just by changing environment variables  \n✅ Use a **consistent query system** without worrying about API differences  \n✅ Easily run A/B tests with different models to find the best fit for your use case  \n\n### 🛠 **Use Cases**  \n- **Chatbots and virtual assistants**: Seamlessly integrate multiple AI models to enhance user experience.  \n- **Natural Language Processing (NLP)**: Analyze text using different models without modifying your code.  \n- **Model comparison**: Evaluate different LMs within the same application with minimal changes.  \n- **Flexible infrastructure**: Switch providers based on availability, cost, or technological improvements.\n- **Analyze requests**: Moderate or analyze requests using language models.\n\n🚀 **Ready to get started?** Continue with the installation guide and start using `fastify-lm` in just a few minutes.  \n\n## Installation\n\nTo install the plugin, on existing Fastify project, just run:\n\n```bash\nnpm install fastify-lm\n```\n\n### Compatibility\n\n| fastify-lm (plugin) | Fastify            |\n| ------------------- | ------------------ |\n| `^1.x`              | `^3.x, ^4.x, ^5.x` |\n\nPlease note that if a Fastify version is out of support, then so are the corresponding versions of this plugin\nin the table above.\nSee [Fastify's LTS policy](https://github.com/fastify/fastify/blob/main/docs/Reference/LTS.md) for more details.\n\n## Quick start\n\nStart by creating a Fastify instance and registering the plugin.\n\n```bash\nnpm i fastify fastify-lm\n```\n\nCreate a file `src/server.js` and add following code:\n\n```javascript\n// Import the framework and instantiate it\nimport Fastify from \"fastify\";\nimport LmPlugin from \"fastify-lm\";\n\nconst fastify = Fastify({\n  logger: true,\n});\n\n// Register the lm-plugin\nfastify.register(LmPlugin, {\n  models: [\n    {\n      name: \"lm\", // the name of the model instance on your app\n      provider: \"openai\", // openai, google, claude, deepseek or any available provider\n      model: \"gpt-4o-mini\",\n      apiKey: \"your-api-key\",\n    },\n  ],\n});\n\n// Declare a route / that returns the models\nfastify.get(\"/\", async function handler(request, reply) {\n  const models = await fastify.lm.models();\n  return { models };\n});\n\n// Run the server!\ntry {\n  await fastify.listen({ port: 3000 });\n  await fastify.lm.models();\n} catch (err) {\n  fastify.log.error(err);\n  process.exit(1);\n}\n```\n\n\u003e Remember to replace `your-api-key` with your actual API key.\n\nFinally, launch the server with:\n\n```bash\nnode src/server.js\n```\n\nand test it with:\n\n```bash\ncurl http://localhost:3000/\n```\n\n## Usage\n\n### Registering the Plugin\n\nRegister the plugin in your Fastify instance by specifying the models and providers to use.\n\n#### Basic Usage\n\n```typescript\nimport Fastify from \"fastify\";\nimport lmPlugin from \"fastify-lm\";\n\n// Create a Fastify instance and register the plugin\nconst app = Fastify();\napp.register(lmPlugin, {\n  models: [\n    {\n      name: \"lm\",\n      provider: process.env.LM_PROVIDER,\n      model: process.env.LM_MODEL,\n      apiKey: process.env.LM_API_KEY,\n    },\n  ],\n});\n\nconst response = await app.lm.chat({\n  messages: [{ role: \"user\", content: \"How are you?\" }],\n});\n```\n\n💡 _Change the environment variables to switch the provider._\n\n#### Multiple Providers with Query Parameter Selection\n\n```typescript\nimport Fastify, { FastifyRequest, FastifyReply } from \"fastify\";\nimport lmPlugin from \"fastify-lm\";\n\n// Create a Fastify instance and register the plugin\nconst app = Fastify();\napp.register(lmPlugin, {\n  models: [\n    {\n      name: \"openai\",\n      provider: \"openai\",\n      model: \"gpt-3.5-turbo\",\n      apiKey: process.env.OPENAI_API_KEY,\n    },\n    {\n      name: \"google\",\n      provider: \"google\",\n      model: \"gemini-2.0-flash-lite\",\n      apiKey: process.env.GOOGLE_API_KEY,\n    },\n    {\n      name: \"claude\",\n      provider: \"claude\",\n      model: \"claude-3-5-sonnet-20240620\",\n      apiKey: process.env.CLAUDE_API_KEY,\n    },\n    {\n      name: \"deepseek\",\n      provider: \"deepseek\",\n      model: \"deepseek-chat\",\n      apiKey: process.env.DEEPSEEK_API_KEY,\n    },\n    {\n      name: \"mistral\",\n      provider: \"mistral\",\n      model: \"mistral-medium\",\n      apiKey: process.env.MISTRAL_API_KEY,\n    },\n  ],\n});\n\n// Route that receives the query and optional model parameter\napp.get\u003c{ Querystring: QueryParams }\u003e(\n  \"/chat\",\n  {\n    schema: {\n      querystring: {\n        type: 'object',\n        required: ['query'],\n        properties: {\n          query: { type: 'string' },\n          model: { \n            type: 'string', \n            enum: ['openai', 'google', 'claude', 'deepseek', 'mistral'],\n            default: 'openai'\n          }\n        }\n      }\n    }\n  },\n  async (\n    request: FastifyRequest\u003c{ Querystring: QueryParams }\u003e,\n    reply: FastifyReply\n  ) =\u003e {\n    const { query, model = \"openai\" } = request.query;\n\n    try {\n      const response = await app[model].chat({\n        messages: [{ role: \"user\", content: query }],\n      });\n      \n      return { response };\n    } catch (error: any) {\n      reply.status(500).send({ error: error.message });\n    }\n  }\n);\n\n// Start the server\napp.listen({ port: 3000 }, (err, address) =\u003e {\n  if (err) {\n    console.error(err);\n    process.exit(1);\n  }\n  console.log(`Server running at ${address}`);\n});\n\ninterface QueryParams {\n  query: string;\n  model?: \"openai\" | \"google\" | \"claude\" | \"deepseek\" | \"mistral\"; // Optional, defaults to \"openai\"\n}\n```\n\n## Advanced Use Cases\n\nBeyond simple model queries, you can leverage `fastify-lm` for more advanced functionalities:\n\n### 🤖 Automated Customer Support Responses\nUse AI to generate instant answers for common support queries.  \n[📖 Read the full guide →](docs/support-bot.md)\n\n### 🎫 AI-Powered Support Ticket Prioritization\nAutomatically classify and prioritize support tickets based on urgency and sentiment.  \n[📖 Read the full guide →](docs/support-ticket-prioritization.md)\n\n### 📢 AI-Driven Sentiment Analysis\nAnalyze user feedback, reviews, or messages to determine sentiment trends.  \n[📖 Read the full guide →](docs/sentiment-analysis.md)\n\n### 📌 Automatic Content Moderation\nDetect and block inappropriate messages before processing them.  \n[📖 Read the full guide →](docs/content-moderation.md)\n\n### 🔍 Semantic Search \u0026 Query Expansion\nImprove search relevance by understanding intent and expanding queries intelligently.  \n[📖 Read the full guide →](docs/semantic-search.md)\n\n### ✨ Smart Autocomplete for Forms\nEnhance user input by automatically generating text suggestions.  \n[📖 Read the full guide →](docs/autocomplete.md)\n\n### 📄 Automatic Text Summarization\nSummarize long text passages using AI models.  \n[📖 Read the full guide →](docs/summarizer.md)\n\n### 🌍 Real-Time Text Translation\nTranslate user input dynamically with multi-provider support.  \n[📖 Read the full guide →](docs/translator.md)\n\n### 📊 AI-Powered Data Extraction\nExtract structured information from unstructured text, such as invoices, legal documents, or reports.  \n[📖 Read the full guide →](docs/data-extraction.md)\n\n🚀 **Check out more examples in the [`/docs/`](docs/) folder!**\n\n\n\n## Contributing\n\nWe need a lot of hands to implement other providers you can help us by submitting a pull request.\n\n[📖 Adding a New Adapter](docs/adding-new-adapter.md)\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgaliprandi%2Ffastify-lm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgaliprandi%2Ffastify-lm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgaliprandi%2Ffastify-lm/lists"}