-
Notifications
You must be signed in to change notification settings - Fork 0
/
ai_provider.py
49 lines (38 loc) · 1.27 KB
/
ai_provider.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import utils
from abc import ABC, abstractmethod
class AIProvider(ABC):
@abstractmethod
def name(self):
pass
def supports_sessions(self):
return False
@abstractmethod
def _list_models(self):
pass
def list_models(self, cache_directory_path):
return utils.list_models(self.name(), self._list_models, True, cache_directory_path)
@abstractmethod
def chat_completion(self, messages, model, stream=False):
pass
@abstractmethod
def convert_result_to_text(self, result, sources, handle_metadata_func):
pass
@abstractmethod
def convert_chunk_to_text(self, chunk, text_chunks, sources, handle_metadata_func):
pass
def remove_source_references(self, text):
return text
@abstractmethod
def close(self):
pass
def get_ai_providers():
providers = []
from passthrough_ai_provider import PassthroughProvider
providers.append(PassthroughProvider())
from openai_ai_provider import OpenAIProvider
providers.append(OpenAIProvider())
from anthropic_ai_provider import AnthropicAIProvider
providers.append(AnthropicAIProvider())
from perplexity_ai_provider import PerplexityAiProvider
providers.append(PerplexityAiProvider())
return providers