{"id":18573917,"url":"https://github.com/basedwon/aiapi","last_synced_at":"2025-08-20T06:33:59.237Z","repository":{"id":208561197,"uuid":"721950419","full_name":"basedwon/aiapi","owner":"basedwon","description":"A versatile library designed to interact with various AI services, including text generation, image processing, and audio conversion.","archived":false,"fork":false,"pushed_at":"2023-11-22T05:49:08.000Z","size":22,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-21T15:09:49.189Z","etag":null,"topics":["ai","huggingface","openai-api","stable-diffusion"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/basedwon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"docs/contributing.md","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-11-22T05:47:07.000Z","updated_at":"2023-11-22T05:48:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"4778037d-0cf0-4c2d-b7ba-3d72fffd168c","html_url":"https://github.com/basedwon/aiapi","commit_stats":null,"previous_names":["basedwon/aiapi"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/basedwon%2Faiapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/basedwon%2Faiapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/basedwon%2Faiapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/basedwon%2Faiapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/basedwon","download_url":"https://codeload.github.com/basedwon/aiapi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254442361,"owners_count":22071863,"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":["ai","huggingface","openai-api","stable-diffusion"],"created_at":"2024-11-06T23:13:22.988Z","updated_at":"2025-05-15T23:34:14.404Z","avatar_url":"https://github.com/basedwon.png","language":"JavaScript","readme":"# aiapi\n\n[![npm](https://img.shields.io/npm/v/aiapi?style=flat\u0026logo=npm)](https://www.npmjs.com/package/aiapi)\n[![pipeline](https://gitlab.com/frenware/ai/aiapi/badges/master/pipeline.svg)](https://gitlab.com/frenware/ai/aiapi/-/pipelines)\n[![license](https://img.shields.io/npm/l/aiapi)](https://gitlab.com/frenware/ai/aiapi/-/blob/master/LICENSE)\n[![downloads](https://img.shields.io/npm/dw/aiapi)](https://www.npmjs.com/package/aiapi) \n\n[![Gitlab](https://img.shields.io/badge/Gitlab%20-%20?logo=gitlab\u0026color=%23383a40)](https://gitlab.com/frenware/ai/aiapi)\n[![Github](https://img.shields.io/badge/Github%20-%20?logo=github\u0026color=%23383a40)](https://github.com/basedwon/aiapi)\n[![Twitter](https://img.shields.io/badge/@basdwon%20-%20?logo=twitter\u0026color=%23383a40)](https://twitter.com/basdwon)\n[![Discord](https://img.shields.io/badge/Basedwon%20-%20?logo=discord\u0026color=%23383a40)](https://discordapp.com/users/basedwon)\n\nA versatile library designed to interact with various AI services, including text generation, image processing, and audio conversion. It offers a flexible architecture that allows users to easily integrate multiple AI providers and switch between them based on their needs.\n\n## Features\n\n- **Multiple AI Providers**: Built-in support for popular AI providers like OpenAI, Hugging Face, and Stable Diffusion.\n- **Dynamic Method Assignment**: Dynamically assign methods like `generateText`, `generateImage` to different providers.\n- **Easy Provider Switching**: Quickly switch AI providers for different methods without altering your main application code.\n- **Extensibility**: Add custom AI providers or override existing ones with ease.\n- **Direct Provider Access**: Directly interact with a specific provider if needed.\n\n## Installation\n\nInstall the package with:\n\n```bash\nnpm install aiapi\n```\n\n## Usage\n\nImport the `aiapi` library.\n\n```js\nimport aiapi from 'aiapi'\n```\nor\n```js\nconst aiapi = require('aiapi')\n```\n\n`aiapi` is designed to be flexible and easy to use, allowing you to interact with multiple AI services seamlessly. Below are some examples of how you can utilize the library in your projects.\n\n### Basic Initialization\n\nFirst, import and initialize the `Api` class with your desired AI providers:\n\n```js\nconst Api = require('aiapi')\n\n// Initialize with your API keys and options\nconst api = new Api({\n  oai: [OpenAIProvider, 'your-openai-api-key', {/* options */}],\n  hf: [HuggingFaceProvider, 'your-huggingface-api-key', {/* options */}],\n  // Add more providers as needed\n})\n```\n\n### Generating Content\n\nUse the API to generate text, images, or audio. By default, the method will use the provider assigned to it:\n\n```js\n// Generate text using the default provider for text generation\napi.generateText(\"Hello, world!\").then(console.log)\n\n// Generate an image\napi.generateImage(\"A sunny beach\").then(console.log)\n```\n\n### Direct Provider Access\n\nYou can also interact directly with a specific provider, bypassing the default method assignments:\n\n```js\n// Directly call the Hugging Face provider\napi.providers.hf.generateText(\"Direct call to Hugging Face\").then(console.log)\n// Or just leverage the Proxy constructor\napi.hf.generateText(\"Direct call to Hugging Face\").then(console.log)\n```\n\n### Assigning Methods to Providers\n\nThe `assignMethod` function allows you to dynamically assign a specific method to a provider. This is useful if you want to change the provider for a particular functionality at runtime:\n\n```js\n// Assign the 'generateText' method to use the 'hf' (Hugging Face) provider\napi.assignMethod('generateText', 'hf')\n\n// Now, calling generateText will use the Hugging Face provider\napi.generateText(\"Switched to Hugging Face\").then(console.log)\n```\n\n### Adding or Overriding Providers\n\nYou can easily add a new provider or override an existing one:\n\n```js\nclass CustomProvider extends AIProvider {\n  // Implement your custom provider\n}\n\n// Register a new provider\napi.registerProvider('custom', new CustomProvider('your-api-key', { /* options */ }))\n\n// Optionally, assign methods to your new provider\napi.assignMethod('generateText', 'custom')\n```\n\n## Documentation\n\n- [API Reference](/docs/api.md)\n\n### Built-in Providers\n\n- **OpenAIProvider**: Interacts with OpenAI's APIs, offering functionalities like GPT-3 text generation.\n- **HuggingFaceProvider**: Utilizes Hugging Face's APIs for text generation and more.\n- **StableDiffusionProvider**: (Work in progress) Aims to offer image generation capabilities.\n\n### Adding Custom Providers\n\nYou can extend the `AIProvider` class to create custom providers. This allows integrating any AI service into the `aiapi` ecosystem.\n\n## Tests\n\nIn order to run the test suite, simply clone the repository and install its dependencies:\n\n```bash\ngit clone https://gitlab.com/frenware/ai/aiapi.git\ncd aiapi\nnpm install\n```\n\nTo run the tests:\n\n```bash\nnpm test\n```\n\n## Contributing\n\nThank you! Please see our [contributing guidelines](/docs/contributing.md) for details.\n\n## Donations\n\nIf you find this project useful and want to help support further development, please send us some coin. We greatly appreciate any and all contributions. Thank you!\n\n**Bitcoin (BTC):**\n```\n1JUb1yNFH6wjGekRUW6Dfgyg4J4h6wKKdF\n```\n\n**Monero (XMR):**\n```\n46uV2fMZT3EWkBrGUgszJCcbqFqEvqrB4bZBJwsbx7yA8e2WBakXzJSUK8aqT4GoqERzbg4oKT2SiPeCgjzVH6VpSQ5y7KQ\n```\n\n## License\n\naiapi is [MIT licensed](https://gitlab.com/frenware/ai/aiapi/-/blob/master/LICENSE).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbasedwon%2Faiapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbasedwon%2Faiapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbasedwon%2Faiapi/lists"}