2024-04-04 00:47:44 +00:00
|
|
|
import { Conversation } from './classes.conversation.js';
|
|
|
|
import * as plugins from './plugins.js';
|
2024-04-29 09:18:40 +00:00
|
|
|
import { AnthropicProvider } from './provider.anthropic.js';
|
2024-04-25 08:49:07 +00:00
|
|
|
import type { OllamaProvider } from './provider.ollama.js';
|
2024-04-27 10:47:49 +00:00
|
|
|
import { OpenAiProvider } from './provider.openai.js';
|
2024-04-25 08:49:07 +00:00
|
|
|
import type { PerplexityProvider } from './provider.perplexity.js';
|
2024-04-04 00:47:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
export interface ISmartAiOptions {
|
2024-04-25 08:49:07 +00:00
|
|
|
openaiToken?: string;
|
|
|
|
anthropicToken?: string;
|
|
|
|
perplexityToken?: string;
|
2024-04-04 00:47:44 +00:00
|
|
|
}
|
|
|
|
|
2024-04-29 09:18:40 +00:00
|
|
|
export type TProvider = 'openai' | 'anthropic' | 'perplexity' | 'ollama';
|
|
|
|
|
2024-04-04 00:47:44 +00:00
|
|
|
export class SmartAi {
|
|
|
|
public options: ISmartAiOptions;
|
|
|
|
|
2024-04-25 08:49:07 +00:00
|
|
|
public openaiProvider: OpenAiProvider;
|
|
|
|
public anthropicProvider: AnthropicProvider;
|
|
|
|
public perplexityProvider: PerplexityProvider;
|
|
|
|
public ollamaProvider: OllamaProvider;
|
|
|
|
|
2024-04-04 00:47:44 +00:00
|
|
|
constructor(optionsArg: ISmartAiOptions) {
|
|
|
|
this.options = optionsArg;
|
|
|
|
}
|
2024-04-25 08:49:07 +00:00
|
|
|
|
|
|
|
public async start() {
|
2024-04-27 10:47:49 +00:00
|
|
|
if (this.options.openaiToken) {
|
|
|
|
this.openaiProvider = new OpenAiProvider({
|
|
|
|
openaiToken: this.options.openaiToken,
|
|
|
|
});
|
|
|
|
await this.openaiProvider.start();
|
|
|
|
}
|
2024-04-29 09:18:40 +00:00
|
|
|
if (this.options.anthropicToken) {
|
|
|
|
this.anthropicProvider = new AnthropicProvider({
|
|
|
|
anthropicToken: this.options.anthropicToken,
|
|
|
|
});
|
|
|
|
}
|
2024-04-25 08:49:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public async stop() {}
|
2024-04-04 00:47:44 +00:00
|
|
|
|
|
|
|
/**
|
2024-04-29 09:18:40 +00:00
|
|
|
* create a new conversation
|
2024-04-04 00:47:44 +00:00
|
|
|
*/
|
2024-04-29 09:18:40 +00:00
|
|
|
createConversation(provider: TProvider) {
|
|
|
|
switch (provider) {
|
|
|
|
case 'openai':
|
|
|
|
return Conversation.createWithOpenAi(this);
|
|
|
|
case 'anthropic':
|
|
|
|
return Conversation.createWithAnthropic(this);
|
|
|
|
case 'perplexity':
|
|
|
|
return Conversation.createWithPerplexity(this);
|
|
|
|
case 'ollama':
|
|
|
|
return Conversation.createWithOllama(this);
|
|
|
|
default:
|
|
|
|
throw new Error('Provider not available');
|
|
|
|
}
|
2024-04-04 00:47:44 +00:00
|
|
|
}
|
|
|
|
}
|