fix(provider): fix anthropic integration

This commit is contained in:
2024-04-29 11:18:40 +02:00
parent 9e19d320e1
commit d1465fc868
7 changed files with 90 additions and 70 deletions

View File

@@ -1,6 +1,6 @@
import { Conversation } from './classes.conversation.js';
import * as plugins from './plugins.js';
import type { AnthropicProvider } from './provider.anthropic.js';
import { AnthropicProvider } from './provider.anthropic.js';
import type { OllamaProvider } from './provider.ollama.js';
import { OpenAiProvider } from './provider.openai.js';
import type { PerplexityProvider } from './provider.perplexity.js';
@@ -12,6 +12,8 @@ export interface ISmartAiOptions {
perplexityToken?: string;
}
export type TProvider = 'openai' | 'anthropic' | 'perplexity' | 'ollama';
export class SmartAi {
public options: ISmartAiOptions;
@@ -31,21 +33,30 @@ export class SmartAi {
});
await this.openaiProvider.start();
}
if (this.options.anthropicToken) {
this.anthropicProvider = new AnthropicProvider({
anthropicToken: this.options.anthropicToken,
});
}
}
public async stop() {}
/**
* creates an OpenAI conversation
* create a new conversation
*/
public async createOpenApiConversation() {
const conversation = await Conversation.createWithOpenAi(this);
}
/**
* creates an OpenAI conversation
*/
public async createAnthropicConversation() {
const conversation = await Conversation.createWithAnthropic(this);
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');
}
}
}