{"id":32476151,"url":"https://github.com/awalsolution/adonis-ai","last_synced_at":"2025-10-26T21:50:13.636Z","repository":{"id":320208325,"uuid":"1080962361","full_name":"awalsolution/adonis-ai","owner":"awalsolution","description":null,"archived":false,"fork":false,"pushed_at":"2025-10-22T13:53:02.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-22T15:44:17.758Z","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/awalsolution.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-22T05:45:45.000Z","updated_at":"2025-10-22T13:53:06.000Z","dependencies_parsed_at":null,"dependency_job_id":"7fcc68d8-f17e-4f0a-82ee-d26025fd2319","html_url":"https://github.com/awalsolution/adonis-ai","commit_stats":null,"previous_names":["awalsolution/adonis-ai"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/awalsolution/adonis-ai","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awalsolution%2Fadonis-ai","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awalsolution%2Fadonis-ai/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awalsolution%2Fadonis-ai/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awalsolution%2Fadonis-ai/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/awalsolution","download_url":"https://codeload.github.com/awalsolution/adonis-ai/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awalsolution%2Fadonis-ai/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281178936,"owners_count":26456678,"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","status":"online","status_checked_at":"2025-10-26T02:00:06.575Z","response_time":61,"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":"2025-10-26T21:50:11.445Z","updated_at":"2025-10-26T21:50:13.631Z","avatar_url":"https://github.com/awalsolution.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @awalsolution/adonis-ai\n\nAI integration package for AdonisJS v6 with OpenAI and Gemini support.\n\n## Overview\n\nThe `@awalsolution/adonis-ai` package provides a unified interface for integrating AI services into AdonisJS v6 applications. It supports multiple AI providers including OpenAI and Google Gemini, with a consistent API for text generation, chat completion, embeddings, and streaming responses.\n\n## Features\n\n- 🚀 **Multiple AI Providers**: Support for OpenAI and Google Gemini\n- 🔧 **Unified Interface**: Provider-agnostic API through AIManager\n- 💬 **Chat Support**: Conversational AI interactions\n- 📝 **Text Generation**: Generate text from prompts\n- 🔍 **Embeddings**: Generate text embeddings for similarity search\n- 📡 **Streaming**: Real-time streaming responses\n- ⚙️ **Easy Configuration**: Interactive CLI setup\n- 🧪 **Comprehensive Testing**: Full test coverage with Japa\n- 🔌 **Extensible**: Easy to add new AI providers\n- 📦 **Response Classes**: Structured response objects like MailResponse\n\n- 🔄 **Event System**: AI operation events (planned)\n- 🛡️ **Error Handling**: Consistent AdonisJS exception management\n\n## Installation\n\nInstall the package using npm:\n\n```bash\nnpm install @awalsolution/adonis-ai\n```\n\n## Configuration\n\nConfigure the package using the AdonisJS CLI:\n\n```bash\nnode ace configure @awalsolution/adonis-ai\n```\n\nThis will:\n\n- Prompt you to select AI providers (OpenAI, Gemini)\n- Generate `config/ai.ts` with your chosen providers\n- Add required environment variables\n- Register the provider in `adonisrc.ts`\n\nAlternatively, configure with specific services:\n\n```bash\nnode ace configure @awalsolution/adonis-ai --services=openai,gemini --install\n```\n\n## Environment Variables\n\nAdd these environment variables to your `.env` file:\n\n```env\n# Default AI driver\nAI_DRIVER=openai\n\n# Request configuration\nAI_TIMEOUT=30000\nAI_MAX_RETRIES=3\n\n# OpenAI Configuration\nOPENAI_API_KEY=your-openai-api-key\nOPENAI_MODEL=gpt-3.5-turbo\nOPENAI_MAX_TOKENS=1000\nOPENAI_TEMPERATURE=0.7\n\n# Gemini Configuration\nGEMINI_API_KEY=your-gemini-api-key\nGEMINI_MODEL=gemini-pro\nGEMINI_MAX_TOKENS=1000\nGEMINI_TEMPERATURE=0.7\n```\n\n## Usage\n\n### Basic Usage\n\n```typescript\nimport { AIManager } from '@awalsolution/adonis-ai'\n\nexport default class AIController {\n  async generate({ request }) {\n    const ai = await app.container.make('ai.manager')\n\n    // Use OpenAI\n    const response = await ai.use('openai').generate('Write a story about AI')\n    return { text: response.text }\n  }\n\n  async chat({ request }) {\n    const ai = await app.container.make('ai.manager')\n\n    // Chat with Gemini\n    const messages = [{ role: 'user', content: 'Hello, how are you?' }]\n\n    const response = await ai.use('gemini').chat(messages)\n    return { messages: response.messages }\n  }\n\n  async embed({ request }) {\n    const ai = await app.container.make('ai.manager')\n\n    // Generate embeddings\n    const response = await ai.use('openai').embed('Text to embed')\n    return { embeddings: response.embeddings }\n  }\n}\n```\n\n### Using the Default Driver\n\n```typescript\nexport default class AIController {\n  async generate({ request }) {\n    const ai = await app.container.make('ai.manager')\n\n    // Use the default driver (configured in AI_DRIVER)\n    const response = await ai.default.generate('Write a poem')\n    return { text: response.text }\n  }\n}\n```\n\n### Configuration Example\n\n```typescript\n// config/ai.ts\nimport env from '#start/env'\nimport { defineConfig, services } from '@awalsolution/adonis-ai'\n\nexport default defineConfig({\n  default: env.get('AI_DRIVER', 'openai'),\n\n  timeout: env.get('AI_TIMEOUT', 30000),\n  maxRetries: env.get('AI_MAX_RETRIES', 3),\n\n  services: {\n    openai: services.openai({\n      apiKey: env.get('OPENAI_API_KEY'),\n      model: env.get('OPENAI_MODEL', 'gpt-3.5-turbo'),\n      maxTokens: env.get('OPENAI_MAX_TOKENS', 1000),\n      temperature: env.get('OPENAI_TEMPERATURE', 0.7),\n    }),\n\n    gemini: services.gemini({\n      apiKey: env.get('GEMINI_API_KEY'),\n      model: env.get('GEMINI_MODEL', 'gemini-pro'),\n      maxTokens: env.get('GEMINI_MAX_TOKENS', 1000),\n      temperature: env.get('GEMINI_TEMPERATURE', 0.7),\n    }),\n  },\n})\n```\n\n### Template Integration\n\n```typescript\n// In Edge templates\n{\n  {\n    await aiGenerate('Summarize this text', text)\n  }\n}\n{\n  {\n    await aiChat('Explain this concept', concept)\n  }\n}\n```\n\n## Architecture\n\n### Core Components\n\n#### AIManager (Like MailManager)\n\nThe `AIManager` is the central orchestrator that:\n\n- Manages multiple AI drivers\n- Provides a unified interface\n- Handles driver registration and selection\n- Maintains provider-agnostic access\n- Caches driver instances for performance\n\n#### Response Classes (Like MailResponse)\n\nStructured response objects for consistent data handling:\n\n```typescript\nimport { AIResponse, AIChatResponse, AIEmbeddingResponse } from '@awalsolution/adonis-ai'\n\n// All responses have consistent structure\nconst response: AIResponse = {\n  text: 'Generated text',\n  usage: { tokens: 150 },\n  finishReason: 'completed',\n  model: 'gpt-3.5-turbo',\n}\n```\n\n### Drivers\n\nEach AI provider has its own driver that implements the `AIDriver` interface:\n\n- **OpenAI Driver** (`src/drivers/openai/main.ts`) - OpenAI API integration\n- **Gemini Driver** (`src/drivers/gemini/main.ts`) - Google Gemini API integration\n\nThe drivers follow the same folder structure as the Drive package:\n\n```\nsrc/\n├── drivers/\n│   ├── base_driver.ts    # Common functionality\n│   ├── openai/main.ts    # OpenAI implementation\n│   └── gemini/main.ts    # Gemini implementation\n├── ai_manager.ts         # Manager class\n└── ai_response.ts        # Response classes\n```\n\n### Provider Lifecycle\n\nThe AI provider follows AdonisJS provider conventions:\n\n- `register()` - Bind services to container\n- `boot()` - Validate configuration\n- `start()` - Initialize connections\n- `ready()` - Verify service availability\n- `shutdown()` - Cleanup resources\n\n### Error Handling\n\nConsistent AdonisJS exception management:\n\n- `AIApiKeyException` - Missing or invalid API keys\n- `AIServiceException` - API service errors\n- `AIRateLimitException` - Rate limit exceeded\n- `AITimeoutException` - Request timeouts\n- `AIDriverNotFoundException` - Unknown drivers\n\n## Testing\n\nRun tests using:\n\n```bash\nnpm run test\n```\n\nThe package includes comprehensive tests for:\n\n- Configuration validation\n- Driver initialization\n- API key validation\n- Mock response testing\n- Error handling\n\n## Extending the Package\n\n### Adding New Drivers\n\nTo add support for a new AI provider:\n\n1. Create a new driver in `src/drivers/`\n2. Implement the `AIDriver` interface\n3. Register the driver in the provider\n4. Add configuration options\n5. Update the CLI configure command\n\n### Example Driver Implementation\n\n```typescript\nimport type { AIDriver, AIResponse, AIChatMessage } from '@awalsolution/adonis-ai'\n\nexport class CustomDriver implements AIDriver {\n  async generate(prompt: string): Promise\u003cAIResponse\u003e {\n    // Implementation here\n  }\n\n  async chat(messages: AIChatMessage[]): Promise\u003cAIChatResponse\u003e {\n    // Implementation here\n  }\n\n  async embed(text: string | string[]): Promise\u003cAIEmbeddingResponse\u003e {\n    // Implementation here\n  }\n\n  async stream(prompt: string): Promise\u003cAIStreamResponse\u003e {\n    // Implementation here\n  }\n}\n```\n\n## License\n\nMIT License - see [LICENSE.md](LICENSE.md) for details.\n\n## Contributing\n\nContributions are welcome! Please read the contributing guidelines and submit pull requests.\n\n## Support\n\nFor support and questions:\n\n- Create an issue on GitHub\n- Check the documentation\n- Review existing issues\n\n## Changelog\n\nSee [CHANGELOG.md](CHANGELOG.md) for version history.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fawalsolution%2Fadonis-ai","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fawalsolution%2Fadonis-ai","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fawalsolution%2Fadonis-ai/lists"}