Add Groq Support (#1481)

This commit is contained in:
Dev Khant
2024-07-16 23:33:28 +05:30
committed by GitHub
parent 80f145fceb
commit 19637804b3
11 changed files with 369 additions and 6 deletions

41
mem0/utils/factory.py Normal file
View File

@@ -0,0 +1,41 @@
import importlib
def load_class(class_type):
module_path, class_name = class_type.rsplit(".", 1)
module = importlib.import_module(module_path)
return getattr(module, class_name)
class LlmFactory:
provider_to_class = {
"ollama": "mem0.llms.ollama.py.OllamaLLM",
"openai": "mem0.llms.openai.OpenAILLM",
"groq": "mem0.llms.groq.GroqLLM"
}
@classmethod
def create(cls, provider_name):
class_type = cls.provider_to_class.get(provider_name)
if class_type:
llm_instance = load_class(class_type)()
return llm_instance
else:
raise ValueError(f"Unsupported Llm provider: {provider_name}")
class EmbedderFactory:
provider_to_class = {
"openai": "mem0.embeddings.openai.OpenAIEmbedding",
"ollama": "mem0.embeddings.ollama.OllamaEmbedding",
"huggingface": "mem0.embeddings.huggingface.HuggingFaceEmbedding"
}
@classmethod
def create(cls, provider_name):
class_type = cls.provider_to_class.get(provider_name)
if class_type:
embedder_instance = load_class(class_type)()
return embedder_instance
else:
raise ValueError(f"Unsupported Embedder provider: {provider_name}")