2024-04-04 02:47:44 +02:00
|
|
|
import { Conversation } from './classes.conversation.js';
|
|
|
|
import * as plugins from './plugins.js';
|
2024-04-29 11:18:40 +02:00
|
|
|
import { AnthropicProvider } from './provider.anthropic.js';
|
2025-02-08 12:08:14 +01:00
|
|
|
import { OllamaProvider } from './provider.ollama.js';
|
2024-04-27 12:47:49 +02:00
|
|
|
import { OpenAiProvider } from './provider.openai.js';
|
2025-02-08 12:08:14 +01:00
|
|
|
import { PerplexityProvider } from './provider.perplexity.js';
|
|
|
|
import { ExoProvider } from './provider.exo.js';
|
|
|
|
import { GroqProvider } from './provider.groq.js';
|
|
|
|
import { XAIProvider } from './provider.xai.js';
|
2024-04-04 02:47:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
export interface ISmartAiOptions {
|
2024-04-25 10:49:07 +02:00
|
|
|
openaiToken?: string;
|
|
|
|
anthropicToken?: string;
|
|
|
|
perplexityToken?: string;
|
2025-02-08 12:08:14 +01:00
|
|
|
groqToken?: string;
|
|
|
|
xaiToken?: string;
|
|
|
|
exo?: {
|
|
|
|
baseUrl?: string;
|
|
|
|
apiKey?: string;
|
|
|
|
};
|
|
|
|
ollama?: {
|
|
|
|
baseUrl?: string;
|
|
|
|
model?: string;
|
|
|
|
visionModel?: string;
|
|
|
|
};
|
2024-04-04 02:47:44 +02:00
|
|
|
}
|
|
|
|
|
2025-02-08 12:08:14 +01:00
|
|
|
export type TProvider = 'openai' | 'anthropic' | 'perplexity' | 'ollama' | 'exo' | 'groq' | 'xai';
|
2024-04-29 11:18:40 +02:00
|
|
|
|
2024-04-04 02:47:44 +02:00
|
|
|
export class SmartAi {
|
|
|
|
public options: ISmartAiOptions;
|
|
|
|
|
2024-04-25 10:49:07 +02:00
|
|
|
public openaiProvider: OpenAiProvider;
|
|
|
|
public anthropicProvider: AnthropicProvider;
|
|
|
|
public perplexityProvider: PerplexityProvider;
|
|
|
|
public ollamaProvider: OllamaProvider;
|
2025-02-08 12:08:14 +01:00
|
|
|
public exoProvider: ExoProvider;
|
|
|
|
public groqProvider: GroqProvider;
|
|
|
|
public xaiProvider: XAIProvider;
|
2024-04-25 10:49:07 +02:00
|
|
|
|
2024-04-04 02:47:44 +02:00
|
|
|
constructor(optionsArg: ISmartAiOptions) {
|
|
|
|
this.options = optionsArg;
|
|
|
|
}
|
2024-04-25 10:49:07 +02:00
|
|
|
|
|
|
|
public async start() {
|
2024-04-27 12:47:49 +02:00
|
|
|
if (this.options.openaiToken) {
|
|
|
|
this.openaiProvider = new OpenAiProvider({
|
|
|
|
openaiToken: this.options.openaiToken,
|
|
|
|
});
|
|
|
|
await this.openaiProvider.start();
|
|
|
|
}
|
2024-04-29 11:18:40 +02:00
|
|
|
if (this.options.anthropicToken) {
|
|
|
|
this.anthropicProvider = new AnthropicProvider({
|
|
|
|
anthropicToken: this.options.anthropicToken,
|
|
|
|
});
|
2025-02-08 12:08:14 +01:00
|
|
|
await this.anthropicProvider.start();
|
|
|
|
}
|
|
|
|
if (this.options.perplexityToken) {
|
|
|
|
this.perplexityProvider = new PerplexityProvider({
|
|
|
|
perplexityToken: this.options.perplexityToken,
|
|
|
|
});
|
|
|
|
await this.perplexityProvider.start();
|
|
|
|
}
|
|
|
|
if (this.options.groqToken) {
|
|
|
|
this.groqProvider = new GroqProvider({
|
|
|
|
groqToken: this.options.groqToken,
|
|
|
|
});
|
|
|
|
await this.groqProvider.start();
|
|
|
|
}
|
|
|
|
if (this.options.xaiToken) {
|
|
|
|
this.xaiProvider = new XAIProvider({
|
|
|
|
xaiToken: this.options.xaiToken,
|
|
|
|
});
|
|
|
|
await this.xaiProvider.start();
|
|
|
|
}
|
|
|
|
if (this.options.ollama) {
|
|
|
|
this.ollamaProvider = new OllamaProvider({
|
|
|
|
baseUrl: this.options.ollama.baseUrl,
|
|
|
|
model: this.options.ollama.model,
|
|
|
|
visionModel: this.options.ollama.visionModel,
|
|
|
|
});
|
|
|
|
await this.ollamaProvider.start();
|
|
|
|
}
|
|
|
|
if (this.options.exo) {
|
|
|
|
this.exoProvider = new ExoProvider({
|
|
|
|
exoBaseUrl: this.options.exo.baseUrl,
|
|
|
|
apiKey: this.options.exo.apiKey,
|
|
|
|
});
|
|
|
|
await this.exoProvider.start();
|
2024-04-29 11:18:40 +02:00
|
|
|
}
|
2024-04-25 10:49:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public async stop() {}
|
2024-04-04 02:47:44 +02:00
|
|
|
|
|
|
|
/**
|
2024-04-29 11:18:40 +02:00
|
|
|
* create a new conversation
|
2024-04-04 02:47:44 +02:00
|
|
|
*/
|
2024-04-29 11:18:40 +02:00
|
|
|
createConversation(provider: TProvider) {
|
|
|
|
switch (provider) {
|
2025-02-08 12:08:14 +01:00
|
|
|
case 'exo':
|
|
|
|
return Conversation.createWithExo(this);
|
2024-04-29 11:18:40 +02:00
|
|
|
case 'openai':
|
|
|
|
return Conversation.createWithOpenAi(this);
|
|
|
|
case 'anthropic':
|
|
|
|
return Conversation.createWithAnthropic(this);
|
|
|
|
case 'perplexity':
|
|
|
|
return Conversation.createWithPerplexity(this);
|
|
|
|
case 'ollama':
|
|
|
|
return Conversation.createWithOllama(this);
|
2025-02-08 12:08:14 +01:00
|
|
|
case 'groq':
|
|
|
|
return Conversation.createWithGroq(this);
|
|
|
|
case 'xai':
|
|
|
|
return Conversation.createWithXai(this);
|
2024-04-29 11:18:40 +02:00
|
|
|
default:
|
|
|
|
throw new Error('Provider not available');
|
|
|
|
}
|
2024-04-04 02:47:44 +02:00
|
|
|
}
|
|
|
|
}
|