{"id":30292649,"url":"https://github.com/spellcraftai/oaib-ts","last_synced_at":"2025-10-18T04:51:31.638Z","repository":{"id":309647844,"uuid":"1036572113","full_name":"SpellcraftAI/oaib-ts","owner":"SpellcraftAI","description":"TS library for making batch requests to LLM providers.","archived":false,"fork":false,"pushed_at":"2025-08-13T02:05:42.000Z","size":209,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-10-04T07:59:10.309Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/SpellcraftAI.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":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-12T09:15:41.000Z","updated_at":"2025-08-13T02:05:45.000Z","dependencies_parsed_at":"2025-08-13T04:07:49.781Z","dependency_job_id":"65eb7327-9dcd-4e63-9e43-1769c116c2ed","html_url":"https://github.com/SpellcraftAI/oaib-ts","commit_stats":null,"previous_names":["spellcraftai/oaib-ts"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/SpellcraftAI/oaib-ts","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpellcraftAI%2Foaib-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpellcraftAI%2Foaib-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpellcraftAI%2Foaib-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpellcraftAI%2Foaib-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SpellcraftAI","download_url":"https://codeload.github.com/SpellcraftAI/oaib-ts/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpellcraftAI%2Foaib-ts/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279001444,"owners_count":26083078,"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-09T02:00:07.460Z","response_time":59,"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-08-17T00:37:36.178Z","updated_at":"2025-10-09T12:32:25.800Z","avatar_url":"https://github.com/SpellcraftAI.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# oaib\n\n**OpenAI batching library** - For batch processing of LLM API requests with\nconcurrency control and progress tracking.\n\n## Installation\n\n```bash\nbun add oaib\n```\n\n*We recommend using [Bun](https://bun.com) for the best performance and compatibility.*\n\n## Usage\n\n```typescript\nimport { batch } from \"oaib\"\nimport { openai } from \"@ai-sdk/openai\"\n\n// Generate random strings of different lengths\nconst randomStrings = [60, 100, 200, 500, 1000]\n  .flatMap(n =\u003e Array.from({ length: 10 }, () =\u003e n))\n  .map(n =\u003e \"x\".repeat(n * (1 + Math.random() * 0.1)))\n\nconst conversations = randomStrings.map((string) =\u003e ({\n  // Add columns to results\n  data: { solution: string.length },\n  messages: [\n    { \n      role: \"user\", \n      content: `Count characters in this string. Answer with \u003ccount\u003e{number}\u003c/count\u003e.\\n${string}` \n    }\n  ]\n}))\n\nconst results = await batch(conversations, {\n  model: openai(\"gpt-4\"),\n  concurrency: 8,\n  process: ({ text }) =\u003e {\n    // Maps model response to { result }\n    const match = text.match(/\u003ccount\u003e(.*?)\u003c\\/count\u003e/)\n    if (!match?.[1]) throw new Error(\"No \u003ccount\u003e tags found\")\n    return parseInt(match[1], 10)\n  },\n})\n\n// results.results contains { input, response, result, ...data }\nawait Bun.write(\"results.json\", JSON.stringify(results, null, 2))\n```\n\nSee the full example in `src/letter-count.ts`.\n\n## Requirements\n\n- **TypeScript 5+** required  \n- **Bun recommended** for optimal performance\n- For Node.js users: Handle TypeScript transpilation on your end*\n\n---\n\n*This is a pure TypeScript repository optimized for Bun. Node.js users will need to set up their own transpilation pipeline (e.g., ts-node, tsx, or build step).\n\n## Quick Start\n\n```typescript\nimport { batch } from 'oaib'\nimport { openai } from '@ai-sdk/openai'\n\nconst conversations = [\n  {\n    messages: [{ role: 'user', content: 'What is 2+2?' }],\n    data: { id: 1 }\n  },\n  {\n    messages: [{ role: 'user', content: 'What is 3+3?' }],\n    data: { id: 2 }\n  }\n]\n\nconst results = await batch(conversations, {\n  model: openai('gpt-4'),\n  process: ({ text }) =\u003e {\n    // Process the AI response\n    return text.trim()\n  },\n  concurrency: 5\n})\n\nconsole.log(results)\n```\n\n## API Reference\n\n### `batch\u003cTOOLS, PROCESSED\u003e(items, options)`\n\nProcess multiple AI conversations concurrently with built-in progress tracking.\n\n#### Parameters\n\n- **`items`** (`BatchItem[]`) - Array of conversation items to process\n- **`options`** (`BatchOptions\u003cTOOLS, PROCESSED\u003e`) - Configuration options\n\n#### `BatchItem`\n\n```typescript\ntype BatchItem = {\n  messages: ModelMessage[]     // Conversation messages\n  data?: Record\u003cstring, unknown\u003e  // Optional metadata\n}\n```\n\n#### `BatchOptions\u003cTOOLS, PROCESSED\u003e`\n\n```typescript\ninterface BatchOptions\u003cTOOLS, PROCESSED\u003e {\n  model: LanguageModel              // AI model to use\n  tools?: TOOLS                     // Available tools for the model\n  process: (response) =\u003e PROCESSED  // Function to process AI responses\n  concurrency?: number              // Max concurrent requests (default: 8)\n  timeout?: number                  // Timeout per request in ms\n  spinner?: boolean                 // Show progress spinner (default: true)\n}\n```\n\n## Features\n\n- **Concurrent Processing**: Control the number of simultaneous AI requests\n- **Progress Tracking**: Built-in spinner showing real-time progress\n- **Error Handling**: Graceful handling of failed requests with error reporting\n- **Flexible Processing**: Custom processing functions for AI responses\n- **Type Safety**: Full TypeScript support with generic types\n- **AI SDK Integration**: Works with any AI SDK provider (OpenAI, Anthropic, etc.)\n\n## Examples\n\n### Basic Usage\n\n```typescript\nimport { batch } from 'oaib'\nimport { openai } from '@ai-sdk/openai'\n\nconst conversations = [\n  { messages: [{ role: 'user', content: 'Translate \"hello\" to Spanish' }] },\n  { messages: [{ role: 'user', content: 'Translate \"goodbye\" to French' }] }\n]\n\nconst results = await batch(conversations, {\n  model: openai('gpt-4'),\n  process: ({ text }) =\u003e text\n})\n```\n\n### With Custom Processing\n\n```typescript\nconst results = await batch(conversations, {\n  model: openai('gpt-4'),\n  process: ({ text }) =\u003e {\n    // Extract structured data from AI response\n    const match = text.match(/\u003canswer\u003e(.*?)\u003c\\/answer\u003e/)\n    return match?.[1] || text\n  },\n  concurrency: 3,\n  timeout: 30000\n})\n```\n\n### With Metadata\n\n```typescript\nconst conversations = [\n  {\n    messages: [{ role: 'user', content: 'Count characters: \"hello\"' }],\n    data: { expectedLength: 5, id: 'test1' }\n  }\n]\n\nconst results = await batch(conversations, {\n  model: openai('gpt-4'),\n  process: ({ text }) =\u003e parseInt(text.match(/\\d+/)?.[0] || '0')\n})\n\n// Access metadata in results\nresults.results.forEach(result =\u003e {\n  console.log(result.id, result.expectedLength, result.result)\n})\n```\n\n### Disable Progress Spinner\n\n```typescript\nconst results = await batch(conversations, {\n  model: openai('gpt-4'),\n  process: ({ text }) =\u003e text,\n  spinner: false  // No progress indicator\n})\n```\n\n## Development\n\nThis project uses Bun for development:\n\n```bash\n# Install dependencies\nbun install\n\n# Run tests\nbun test\n\n# Run the example\nbun src/letter-count.ts\n```\n\n## Requirements\n\n- **TypeScript 5+** required\n- **Bun recommended** for optimal performance\n- For Node.js users: Handle TypeScript transpilation on your end*\n\n---\n\n*This is a pure TypeScript repository optimized for Bun. Node.js users will need to set up their own transpilation pipeline (e.g., ts-node, tsx, or build step).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspellcraftai%2Foaib-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspellcraftai%2Foaib-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspellcraftai%2Foaib-ts/lists"}