feat(providers): Add Anthropic extended thinking and adapt providers to new streaming/file APIs; bump dependencies and update docs, tests and configuration
This commit is contained in:
7
.gitignore
vendored
7
.gitignore
vendored
@@ -3,7 +3,6 @@
|
||||
# artifacts
|
||||
coverage/
|
||||
public/
|
||||
pages/
|
||||
|
||||
# installs
|
||||
node_modules/
|
||||
@@ -17,4 +16,8 @@ node_modules/
|
||||
dist/
|
||||
dist_*/
|
||||
|
||||
# custom
|
||||
# AI
|
||||
.claude/
|
||||
.serena/
|
||||
|
||||
#------# custom
|
||||
|
||||
58
changelog.md
58
changelog.md
@@ -1,6 +1,19 @@
|
||||
# Changelog
|
||||
|
||||
## 2026-01-18 - 0.9.0 - feat(providers)
|
||||
Add Anthropic extended thinking and adapt providers to new streaming/file APIs; bump dependencies and update docs, tests and configuration
|
||||
|
||||
- Add IAnthropicProviderOptions.extendedThinking with thinking modes (quick/normal/deep/off) and getThinkingConfig mapping budgets; apply thinking to Anthropic requests and omit temperature when thinking is enabled.
|
||||
- Update Anthropic research flow to include thinking configuration and conditionally set temperature.
|
||||
- OpenAI image editing: use openai.toFile to convert image/mask Buffers to uploadable files (image/png) before sending.
|
||||
- ElevenLabs streaming: switch from response.streamNode() to response.stream() and convert web stream to Node stream using Readable.fromWeb().
|
||||
- Upgrade dependencies and dev tools: @anthropic-ai/sdk ^0.71.2, @push.rocks/smartrequest ^5.0.1, @git.zone/tsbuild and related @git.zone packages, and other bumps in package.json.
|
||||
- Tests and test imports updated to use @git.zone/tstest/tapbundle; many test files adjusted accordingly.
|
||||
- Docs and hints updated: README and readme.hints.md include extended thinking docs, examples, formatting fixes, security/issue reporting guidance, and trademark/license clarifications.
|
||||
- Project config tweaks: package build script changed, tsconfig baseUrl/paths added, npmextra.json reorganized (release registries added), .gitignore updated to ignore .claude/.serena local tooling files.
|
||||
|
||||
## 2025-10-30 - 0.8.0 - feat(provider.anthropic)
|
||||
|
||||
Add extended thinking modes to AnthropicProvider and apply thinking budgets to API calls
|
||||
|
||||
- Introduce IAnthropicProviderOptions.extendedThinking to configure thinking modes: 'quick' | 'normal' | 'deep' | 'off'.
|
||||
@@ -10,6 +23,7 @@ Add extended thinking modes to AnthropicProvider and apply thinking budgets to A
|
||||
- Add .claude/settings.local.json for local assistant permissions used in development/testing.
|
||||
|
||||
## 2025-10-10 - 0.7.7 - fix(MultiModalModel)
|
||||
|
||||
Lazy-load SmartPdf and guard document processing across providers; ensure SmartPdf is initialized only when needed
|
||||
|
||||
- Make SmartPdf lazy-loaded: smartpdfInstance is now nullable and no longer started automatically in start()
|
||||
@@ -20,6 +34,7 @@ Lazy-load SmartPdf and guard document processing across providers; ensure SmartP
|
||||
- Add local Claude permissions file (.claude/settings.local.json) for tooling/configuration
|
||||
|
||||
## 2025-10-09 - 0.7.6 - fix(provider.elevenlabs)
|
||||
|
||||
Provide default ElevenLabs TTS voice fallback and add local tool/project configs
|
||||
|
||||
- ElevenLabsProvider: fallback to Samara voice id ('19STyYD15bswVz51nqLf') when no voiceId or defaultVoiceId is provided — avoids throwing an error on TTS calls.
|
||||
@@ -28,18 +43,21 @@ Provide default ElevenLabs TTS voice fallback and add local tool/project configs
|
||||
- Add .serena/project.yml and .serena/.gitignore to include Serena project configuration and ignore cache.
|
||||
|
||||
## 2025-10-08 - 0.7.5 - fix(provider.elevenlabs)
|
||||
|
||||
Update ElevenLabs default TTS model to eleven_v3 and add local Claude permissions file
|
||||
|
||||
- Changed default ElevenLabs modelId from 'eleven_multilingual_v2' to 'eleven_v3' in ts/provider.elevenlabs.ts to use the newer/default TTS model.
|
||||
- Added .claude/settings.local.json with a permissions allow-list for local Claude tooling and CI tasks.
|
||||
|
||||
## 2025-10-03 - 0.7.4 - fix(provider.anthropic)
|
||||
|
||||
Use image/png for embedded PDF images in Anthropic provider and add local Claude settings for development permissions
|
||||
|
||||
- AnthropicProvider: change media_type from 'image/jpeg' to 'image/png' when embedding images extracted from PDFs to ensure correct format in Anthropic requests.
|
||||
- Add .claude/settings.local.json with development/testing permissions for local Claude usage (shell commands, webfetch, websearch, test/run tasks).
|
||||
|
||||
## 2025-10-03 - 0.7.3 - fix(tests)
|
||||
|
||||
Add extensive provider/feature tests and local Claude CI permissions
|
||||
|
||||
- Add many focused test files covering providers and features: OpenAI, Anthropic, Perplexity, Groq, Ollama, Exo, XAI (chat, audio, vision, document, research, image generation, stubs, interfaces, basic)
|
||||
@@ -48,12 +66,14 @@ Add extensive provider/feature tests and local Claude CI permissions
|
||||
- No changes to library runtime code — this change adds tests and CI/local agent configuration only
|
||||
|
||||
## 2025-10-03 - 0.7.2 - fix(anthropic)
|
||||
|
||||
Update Anthropic provider branding to Claude Sonnet 4.5 and add local Claude permissions
|
||||
|
||||
- Docs: Replace 'Claude 3 Opus' with 'Claude Sonnet 4.5' in README provider capabilities matrix.
|
||||
- Config: Add .claude/settings.local.json to define local Claude permissions for tests and development commands.
|
||||
|
||||
## 2025-10-03 - 0.7.1 - fix(docs)
|
||||
|
||||
Add README image generation docs and .claude local settings
|
||||
|
||||
- Add .claude/settings.local.json with permission allow-list for local assistant tooling and web search
|
||||
@@ -62,6 +82,7 @@ Add README image generation docs and .claude local settings
|
||||
- Mark image generation support as implemented in the roadmap and remove duplicate entry
|
||||
|
||||
## 2025-10-03 - 0.7.0 - feat(providers)
|
||||
|
||||
Add research API and image generation/editing support; extend providers and tests
|
||||
|
||||
- Introduce ResearchOptions and ResearchResponse to the MultiModalModel interface and implement research() where supported
|
||||
@@ -75,14 +96,16 @@ Add research API and image generation/editing support; extend providers and test
|
||||
- Add local Claude agent permissions file (.claude/settings.local.json) and various provider type/import updates
|
||||
|
||||
## 2025-09-28 - 0.6.1 - fix(provider.anthropic)
|
||||
|
||||
Fix Anthropic research tool identifier and add tests + local Claude permissions
|
||||
|
||||
- Replace Anthropic research tool type from 'computer_20241022' to 'web_search_20250305' to match the expected web-search tool schema.
|
||||
- Add comprehensive test suites and fixtures for providers and research features (new/updated tests under test/ including anthropic, openai, research.* and stubs).
|
||||
- Add comprehensive test suites and fixtures for providers and research features (new/updated tests under test/ including anthropic, openai, research.\* and stubs).
|
||||
- Fix test usage of XAI provider class name (use XAIProvider) and adjust basic provider test expectations (provider instantiation moved to start()).
|
||||
- Add .claude/settings.local.json with local Claude permissions to allow common CI/dev commands and web search during testing.
|
||||
|
||||
## 2025-09-28 - 0.6.0 - feat(research)
|
||||
|
||||
Introduce research API with provider implementations, docs and tests
|
||||
|
||||
- Add ResearchOptions and ResearchResponse interfaces and a new abstract research() method to MultiModalModel
|
||||
@@ -97,6 +120,7 @@ Introduce research API with provider implementations, docs and tests
|
||||
- Add .claude/settings.local.json (local agent permissions for CI/dev tasks)
|
||||
|
||||
## 2025-08-12 - 0.5.11 - fix(openaiProvider)
|
||||
|
||||
Update default chat model to gpt-5-mini and bump dependency versions
|
||||
|
||||
- Changed default chat model in OpenAiProvider from 'o3-mini' and 'o4-mini' to 'gpt-5-mini'
|
||||
@@ -105,6 +129,7 @@ Update default chat model to gpt-5-mini and bump dependency versions
|
||||
- Added new local Claude settings configuration (.claude/settings.local.json)
|
||||
|
||||
## 2025-08-03 - 0.5.10 - fix(dependencies)
|
||||
|
||||
Update SmartPdf to v4.1.1 for enhanced PDF processing capabilities
|
||||
|
||||
- Updated @push.rocks/smartpdf from ^3.3.0 to ^4.1.1
|
||||
@@ -112,12 +137,14 @@ Update SmartPdf to v4.1.1 for enhanced PDF processing capabilities
|
||||
- Dependency updates for better performance and compatibility
|
||||
|
||||
## 2025-08-01 - 0.5.9 - fix(documentation)
|
||||
|
||||
Remove contribution section from readme
|
||||
|
||||
- Removed the contribution section from readme.md as requested
|
||||
- Kept the roadmap section for future development plans
|
||||
|
||||
## 2025-08-01 - 0.5.8 - fix(core)
|
||||
|
||||
Fix SmartPdf lifecycle management and update dependencies
|
||||
|
||||
- Moved SmartPdf instance management to the MultiModalModel base class for better resource sharing
|
||||
@@ -127,12 +154,14 @@ Fix SmartPdf lifecycle management and update dependencies
|
||||
- Enhanced readme with professional documentation and feature matrix
|
||||
|
||||
## 2025-07-26 - 0.5.7 - fix(provider.openai)
|
||||
|
||||
Fix stream type mismatch in audio method
|
||||
|
||||
- Fixed type error where OpenAI SDK returns a web ReadableStream but the audio method needs to return a Node.js ReadableStream
|
||||
- Added conversion using Node.js's built-in Readable.fromWeb() method
|
||||
|
||||
## 2025-07-25 - 0.5.5 - feat(documentation)
|
||||
|
||||
Comprehensive documentation enhancement and test improvements
|
||||
|
||||
- Completely rewrote readme.md with detailed provider comparisons, advanced usage examples, and performance tips
|
||||
@@ -141,6 +170,7 @@ Comprehensive documentation enhancement and test improvements
|
||||
- Added verbose flag to test script for better debugging
|
||||
|
||||
## 2025-05-13 - 0.5.4 - fix(provider.openai)
|
||||
|
||||
Update dependency versions, clean test imports, and adjust default OpenAI model configurations
|
||||
|
||||
- Bump dependency versions in package.json (@git.zone/tsbuild, @push.rocks/tapbundle, openai, etc.)
|
||||
@@ -148,17 +178,20 @@ Update dependency versions, clean test imports, and adjust default OpenAI model
|
||||
- Remove unused 'expectAsync' import from test file
|
||||
|
||||
## 2025-04-03 - 0.5.3 - fix(package.json)
|
||||
|
||||
Add explicit packageManager field to package.json
|
||||
|
||||
- Include the packageManager property to specify the pnpm version and checksum.
|
||||
- Align package metadata with current standards.
|
||||
|
||||
## 2025-04-03 - 0.5.2 - fix(readme)
|
||||
|
||||
Remove redundant conclusion section from README to streamline documentation.
|
||||
|
||||
- Eliminated the conclusion block describing SmartAi's capabilities and documentation pointers.
|
||||
|
||||
## 2025-02-25 - 0.5.1 - fix(OpenAiProvider)
|
||||
|
||||
Corrected audio model ID in OpenAiProvider
|
||||
|
||||
- Fixed audio model identifier from 'o3-mini' to 'tts-1-hd' in the OpenAiProvider's audio method.
|
||||
@@ -166,6 +199,7 @@ Corrected audio model ID in OpenAiProvider
|
||||
- Corrected spelling errors in test documentation and comments.
|
||||
|
||||
## 2025-02-25 - 0.5.0 - feat(documentation and configuration)
|
||||
|
||||
Enhanced package and README documentation
|
||||
|
||||
- Expanded the package description to better reflect the library's capabilities.
|
||||
@@ -173,6 +207,7 @@ Enhanced package and README documentation
|
||||
- Provided error handling strategies and advanced streaming customization examples.
|
||||
|
||||
## 2025-02-25 - 0.4.2 - fix(core)
|
||||
|
||||
Fix OpenAI chat streaming and PDF document processing logic.
|
||||
|
||||
- Updated OpenAI chat streaming to handle new async iterable format.
|
||||
@@ -180,6 +215,7 @@ Fix OpenAI chat streaming and PDF document processing logic.
|
||||
- Removed unsupported temperature options from OpenAI requests.
|
||||
|
||||
## 2025-02-25 - 0.4.1 - fix(provider)
|
||||
|
||||
Fix provider modules for consistency
|
||||
|
||||
- Updated TypeScript interfaces and options in provider modules for better type safety.
|
||||
@@ -187,6 +223,7 @@ Fix provider modules for consistency
|
||||
- Added optional model options to OpenAI provider for custom model usage.
|
||||
|
||||
## 2025-02-08 - 0.4.0 - feat(core)
|
||||
|
||||
Added support for Exo AI provider
|
||||
|
||||
- Introduced ExoProvider with chat functionalities.
|
||||
@@ -194,18 +231,21 @@ Added support for Exo AI provider
|
||||
- Extended Conversation class to support ExoProvider.
|
||||
|
||||
## 2025-02-05 - 0.3.3 - fix(documentation)
|
||||
|
||||
Update readme with detailed license and legal information.
|
||||
|
||||
- Added explicit section on License and Legal Information in the README.
|
||||
- Clarified the use of trademarks and company information.
|
||||
|
||||
## 2025-02-05 - 0.3.2 - fix(documentation)
|
||||
|
||||
Remove redundant badges from readme
|
||||
|
||||
- Removed Build Status badge from the readme file.
|
||||
- Removed License badge from the readme file.
|
||||
|
||||
## 2025-02-05 - 0.3.1 - fix(documentation)
|
||||
|
||||
Updated README structure and added detailed usage examples
|
||||
|
||||
- Introduced a Table of Contents
|
||||
@@ -214,6 +254,7 @@ Updated README structure and added detailed usage examples
|
||||
- Clarified the development setup with instructions for running tests and building the project
|
||||
|
||||
## 2025-02-05 - 0.3.0 - feat(integration-xai)
|
||||
|
||||
Add support for X.AI provider with chat and document processing capabilities.
|
||||
|
||||
- Introduced XAIProvider class for integrating X.AI features.
|
||||
@@ -221,6 +262,7 @@ Add support for X.AI provider with chat and document processing capabilities.
|
||||
- Enabled document processing capabilities with PDF conversion in X.AI.
|
||||
|
||||
## 2025-02-03 - 0.2.0 - feat(provider.anthropic)
|
||||
|
||||
Add support for vision and document processing in Anthropic provider
|
||||
|
||||
- Implemented vision tasks for Anthropic provider using Claude-3-opus-20240229 model.
|
||||
@@ -228,6 +270,7 @@ Add support for vision and document processing in Anthropic provider
|
||||
- Updated documentation to reflect the new capabilities of the Anthropic provider.
|
||||
|
||||
## 2025-02-03 - 0.1.0 - feat(providers)
|
||||
|
||||
Add vision and document processing capabilities to providers
|
||||
|
||||
- OpenAI and Ollama providers now support vision tasks using GPT-4 Vision and Llava models respectively.
|
||||
@@ -236,6 +279,7 @@ Add vision and document processing capabilities to providers
|
||||
- Updated the readme file with examples for vision and document processing.
|
||||
|
||||
## 2025-02-03 - 0.0.19 - fix(core)
|
||||
|
||||
Enhanced chat streaming and error handling across providers
|
||||
|
||||
- Refactored chatStream method to properly handle input streams and processes in Perplexity, OpenAI, Ollama, and Anthropic providers.
|
||||
@@ -244,6 +288,7 @@ Enhanced chat streaming and error handling across providers
|
||||
- Adjusted the test logic in test/test.ts for the new classification response requirement.
|
||||
|
||||
## 2024-09-19 - 0.0.18 - fix(dependencies)
|
||||
|
||||
Update dependencies to the latest versions.
|
||||
|
||||
- Updated @git.zone/tsbuild from ^2.1.76 to ^2.1.84
|
||||
@@ -257,46 +302,53 @@ Update dependencies to the latest versions.
|
||||
- Updated openai from ^4.47.1 to ^4.62.1
|
||||
|
||||
## 2024-05-29 - 0.0.17 - Documentation
|
||||
|
||||
Updated project description.
|
||||
|
||||
- Improved project description for clarity and details.
|
||||
|
||||
## 2024-05-17 - 0.0.16 to 0.0.15 - Core
|
||||
|
||||
Fixes and updates.
|
||||
|
||||
- Various core updates and fixes for stability improvements.
|
||||
|
||||
## 2024-04-29 - 0.0.14 to 0.0.13 - Core
|
||||
|
||||
Fixes and updates.
|
||||
|
||||
- Multiple core updates and fixes for enhanced functionality.
|
||||
|
||||
## 2024-04-29 - 0.0.12 - Core
|
||||
|
||||
Fixes and updates.
|
||||
|
||||
- Core update and bug fixes.
|
||||
|
||||
## 2024-04-29 - 0.0.11 - Provider
|
||||
|
||||
Fix integration for anthropic provider.
|
||||
|
||||
- Correction in the integration process with anthropic provider for better compatibility.
|
||||
|
||||
## 2024-04-27 - 0.0.10 to 0.0.9 - Core
|
||||
|
||||
Fixes and updates.
|
||||
|
||||
- Updates and fixes to core components.
|
||||
- Updated tsconfig for improved TypeScript configuration.
|
||||
|
||||
## 2024-04-01 - 0.0.8 to 0.0.7 - Core and npmextra
|
||||
|
||||
Core updates and npmextra configuration.
|
||||
|
||||
- Core fixes and updates.
|
||||
- Updates to npmextra.json for githost configuration.
|
||||
|
||||
## 2024-03-31 - 0.0.6 to 0.0.2 - Core
|
||||
|
||||
Initial core updates and fixes.
|
||||
|
||||
- Multiple updates and fixes to core following initial versions.
|
||||
|
||||
|
||||
This summarizes the relevant updates and changes based on the provided commit messages. The changelog excludes commits that are version tags without meaningful content or repeated entries.
|
||||
This summarizes the relevant updates and changes based on the provided commit messages. The changelog excludes commits that are version tags without meaningful content or repeated entries.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"gitzone": {
|
||||
"@git.zone/cli": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "code.foss.global",
|
||||
@@ -33,13 +33,19 @@
|
||||
"AI toolkit",
|
||||
"provider switching"
|
||||
]
|
||||
},
|
||||
"release": {
|
||||
"accessLevel": "public",
|
||||
"registries": [
|
||||
"https://verdaccio.lossless.digital",
|
||||
"https://registry.npmjs.org"
|
||||
]
|
||||
}
|
||||
},
|
||||
"npmci": {
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"tsdoc": {
|
||||
"@git.zone/tsdoc": {
|
||||
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
||||
},
|
||||
"@ship.zone/szci": {
|
||||
"npmGlobalTools": []
|
||||
}
|
||||
}
|
||||
18
package.json
18
package.json
@@ -11,27 +11,26 @@
|
||||
"scripts": {
|
||||
"test": "(tstest test/ --web --verbose)",
|
||||
"typecheck": "tsbuild check",
|
||||
"build": "(tsbuild --web --allowimplicitany)",
|
||||
"build": "(tsbuild tsfolders --allowimplicitany)",
|
||||
"buildDocs": "(tsdoc)"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@git.zone/tsbuild": "^2.6.8",
|
||||
"@git.zone/tsbundle": "^2.5.1",
|
||||
"@git.zone/tsrun": "^1.3.3",
|
||||
"@git.zone/tstest": "^2.3.8",
|
||||
"@git.zone/tsbuild": "^4.1.2",
|
||||
"@git.zone/tsbundle": "^2.8.1",
|
||||
"@git.zone/tsrun": "^2.0.1",
|
||||
"@git.zone/tstest": "^3.1.4",
|
||||
"@push.rocks/qenv": "^6.1.3",
|
||||
"@push.rocks/tapbundle": "^6.0.3",
|
||||
"@types/node": "^22.15.17",
|
||||
"typescript": "^5.9.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@anthropic-ai/sdk": "^0.65.0",
|
||||
"@anthropic-ai/sdk": "^0.71.2",
|
||||
"@push.rocks/smartarray": "^1.1.0",
|
||||
"@push.rocks/smartfile": "^11.2.7",
|
||||
"@push.rocks/smartpath": "^6.0.0",
|
||||
"@push.rocks/smartpdf": "^4.1.1",
|
||||
"@push.rocks/smartpromise": "^4.2.3",
|
||||
"@push.rocks/smartrequest": "^4.3.1",
|
||||
"@push.rocks/smartrequest": "^5.0.1",
|
||||
"@push.rocks/webstream": "^1.0.10",
|
||||
"openai": "^5.12.2"
|
||||
},
|
||||
@@ -86,7 +85,8 @@
|
||||
"onlyBuiltDependencies": [
|
||||
"esbuild",
|
||||
"puppeteer"
|
||||
]
|
||||
],
|
||||
"overrides": {}
|
||||
},
|
||||
"packageManager": "pnpm@10.7.0+sha512.6b865ad4b62a1d9842b61d674a393903b871d9244954f652b8842c2b553c72176b278f64c463e52d40fff8aba385c235c8c9ecf5cc7de4fd78b8bb6d49633ab6"
|
||||
}
|
||||
|
||||
5182
pnpm-lock.yaml
generated
5182
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -1,8 +1,21 @@
|
||||
# SmartAI Project Hints
|
||||
|
||||
## Dependencies
|
||||
|
||||
- Uses `@git.zone/tstest` v3.x for testing (import from `@git.zone/tstest/tapbundle`)
|
||||
- `@push.rocks/smartfile` is kept at v11 to avoid migration to factory pattern
|
||||
- `@anthropic-ai/sdk` v0.71.x with extended thinking support
|
||||
- `@push.rocks/smartrequest` v5.x - uses `response.stream()` + `Readable.fromWeb()` for streaming
|
||||
|
||||
## Important Notes
|
||||
|
||||
- When extended thinking is enabled, temperature parameter must NOT be set (or set to 1)
|
||||
- The `streamNode()` method was removed in smartrequest v5, use `response.stream()` with `Readable.fromWeb()` instead
|
||||
|
||||
## Anthropic Extended Thinking Feature
|
||||
|
||||
### Overview
|
||||
|
||||
The Anthropic provider now supports extended thinking by default across all methods. Extended thinking enables Claude to spend more time reasoning about complex problems before generating responses, leading to higher quality answers for difficult questions.
|
||||
|
||||
### Configuration
|
||||
@@ -22,18 +35,19 @@ const provider = new smartai.AnthropicProvider({
|
||||
|
||||
The `extendedThinking` parameter accepts four modes:
|
||||
|
||||
| Mode | Budget Tokens | Use Case |
|
||||
|------|---------------|----------|
|
||||
| `'quick'` | 2,048 | Lightweight reasoning for simple queries |
|
||||
| `'normal'` | 8,000 | **Default** - Balanced reasoning for most tasks |
|
||||
| `'deep'` | 16,000 | Complex reasoning for difficult problems |
|
||||
| `'off'` | 0 | Disable extended thinking |
|
||||
| Mode | Budget Tokens | Use Case |
|
||||
| ---------- | ------------- | ----------------------------------------------- |
|
||||
| `'quick'` | 2,048 | Lightweight reasoning for simple queries |
|
||||
| `'normal'` | 8,000 | **Default** - Balanced reasoning for most tasks |
|
||||
| `'deep'` | 16,000 | Complex reasoning for difficult problems |
|
||||
| `'off'` | 0 | Disable extended thinking |
|
||||
|
||||
**Default Behavior**: If `extendedThinking` is not specified, it defaults to `'normal'` mode (8,000 tokens).
|
||||
|
||||
### Supported Methods
|
||||
|
||||
Extended thinking is automatically applied to all Anthropic provider methods:
|
||||
|
||||
- `chat()` - Synchronous chat
|
||||
- `chatStream()` - Streaming chat
|
||||
- `vision()` - Image analysis
|
||||
@@ -53,16 +67,19 @@ Extended thinking is automatically applied to all Anthropic provider methods:
|
||||
### Performance and Cost Implications
|
||||
|
||||
**Token Usage**:
|
||||
|
||||
- You are charged for the **full thinking tokens** generated, not just the summary
|
||||
- Higher thinking budgets may result in more thorough reasoning but increased costs
|
||||
- The budget is a **target**, not a strict limit - actual usage may vary
|
||||
|
||||
**Response Quality**:
|
||||
|
||||
- `'quick'`: Fast responses, basic reasoning
|
||||
- `'normal'`: Good balance between quality and speed (recommended for most use cases)
|
||||
- `'deep'`: Highest quality reasoning for complex problems, slower responses
|
||||
|
||||
**Recommendations**:
|
||||
|
||||
- Start with `'normal'` (default) for general usage
|
||||
- Use `'deep'` for complex analytical tasks, philosophy, mathematics, or research
|
||||
- Use `'quick'` for simple factual queries where deep reasoning isn't needed
|
||||
@@ -71,6 +88,7 @@ Extended thinking is automatically applied to all Anthropic provider methods:
|
||||
### Usage Examples
|
||||
|
||||
#### Example 1: Default (Normal Mode)
|
||||
|
||||
```typescript
|
||||
const provider = new smartai.AnthropicProvider({
|
||||
anthropicToken: process.env.ANTHROPIC_TOKEN,
|
||||
@@ -87,6 +105,7 @@ const response = await provider.chat({
|
||||
```
|
||||
|
||||
#### Example 2: Deep Thinking for Complex Analysis
|
||||
|
||||
```typescript
|
||||
const provider = new smartai.AnthropicProvider({
|
||||
anthropicToken: process.env.ANTHROPIC_TOKEN,
|
||||
@@ -103,6 +122,7 @@ const response = await provider.chat({
|
||||
```
|
||||
|
||||
#### Example 3: Quick Mode for Simple Queries
|
||||
|
||||
```typescript
|
||||
const provider = new smartai.AnthropicProvider({
|
||||
anthropicToken: process.env.ANTHROPIC_TOKEN,
|
||||
@@ -119,6 +139,7 @@ const response = await provider.chat({
|
||||
```
|
||||
|
||||
#### Example 4: Disable Thinking
|
||||
|
||||
```typescript
|
||||
const provider = new smartai.AnthropicProvider({
|
||||
anthropicToken: process.env.ANTHROPIC_TOKEN,
|
||||
@@ -135,6 +156,7 @@ const response = await provider.chat({
|
||||
```
|
||||
|
||||
#### Example 5: Extended Thinking with Vision
|
||||
|
||||
```typescript
|
||||
const provider = new smartai.AnthropicProvider({
|
||||
anthropicToken: process.env.ANTHROPIC_TOKEN,
|
||||
@@ -153,14 +175,17 @@ const analysis = await provider.vision({
|
||||
### Testing
|
||||
|
||||
Comprehensive tests for extended thinking are available in:
|
||||
|
||||
- `test/test.thinking.anthropic.ts` - Tests all thinking modes
|
||||
|
||||
Run tests with:
|
||||
|
||||
```bash
|
||||
pnpm test
|
||||
```
|
||||
|
||||
Run specific thinking tests:
|
||||
|
||||
```bash
|
||||
npx tstest test/test.thinking.anthropic.ts --verbose
|
||||
```
|
||||
@@ -168,6 +193,7 @@ npx tstest test/test.thinking.anthropic.ts --verbose
|
||||
### API Reference
|
||||
|
||||
According to Anthropic's documentation:
|
||||
|
||||
- Extended thinking is supported on Claude Sonnet 4.5, 4, 3.7, Haiku 4.5, and Opus 4.1, 4
|
||||
- The current model used is `claude-sonnet-4-5-20250929`
|
||||
- Minimum thinking budget is 1,024 tokens
|
||||
@@ -176,6 +202,7 @@ According to Anthropic's documentation:
|
||||
### Implementation Details
|
||||
|
||||
The extended thinking feature is implemented via:
|
||||
|
||||
1. **Interface**: `IAnthropicProviderOptions.extendedThinking` property
|
||||
2. **Helper Method**: `getThinkingConfig()` private method that maps modes to token budgets
|
||||
3. **API Parameter**: Adds `thinking: { type: 'enabled', budget_tokens: number }` to all API calls
|
||||
|
||||
217
readme.md
217
readme.md
@@ -1,11 +1,16 @@
|
||||
# @push.rocks/smartai
|
||||
|
||||
**One API to rule them all** 🚀
|
||||
|
||||
[](https://www.npmjs.com/package/@push.rocks/smartai)
|
||||
[](https://www.typescriptlang.org/)
|
||||
[](https://opensource.org/licenses/MIT)
|
||||
|
||||
SmartAI unifies the world's leading AI providers - OpenAI, Anthropic, Perplexity, Ollama, Groq, XAI, Exo, and ElevenLabs - under a single, elegant TypeScript interface. Build AI applications at lightning speed without vendor lock-in.
|
||||
SmartAI unifies the world's leading AI providers - OpenAI, Anthropic, Perplexity, Ollama, Groq, XAI, Exo, and ElevenLabs - under a single, elegant TypeScript interface. Build AI applications at lightning speed without vendor lock-in.
|
||||
|
||||
## Issue Reporting and Security
|
||||
|
||||
For reporting bugs, issues, or security vulnerabilities, please visit [community.foss.global/](https://community.foss.global/). This is the central community hub for all issue reporting. Developers who sign and comply with our contribution agreement and go through identification can also get a [code.foss.global/](https://code.foss.global/) account to submit Pull Requests directly.
|
||||
|
||||
## 🎯 Why SmartAI?
|
||||
|
||||
@@ -31,8 +36,8 @@ const ai = new SmartAi({
|
||||
anthropicToken: 'sk-ant-...',
|
||||
elevenlabsToken: 'sk-...',
|
||||
elevenlabs: {
|
||||
defaultVoiceId: '19STyYD15bswVz51nqLf' // Optional: Samara voice
|
||||
}
|
||||
defaultVoiceId: '19STyYD15bswVz51nqLf', // Optional: Samara voice
|
||||
},
|
||||
});
|
||||
|
||||
await ai.start();
|
||||
@@ -41,7 +46,7 @@ await ai.start();
|
||||
const response = await ai.openaiProvider.chat({
|
||||
systemMessage: 'You are a helpful assistant.',
|
||||
userMessage: 'Explain quantum computing in simple terms',
|
||||
messageHistory: []
|
||||
messageHistory: [],
|
||||
});
|
||||
```
|
||||
|
||||
@@ -49,16 +54,16 @@ const response = await ai.openaiProvider.chat({
|
||||
|
||||
Choose the right provider for your use case:
|
||||
|
||||
| Provider | Chat | Streaming | TTS | Vision | Documents | Research | Images | Highlights |
|
||||
|----------|:----:|:---------:|:---:|:------:|:---------:|:--------:|:------:|------------|
|
||||
| **OpenAI** | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | • gpt-image-1<br>• DALL-E 3<br>• Deep research API |
|
||||
| **Anthropic** | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ❌ | • Claude Sonnet 4.5<br>• Superior reasoning<br>• Web search API |
|
||||
| **ElevenLabs** | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | • Premium TTS<br>• 70+ languages<br>• Natural voices |
|
||||
| **Ollama** | ✅ | ✅ | ❌ | ✅ | ✅ | ❌ | ❌ | • 100% local<br>• Privacy-first<br>• No API costs |
|
||||
| **XAI** | ✅ | ✅ | ❌ | ❌ | ✅ | ❌ | ❌ | • Grok models<br>• Real-time data<br>• Uncensored |
|
||||
| **Perplexity** | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | ❌ | • Web-aware<br>• Research-focused<br>• Sonar Pro models |
|
||||
| **Groq** | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | • 10x faster<br>• LPU inference<br>• Low latency |
|
||||
| **Exo** | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | • Distributed<br>• P2P compute<br>• Decentralized |
|
||||
| Provider | Chat | Streaming | TTS | Vision | Documents | Research | Images | Highlights |
|
||||
| -------------- | :--: | :-------: | :-: | :----: | :-------: | :------: | :----: | --------------------------------------------------------------- |
|
||||
| **OpenAI** | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | • gpt-image-1<br>• DALL-E 3<br>• Deep research API |
|
||||
| **Anthropic** | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ❌ | • Claude Sonnet 4.5<br>• Superior reasoning<br>• Web search API |
|
||||
| **ElevenLabs** | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | • Premium TTS<br>• 70+ languages<br>• Natural voices |
|
||||
| **Ollama** | ✅ | ✅ | ❌ | ✅ | ✅ | ❌ | ❌ | • 100% local<br>• Privacy-first<br>• No API costs |
|
||||
| **XAI** | ✅ | ✅ | ❌ | ❌ | ✅ | ❌ | ❌ | • Grok models<br>• Real-time data<br>• Uncensored |
|
||||
| **Perplexity** | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | ❌ | • Web-aware<br>• Research-focused<br>• Sonar Pro models |
|
||||
| **Groq** | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | • 10x faster<br>• LPU inference<br>• Low latency |
|
||||
| **Exo** | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | • Distributed<br>• P2P compute<br>• Decentralized |
|
||||
|
||||
## 🎮 Core Features
|
||||
|
||||
@@ -71,21 +76,21 @@ Works identically across all providers:
|
||||
const gptResponse = await ai.openaiProvider.chat({
|
||||
systemMessage: 'You are a expert physicist.',
|
||||
userMessage: 'Explain the implications of quantum entanglement',
|
||||
messageHistory: []
|
||||
messageHistory: [],
|
||||
});
|
||||
|
||||
// Use Claude for safety-critical applications
|
||||
const claudeResponse = await ai.anthropicProvider.chat({
|
||||
systemMessage: 'You are a medical advisor.',
|
||||
userMessage: 'Review this patient data for concerns',
|
||||
messageHistory: []
|
||||
messageHistory: [],
|
||||
});
|
||||
|
||||
// Use Groq for lightning-fast responses
|
||||
const groqResponse = await ai.groqProvider.chat({
|
||||
systemMessage: 'You are a code reviewer.',
|
||||
userMessage: 'Quick! Find the bug in this code: ...',
|
||||
messageHistory: []
|
||||
messageHistory: [],
|
||||
});
|
||||
```
|
||||
|
||||
@@ -102,7 +107,7 @@ const reader = stream.getReader();
|
||||
while (true) {
|
||||
const { done, value } = await reader.read();
|
||||
if (done) break;
|
||||
|
||||
|
||||
// Update UI in real-time
|
||||
process.stdout.write(value);
|
||||
}
|
||||
@@ -115,7 +120,7 @@ Generate natural voices with OpenAI or ElevenLabs:
|
||||
```typescript
|
||||
// OpenAI TTS
|
||||
const audioStream = await ai.openaiProvider.audio({
|
||||
message: 'Welcome to the future of AI development!'
|
||||
message: 'Welcome to the future of AI development!',
|
||||
});
|
||||
|
||||
// ElevenLabs TTS - Premium quality, natural voices (uses v3 by default)
|
||||
@@ -123,12 +128,13 @@ const elevenLabsAudio = await ai.elevenlabsProvider.audio({
|
||||
message: 'Experience the most lifelike text to speech technology.',
|
||||
voiceId: '19STyYD15bswVz51nqLf', // Optional: Samara voice
|
||||
modelId: 'eleven_v3', // Optional: defaults to eleven_v3 (70+ languages, most expressive)
|
||||
voiceSettings: { // Optional: fine-tune voice characteristics
|
||||
stability: 0.5, // 0-1: Speech consistency
|
||||
voiceSettings: {
|
||||
// Optional: fine-tune voice characteristics
|
||||
stability: 0.5, // 0-1: Speech consistency
|
||||
similarity_boost: 0.8, // 0-1: Voice similarity to original
|
||||
style: 0.0, // 0-1: Expressiveness (higher = more expressive)
|
||||
use_speaker_boost: true // Enhanced clarity
|
||||
}
|
||||
style: 0.0, // 0-1: Expressiveness (higher = more expressive)
|
||||
use_speaker_boost: true, // Enhanced clarity
|
||||
},
|
||||
});
|
||||
|
||||
// Stream directly to speakers
|
||||
@@ -148,19 +154,19 @@ const image = fs.readFileSync('product-photo.jpg');
|
||||
// OpenAI: General purpose vision
|
||||
const gptVision = await ai.openaiProvider.vision({
|
||||
image,
|
||||
prompt: 'Describe this product and suggest marketing angles'
|
||||
prompt: 'Describe this product and suggest marketing angles',
|
||||
});
|
||||
|
||||
// Anthropic: Detailed analysis
|
||||
const claudeVision = await ai.anthropicProvider.vision({
|
||||
image,
|
||||
prompt: 'Identify any safety concerns or defects'
|
||||
prompt: 'Identify any safety concerns or defects',
|
||||
});
|
||||
|
||||
// Ollama: Private, local analysis
|
||||
const ollamaVision = await ai.ollamaProvider.vision({
|
||||
image,
|
||||
prompt: 'Extract all text and categorize the content'
|
||||
prompt: 'Extract all text and categorize the content',
|
||||
});
|
||||
```
|
||||
|
||||
@@ -177,7 +183,7 @@ const analysis = await ai.openaiProvider.document({
|
||||
systemMessage: 'You are a legal expert.',
|
||||
userMessage: 'Compare these documents and highlight key differences',
|
||||
messageHistory: [],
|
||||
pdfDocuments: [contract, invoice]
|
||||
pdfDocuments: [contract, invoice],
|
||||
});
|
||||
|
||||
// Multi-document analysis
|
||||
@@ -186,7 +192,7 @@ const taxAnalysis = await ai.anthropicProvider.document({
|
||||
systemMessage: 'You are a tax advisor.',
|
||||
userMessage: 'Prepare a tax summary from these documents',
|
||||
messageHistory: [],
|
||||
pdfDocuments: taxDocs
|
||||
pdfDocuments: taxDocs,
|
||||
});
|
||||
```
|
||||
|
||||
@@ -199,7 +205,7 @@ Perform deep research with web search capabilities across multiple providers:
|
||||
const deepResearch = await ai.openaiProvider.research({
|
||||
query: 'What are the latest developments in quantum computing?',
|
||||
searchDepth: 'deep',
|
||||
includeWebSearch: true
|
||||
includeWebSearch: true,
|
||||
});
|
||||
|
||||
console.log(deepResearch.answer);
|
||||
@@ -209,32 +215,73 @@ console.log('Sources:', deepResearch.sources);
|
||||
const anthropic = new AnthropicProvider({
|
||||
anthropicToken: 'sk-ant-...',
|
||||
enableWebSearch: true,
|
||||
searchDomainAllowList: ['nature.com', 'science.org']
|
||||
searchDomainAllowList: ['nature.com', 'science.org'],
|
||||
});
|
||||
|
||||
const scientificResearch = await anthropic.research({
|
||||
query: 'Latest breakthroughs in CRISPR gene editing',
|
||||
searchDepth: 'advanced'
|
||||
searchDepth: 'advanced',
|
||||
});
|
||||
|
||||
// Perplexity - Research-focused with citations
|
||||
const perplexityResearch = await ai.perplexityProvider.research({
|
||||
query: 'Current state of autonomous vehicle technology',
|
||||
searchDepth: 'deep' // Uses Sonar Pro model
|
||||
searchDepth: 'deep', // Uses Sonar Pro model
|
||||
});
|
||||
```
|
||||
|
||||
**Research Options:**
|
||||
|
||||
- `searchDepth`: 'basic' | 'advanced' | 'deep'
|
||||
- `maxSources`: Number of sources to include
|
||||
- `includeWebSearch`: Enable web search (OpenAI)
|
||||
- `background`: Run as background task (OpenAI)
|
||||
|
||||
**Supported Providers:**
|
||||
|
||||
- **OpenAI**: Deep Research API with specialized models (`o3-deep-research-2025-06-26`, `o4-mini-deep-research-2025-06-26`)
|
||||
- **Anthropic**: Web Search API with domain filtering
|
||||
- **Perplexity**: Sonar and Sonar Pro models with built-in citations
|
||||
|
||||
### 🧠 Extended Thinking (Anthropic)
|
||||
|
||||
Enable Claude to spend more time reasoning about complex problems before generating responses:
|
||||
|
||||
```typescript
|
||||
import { AnthropicProvider } from '@push.rocks/smartai';
|
||||
|
||||
// Configure extended thinking mode at provider level
|
||||
const anthropic = new AnthropicProvider({
|
||||
anthropicToken: 'sk-ant-...',
|
||||
extendedThinking: 'normal', // Options: 'quick' | 'normal' | 'deep' | 'off'
|
||||
});
|
||||
|
||||
await anthropic.start();
|
||||
|
||||
// Extended thinking is automatically applied to all methods
|
||||
const response = await anthropic.chat({
|
||||
systemMessage: 'You are an expert mathematician.',
|
||||
userMessage: 'Prove the Pythagorean theorem from first principles',
|
||||
messageHistory: [],
|
||||
});
|
||||
```
|
||||
|
||||
**Thinking Modes:**
|
||||
|
||||
| Mode | Budget Tokens | Use Case |
|
||||
|------|---------------|----------|
|
||||
| `'quick'` | 2,048 | Lightweight reasoning for simple queries |
|
||||
| `'normal'` | 8,000 | **Default** - Balanced reasoning for most tasks |
|
||||
| `'deep'` | 16,000 | Complex reasoning for difficult problems |
|
||||
| `'off'` | 0 | Disable extended thinking |
|
||||
|
||||
**Best Practices:**
|
||||
|
||||
- Start with `'normal'` (default) for general usage
|
||||
- Use `'deep'` for complex analytical tasks, philosophy, mathematics, or research
|
||||
- Use `'quick'` for simple factual queries where deep reasoning isn't needed
|
||||
- Thinking budget counts against total token usage
|
||||
|
||||
### 🎨 Image Generation & Editing
|
||||
|
||||
Generate and edit images with OpenAI's cutting-edge models:
|
||||
@@ -245,7 +292,7 @@ const image = await ai.openaiProvider.imageGenerate({
|
||||
prompt: 'A futuristic robot assistant in a modern office, digital art',
|
||||
model: 'gpt-image-1',
|
||||
quality: 'high',
|
||||
size: '1024x1024'
|
||||
size: '1024x1024',
|
||||
});
|
||||
|
||||
// Save the generated image
|
||||
@@ -259,7 +306,7 @@ const logo = await ai.openaiProvider.imageGenerate({
|
||||
quality: 'high',
|
||||
size: '1024x1024',
|
||||
background: 'transparent',
|
||||
outputFormat: 'png'
|
||||
outputFormat: 'png',
|
||||
});
|
||||
|
||||
// WebP with compression for web use
|
||||
@@ -269,15 +316,16 @@ const webImage = await ai.openaiProvider.imageGenerate({
|
||||
quality: 'high',
|
||||
size: '1536x1024',
|
||||
outputFormat: 'webp',
|
||||
outputCompression: 85
|
||||
outputCompression: 85,
|
||||
});
|
||||
|
||||
// Superior text rendering (gpt-image-1's strength)
|
||||
const signage = await ai.openaiProvider.imageGenerate({
|
||||
prompt: 'Vintage cafe sign saying "COFFEE & CODE" in hand-lettered typography',
|
||||
prompt:
|
||||
'Vintage cafe sign saying "COFFEE & CODE" in hand-lettered typography',
|
||||
model: 'gpt-image-1',
|
||||
quality: 'high',
|
||||
size: '1024x1024'
|
||||
size: '1024x1024',
|
||||
});
|
||||
|
||||
// Generate multiple variations at once
|
||||
@@ -286,7 +334,7 @@ const variations = await ai.openaiProvider.imageGenerate({
|
||||
model: 'gpt-image-1',
|
||||
n: 3,
|
||||
quality: 'medium',
|
||||
size: '1024x1024'
|
||||
size: '1024x1024',
|
||||
});
|
||||
|
||||
// Edit an existing image
|
||||
@@ -294,11 +342,12 @@ const editedImage = await ai.openaiProvider.imageEdit({
|
||||
image: originalImageBuffer,
|
||||
prompt: 'Add sunglasses and change the background to a beach sunset',
|
||||
model: 'gpt-image-1',
|
||||
quality: 'high'
|
||||
quality: 'high',
|
||||
});
|
||||
```
|
||||
|
||||
**Image Generation Options:**
|
||||
|
||||
- `model`: 'gpt-image-1' | 'dall-e-3' | 'dall-e-2'
|
||||
- `quality`: 'low' | 'medium' | 'high' | 'auto'
|
||||
- `size`: Multiple aspect ratios up to 4096×4096
|
||||
@@ -309,6 +358,7 @@ const editedImage = await ai.openaiProvider.imageEdit({
|
||||
- `n`: Number of images (1-10)
|
||||
|
||||
**gpt-image-1 Advantages:**
|
||||
|
||||
- Superior text rendering in images
|
||||
- Up to 4096×4096 resolution
|
||||
- Transparent background support
|
||||
@@ -347,12 +397,12 @@ const supportBot = new SmartAi({
|
||||
async function handleCustomerQuery(query: string, history: ChatMessage[]) {
|
||||
try {
|
||||
const response = await supportBot.anthropicProvider.chat({
|
||||
systemMessage: `You are a helpful customer support agent.
|
||||
systemMessage: `You are a helpful customer support agent.
|
||||
Be empathetic, professional, and solution-oriented.`,
|
||||
userMessage: query,
|
||||
messageHistory: history
|
||||
});
|
||||
|
||||
|
||||
return response.message;
|
||||
} catch (error) {
|
||||
// Fallback to another provider if needed
|
||||
@@ -365,12 +415,12 @@ async function handleCustomerQuery(query: string, history: ChatMessage[]) {
|
||||
|
||||
```typescript
|
||||
const codeReviewer = new SmartAi({
|
||||
groqToken: process.env.GROQ_KEY // Groq for speed
|
||||
groqToken: process.env.GROQ_KEY, // Groq for speed
|
||||
});
|
||||
|
||||
async function reviewCode(code: string, language: string) {
|
||||
const startTime = Date.now();
|
||||
|
||||
|
||||
const review = await codeReviewer.groqProvider.chat({
|
||||
systemMessage: `You are a ${language} expert. Review code for:
|
||||
- Security vulnerabilities
|
||||
@@ -378,9 +428,9 @@ async function reviewCode(code: string, language: string) {
|
||||
- Best practices
|
||||
- Potential bugs`,
|
||||
userMessage: `Review this code:\n\n${code}`,
|
||||
messageHistory: []
|
||||
messageHistory: [],
|
||||
});
|
||||
|
||||
|
||||
console.log(`Review completed in ${Date.now() - startTime}ms`);
|
||||
return review.message;
|
||||
}
|
||||
@@ -390,17 +440,18 @@ async function reviewCode(code: string, language: string) {
|
||||
|
||||
```typescript
|
||||
const researcher = new SmartAi({
|
||||
perplexityToken: process.env.PERPLEXITY_KEY
|
||||
perplexityToken: process.env.PERPLEXITY_KEY,
|
||||
});
|
||||
|
||||
async function research(topic: string) {
|
||||
// Perplexity excels at web-aware research
|
||||
const findings = await researcher.perplexityProvider.chat({
|
||||
systemMessage: 'You are a research assistant. Provide factual, cited information.',
|
||||
systemMessage:
|
||||
'You are a research assistant. Provide factual, cited information.',
|
||||
userMessage: `Research the latest developments in ${topic}`,
|
||||
messageHistory: []
|
||||
messageHistory: [],
|
||||
});
|
||||
|
||||
|
||||
return findings.message;
|
||||
}
|
||||
```
|
||||
@@ -412,8 +463,8 @@ const localAI = new SmartAi({
|
||||
ollama: {
|
||||
baseUrl: 'http://localhost:11434',
|
||||
model: 'llama2',
|
||||
visionModel: 'llava'
|
||||
}
|
||||
visionModel: 'llava',
|
||||
},
|
||||
});
|
||||
|
||||
// Process sensitive documents without leaving your infrastructure
|
||||
@@ -422,9 +473,9 @@ async function analyzeSensitiveDoc(pdfBuffer: Buffer) {
|
||||
systemMessage: 'Extract and summarize key information.',
|
||||
userMessage: 'Analyze this confidential document',
|
||||
messageHistory: [],
|
||||
pdfDocuments: [pdfBuffer]
|
||||
pdfDocuments: [pdfBuffer],
|
||||
});
|
||||
|
||||
|
||||
// Data never leaves your servers
|
||||
return analysis.message;
|
||||
}
|
||||
@@ -437,7 +488,7 @@ async function analyzeSensitiveDoc(pdfBuffer: Buffer) {
|
||||
```typescript
|
||||
class SmartAIRouter {
|
||||
constructor(private ai: SmartAi) {}
|
||||
|
||||
|
||||
async query(message: string, requirements: {
|
||||
speed?: boolean;
|
||||
accuracy?: boolean;
|
||||
@@ -464,8 +515,10 @@ class SmartAIRouter {
|
||||
```typescript
|
||||
// Don't wait for the entire response
|
||||
async function streamResponse(userQuery: string) {
|
||||
const stream = await ai.openaiProvider.chatStream(createInputStream(userQuery));
|
||||
|
||||
const stream = await ai.openaiProvider.chatStream(
|
||||
createInputStream(userQuery),
|
||||
);
|
||||
|
||||
// Process tokens as they arrive
|
||||
for await (const chunk of stream) {
|
||||
updateUI(chunk); // Immediate feedback
|
||||
@@ -484,7 +537,7 @@ async function consensusQuery(question: string) {
|
||||
ai.anthropicProvider.chat({...}),
|
||||
ai.perplexityProvider.chat({...})
|
||||
];
|
||||
|
||||
|
||||
const responses = await Promise.all(providers);
|
||||
return synthesizeResponses(responses);
|
||||
}
|
||||
@@ -500,7 +553,7 @@ const translationStream = new TransformStream({
|
||||
async transform(chunk, controller) {
|
||||
const translated = await translateChunk(chunk);
|
||||
controller.enqueue(translated);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
const responseStream = await ai.openaiProvider.chatStream(input);
|
||||
@@ -512,7 +565,7 @@ const translatedStream = responseStream.pipeThrough(translationStream);
|
||||
```typescript
|
||||
class ResilientAI {
|
||||
private providers = ['openai', 'anthropic', 'groq'];
|
||||
|
||||
|
||||
async query(opts: ChatOptions): Promise<ChatResponse> {
|
||||
for (const provider of this.providers) {
|
||||
try {
|
||||
@@ -535,14 +588,14 @@ class UsageTracker {
|
||||
async trackedChat(provider: string, options: ChatOptions) {
|
||||
const start = Date.now();
|
||||
const response = await ai[`${provider}Provider`].chat(options);
|
||||
|
||||
|
||||
const usage = {
|
||||
provider,
|
||||
duration: Date.now() - start,
|
||||
inputTokens: estimateTokens(options),
|
||||
outputTokens: estimateTokens(response.message)
|
||||
outputTokens: estimateTokens(response.message),
|
||||
};
|
||||
|
||||
|
||||
await this.logUsage(usage);
|
||||
return response;
|
||||
}
|
||||
@@ -553,7 +606,7 @@ class UsageTracker {
|
||||
|
||||
### Prerequisites
|
||||
|
||||
- Node.js 16+
|
||||
- Node.js 16+
|
||||
- TypeScript 4.5+
|
||||
- API keys for your chosen providers
|
||||
|
||||
@@ -588,17 +641,17 @@ export ELEVENLABS_API_KEY=sk-...
|
||||
|
||||
## 🎯 Choosing the Right Provider
|
||||
|
||||
| Use Case | Recommended Provider | Why |
|
||||
|----------|---------------------|-----|
|
||||
| **General Purpose** | OpenAI | Most features, stable, well-documented |
|
||||
| **Complex Reasoning** | Anthropic | Superior logical thinking, safer outputs |
|
||||
| **Research & Facts** | Perplexity | Web-aware, provides citations |
|
||||
| **Deep Research** | OpenAI | Deep Research API with comprehensive analysis |
|
||||
| **Premium TTS** | ElevenLabs | Most natural voices, 70+ languages, superior quality (v3) |
|
||||
| **Speed Critical** | Groq | 10x faster inference, sub-second responses |
|
||||
| **Privacy Critical** | Ollama | 100% local, no data leaves your servers |
|
||||
| **Real-time Data** | XAI | Access to current information |
|
||||
| **Cost Sensitive** | Ollama/Exo | Free (local) or distributed compute |
|
||||
| Use Case | Recommended Provider | Why |
|
||||
| --------------------- | -------------------- | --------------------------------------------------------- |
|
||||
| **General Purpose** | OpenAI | Most features, stable, well-documented |
|
||||
| **Complex Reasoning** | Anthropic | Superior logical thinking, safer outputs |
|
||||
| **Research & Facts** | Perplexity | Web-aware, provides citations |
|
||||
| **Deep Research** | OpenAI | Deep Research API with comprehensive analysis |
|
||||
| **Premium TTS** | ElevenLabs | Most natural voices, 70+ languages, superior quality (v3) |
|
||||
| **Speed Critical** | Groq | 10x faster inference, sub-second responses |
|
||||
| **Privacy Critical** | Ollama | 100% local, no data leaves your servers |
|
||||
| **Real-time Data** | XAI | Access to current information |
|
||||
| **Cost Sensitive** | Ollama/Exo | Free (local) or distributed compute |
|
||||
|
||||
## 📈 Roadmap
|
||||
|
||||
@@ -613,19 +666,21 @@ export ELEVENLABS_API_KEY=sk-...
|
||||
|
||||
## License and Legal Information
|
||||
|
||||
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
|
||||
This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [LICENSE](./LICENSE) file.
|
||||
|
||||
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
||||
|
||||
### Trademarks
|
||||
|
||||
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
|
||||
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH or third parties, and are not included within the scope of the MIT license granted herein.
|
||||
|
||||
Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.
|
||||
|
||||
### Company Information
|
||||
|
||||
Task Venture Capital GmbH
|
||||
Registered at District court Bremen HRB 35230 HB, Germany
|
||||
Task Venture Capital GmbH
|
||||
Registered at District Court Bremen HRB 35230 HB, Germany
|
||||
|
||||
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
|
||||
For any legal inquiries or further information, please contact us via email at hello@task.vc.
|
||||
|
||||
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
||||
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import * as qenv from '@push.rocks/qenv';
|
||||
import * as smartfile from '@push.rocks/smartfile';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import * as qenv from '@push.rocks/qenv';
|
||||
import * as smartfile from '@push.rocks/smartfile';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import * as qenv from '@push.rocks/qenv';
|
||||
|
||||
const testQenv = new qenv.Qenv('./', './.nogit/');
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { tap, expect } from '@push.rocks/tapbundle';
|
||||
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
||||
import * as smartai from '../ts/index.js';
|
||||
|
||||
// Basic instantiation tests that don't require API tokens
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import * as qenv from '@push.rocks/qenv';
|
||||
|
||||
const testQenv = new qenv.Qenv('./', './.nogit/');
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import * as qenv from '@push.rocks/qenv';
|
||||
|
||||
const testQenv = new qenv.Qenv('./', './.nogit/');
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import * as qenv from '@push.rocks/qenv';
|
||||
import * as smartrequest from '@push.rocks/smartrequest';
|
||||
import * as smartfile from '@push.rocks/smartfile';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import * as qenv from '@push.rocks/qenv';
|
||||
import * as smartrequest from '@push.rocks/smartrequest';
|
||||
import * as smartfile from '@push.rocks/smartfile';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import * as qenv from '@push.rocks/qenv';
|
||||
import * as smartai from '../ts/index.js';
|
||||
import * as path from 'path';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { tap, expect } from '@push.rocks/tapbundle';
|
||||
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
||||
import * as smartai from '../ts/index.js';
|
||||
|
||||
// Test interface exports and type checking
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import * as qenv from '@push.rocks/qenv';
|
||||
import * as smartai from '../ts/index.js';
|
||||
import * as path from 'path';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import * as qenv from '@push.rocks/qenv';
|
||||
import * as smartai from '../ts/index.js';
|
||||
import * as path from 'path';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { tap, expect } from '@push.rocks/tapbundle';
|
||||
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
||||
import * as smartai from '../ts/index.js';
|
||||
|
||||
// Test research method stubs for providers without full implementation
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import * as qenv from '@push.rocks/qenv';
|
||||
|
||||
const testQenv = new qenv.Qenv('./', './.nogit/');
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import * as qenv from '@push.rocks/qenv';
|
||||
import * as smartfile from '@push.rocks/smartfile';
|
||||
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartai',
|
||||
version: '0.8.0',
|
||||
version: '0.9.0',
|
||||
description: 'SmartAi is a versatile TypeScript library designed to facilitate integration and interaction with various AI models, offering functionalities for chat, audio generation, document processing, and vision tasks.'
|
||||
}
|
||||
|
||||
@@ -317,7 +317,11 @@ export class AnthropicProvider extends MultiModalModel {
|
||||
const maxTokens = optionsArg.searchDepth === 'deep' ? 20000 :
|
||||
optionsArg.searchDepth === 'advanced' ? 20000 : 20000;
|
||||
|
||||
// Add thinking configuration if enabled
|
||||
const thinkingConfig = this.getThinkingConfig();
|
||||
|
||||
// Create the research request
|
||||
// Note: When thinking is enabled, temperature must be 1 (or omitted)
|
||||
const requestParams: any = {
|
||||
model: 'claude-sonnet-4-5-20250929',
|
||||
system: systemMessage,
|
||||
@@ -328,7 +332,8 @@ export class AnthropicProvider extends MultiModalModel {
|
||||
}
|
||||
],
|
||||
max_tokens: maxTokens,
|
||||
temperature: 0.7
|
||||
// Only set temperature when thinking is NOT enabled
|
||||
...(thinkingConfig ? {} : { temperature: 0.7 })
|
||||
};
|
||||
|
||||
// Add tools if web search is enabled
|
||||
@@ -337,7 +342,6 @@ export class AnthropicProvider extends MultiModalModel {
|
||||
}
|
||||
|
||||
// Add thinking configuration if enabled
|
||||
const thinkingConfig = this.getThinkingConfig();
|
||||
if (thinkingConfig) {
|
||||
requestParams.thinking = thinkingConfig;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import * as plugins from './plugins.js';
|
||||
import { Readable } from 'stream';
|
||||
|
||||
import { MultiModalModel } from './abstract.classes.multimodal.js';
|
||||
import type {
|
||||
@@ -83,7 +84,8 @@ export class ElevenLabsProvider extends MultiModalModel {
|
||||
throw new Error(`ElevenLabs API error: ${response.status} ${response.statusText} - ${errorText}`);
|
||||
}
|
||||
|
||||
const nodeStream = response.streamNode();
|
||||
const webStream = response.stream();
|
||||
const nodeStream = Readable.fromWeb(webStream as any);
|
||||
return nodeStream;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import * as plugins from './plugins.js';
|
||||
import * as paths from './paths.js';
|
||||
import { Readable } from 'stream';
|
||||
import { toFile } from 'openai';
|
||||
|
||||
// Custom type definition for chat completion messages
|
||||
export type TChatCompletionRequestMessage = {
|
||||
@@ -405,16 +406,19 @@ export class OpenAiProvider extends MultiModalModel {
|
||||
const model = optionsArg.model || this.options.imageModel || 'gpt-image-1';
|
||||
|
||||
try {
|
||||
// Convert Buffer to uploadable file format for OpenAI API
|
||||
const imageFile = await toFile(optionsArg.image, 'image.png', { type: 'image/png' });
|
||||
|
||||
const requestParams: any = {
|
||||
model,
|
||||
image: optionsArg.image,
|
||||
image: imageFile,
|
||||
prompt: optionsArg.prompt,
|
||||
n: optionsArg.n || 1,
|
||||
};
|
||||
|
||||
// Add mask if provided
|
||||
// Add mask if provided (also convert to file format)
|
||||
if (optionsArg.mask) {
|
||||
requestParams.mask = optionsArg.mask;
|
||||
requestParams.mask = await toFile(optionsArg.mask, 'mask.png', { type: 'image/png' });
|
||||
}
|
||||
|
||||
// Add gpt-image-1 specific parameters
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"esModuleInterop": true,
|
||||
"verbatimModuleSyntax": true
|
||||
"verbatimModuleSyntax": true,
|
||||
"baseUrl": ".",
|
||||
"paths": {}
|
||||
},
|
||||
"exclude": [
|
||||
"dist_*/**/*.d.ts"
|
||||
]
|
||||
"exclude": ["dist_*/**/*.d.ts"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user