Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add non-GCP PALM providers #579

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/advanced/app_types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,14 @@ app = CustomApp(
- GPT4ALL
- AZURE_OPENAI
- LLAMA2
- PALM
- Following embedding functions are available for an embedding function
- OPENAI
- HUGGING_FACE
- VERTEX_AI
- GPT4ALL
- AZURE_OPENAI
- PALM


### PersonApp
Expand Down
26 changes: 26 additions & 0 deletions embedchain/embedder/palm_embedder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os
from typing import Optional

from langchain.embeddings import GooglePalmEmbeddings

from embedchain.config import BaseEmbedderConfig
from embedchain.embedder.base_embedder import BaseEmbedder
from embedchain.models import EmbeddingFunctions


class PalmEmbedder(BaseEmbedder):
def __init__(self, config: Optional[BaseEmbedderConfig] = None):
super().__init__(config=config)

if os.getenv("GOOGLE_API_KEY") is None:
raise ValueError("GOOGLE_API_KEY environment variables not provided")

model = "models/embedding-gecko-001"
if (config is not None) and (config.model is not None):
model = config.model

embeddings = GooglePalmEmbeddings(model_name=model)
embedding_fn = BaseEmbedder._langchain_default_concept(embeddings)

self.set_embedding_fn(embedding_fn=embedding_fn)
self.set_vector_dimension(vector_dimension=EmbeddingFunctions.PALM.value)
31 changes: 31 additions & 0 deletions embedchain/llm/palm_llm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import os
from typing import Optional

from embedchain.config import BaseLlmConfig
from embedchain.helper_classes.json_serializable import register_deserializable
from embedchain.llm.base_llm import BaseLlm


@register_deserializable
class PalmLlm(BaseLlm):
def __init__(self, config: Optional[BaseLlmConfig] = None):
super().__init__(config=config)

def get_llm_model_answer(self, prompt):
return PalmLlm._get_athrophic_answer(prompt=prompt, config=self.config)

@staticmethod
def _get_athrophic_answer(prompt: str, config: BaseLlmConfig) -> str:
if os.getenv("GOOGLE_API_KEY") is None:
raise ValueError("GOOGLE_API_KEY environment variables not provided")

from langchain.chat_models import ChatGooglePalm

model = "models/chat-bison-001"
deshraj marked this conversation as resolved.
Show resolved Hide resolved
if (config is not None) and (config.model is not None):
model = config.model

chat = ChatGooglePalm(temperature=config.temperature, top_p=config.top_p, model_name=model)
messages = BaseLlm._get_messages(prompt, system_prompt=config.system_prompt)

return chat(messages).content
1 change: 1 addition & 0 deletions embedchain/models/EmbeddingFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ class EmbeddingFunctions(Enum):
HUGGING_FACE = "HUGGING_FACE"
VERTEX_AI = "VERTEX_AI"
GPT4ALL = "GPT4ALL"
PALM = "PALM"
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ youtube-transcript-api = "^0.6.1"
beautifulsoup4 = "^4.12.2"
pypdf = "^3.11.0"
pytube = "^15.0.0"
google-generativeai = "^0.1.0"
cachho marked this conversation as resolved.
Show resolved Hide resolved
llama-index = { version = "^0.7.21", optional = true }
sentence-transformers = { version = "^2.2.2", optional = true }
torch = { version = ">=2.0.0, !=2.0.1", optional = true }
Expand Down