@neurodevworks/chatbot-core
Version:
Core AI chatbot functionality for Angular applications
182 lines (133 loc) • 4.59 kB
Markdown
[](https://www.npmjs.com/package/@neurodevworks/chatbot-core)
[](https://opensource.org/licenses/MIT)
Core AI client services and utilities for chatbot functionality in Angular applications.
- **Multi-AI Provider Support**: OpenAI, Claude, Gemini, and more
- **Streaming Responses**: Real-time token streaming with RxJS observables
- **TypeScript First**: Full type safety and IntelliSense support
- **Reactive Architecture**: Built with RxJS for reactive programming
- **Error Handling**: Comprehensive error handling and retry logic
- **Configurable**: Flexible configuration options for different AI providers
```bash
npm install @neurodevworks/chatbot-core
```
```typescript
import { AIClientService } from '@neurodevworks/chatbot-core';
// Initialize the service
const aiClient = new AIClientService();
// Configure with OpenAI
aiClient.initialize({
provider: 'openai',
apiKey: 'your-openai-api-key',
model: 'gpt-3.5-turbo'
});
// Send a message
const response = await aiClient.sendMessage('Hello, AI!');
console.log(response);
```
```typescript
// Send streaming message
await aiClient.sendStreamingMessage('Tell me a story');
// Subscribe to token stream
aiClient.tokenStream$.subscribe(token => {
console.log('New token:', token);
});
// Subscribe to completion
aiClient.responseComplete$.subscribe(fullResponse => {
console.log('Complete response:', fullResponse);
});
```
```typescript
import { Injectable } from '@angular/core';
import { AIClientService, AIClientOptions } from '@neurodevworks/chatbot-core';
@Injectable({
providedIn: 'root'
})
export class ChatService {
constructor(private aiClient: AIClientService) {}
async initializeChat(apiKey: string) {
const options: AIClientOptions = {
provider: 'openai',
apiKey,
model: 'gpt-3.5-turbo'
};
this.aiClient.initialize(options);
}
async sendMessage(message: string) {
return await this.aiClient.sendMessage(message, {
temperature: 0.7,
maxTokens: 1000
});
}
}
```
- `initialize(options: AIClientOptions): void` - Initialize the AI client
- `sendMessage(message: string, options?: MessageOptions): Promise<string>` - Send a message
- `sendStreamingMessage(message: string, options?: MessageOptions): Promise<void>` - Send streaming message
- `clearMessages(): void` - Clear message history
- `isInitialized: boolean` - Check if client is initialized
- `tokenStream$: Observable<string>` - Stream of tokens during response generation
- `responseComplete$: Observable<string>` - Complete response when generation finishes
```typescript
interface AIClientOptions {
provider: 'openai' | 'claude' | 'gemini';
apiKey: string;
model: string;
baseUrl?: string;
}
interface MessageOptions {
temperature?: number;
maxTokens?: number;
systemPrompt?: string;
}
```
```typescript
const options: AIClientOptions = {
provider: 'openai',
apiKey: 'sk-...',
model: 'gpt-3.5-turbo' // or 'gpt-4'
};
```
```typescript
const options: AIClientOptions = {
provider: 'claude',
apiKey: 'sk-ant-...',
model: 'claude-3-sonnet-20240229'
};
```
```typescript
const options: AIClientOptions = {
provider: 'gemini',
apiKey: 'AI...',
model: 'gemini-pro'
};
```
We welcome contributions! Please see our [Contributing Guide](https://github.com/NeuroDevWorks/angular-chatbot-ai/blob/main/CONTRIBUTING.md) for details.
This project is licensed under the MIT License - see the [LICENSE](https://github.com/NeuroDevWorks/angular-chatbot-ai/blob/main/LICENSE) file for details.
- [@neurodevworks/angular-chatbot](https://www.npmjs.com/package/@neurodevworks/angular-chatbot) - Angular UI components
- [Angular Chatbot AI](https://github.com/NeuroDevWorks/angular-chatbot-ai) - Complete monorepo
**Manoj Kumar**
- Email: manojkumar.smgr@gmail.com
- GitHub: [@neurodevworks](https://github.com/neurodevworks)
- NPM: [@neurodevworks](https://www.npmjs.com/~neurodevworks)
---
Made with ❤️ by [NeuroDevWorks](https://github.com/NeuroDevWorks)