mirror of
https://github.com/zylon-ai/private-gpt.git
synced 2025-12-22 04:30:11 +01:00
feat(llm): Support for Google Gemini LLMs and Embeddings (#1965)
Some checks are pending
publish docs / publish-docs (push) Waiting to run
release-please / release-please (push) Waiting to run
tests / setup (push) Waiting to run
tests / ${{ matrix.quality-command }} (black) (push) Blocked by required conditions
tests / ${{ matrix.quality-command }} (mypy) (push) Blocked by required conditions
tests / ${{ matrix.quality-command }} (ruff) (push) Blocked by required conditions
tests / test (push) Blocked by required conditions
tests / all_checks_passed (push) Blocked by required conditions
Some checks are pending
publish docs / publish-docs (push) Waiting to run
release-please / release-please (push) Waiting to run
tests / setup (push) Waiting to run
tests / ${{ matrix.quality-command }} (black) (push) Blocked by required conditions
tests / ${{ matrix.quality-command }} (mypy) (push) Blocked by required conditions
tests / ${{ matrix.quality-command }} (ruff) (push) Blocked by required conditions
tests / test (push) Blocked by required conditions
tests / all_checks_passed (push) Blocked by required conditions
* Support for Google Gemini LLMs and Embeddings Initial support for Gemini, enables usage of Google LLMs and embedding models (see settings-gemini.yaml) Install via poetry install --extras "llms-gemini embeddings-gemini" Notes: * had to bump llama-index-core to later version that supports Gemini * poetry --no-update did not work: Gemini/llama_index seem to require more (transient) updates to make it work... * fix: crash when gemini is not selected * docs: add gemini llm --------- Co-authored-by: Javier Martinez <javiermartinezalvarez98@gmail.com>
This commit is contained in:
parent
19a7c065ef
commit
fc13368bc7
9 changed files with 382 additions and 59 deletions
|
|
@ -99,6 +99,20 @@ class EmbeddingComponent:
|
|||
azure_endpoint=azopenai_settings.azure_endpoint,
|
||||
api_version=azopenai_settings.api_version,
|
||||
)
|
||||
case "gemini":
|
||||
try:
|
||||
from llama_index.embeddings.gemini import ( # type: ignore
|
||||
GeminiEmbedding,
|
||||
)
|
||||
except ImportError as e:
|
||||
raise ImportError(
|
||||
"Gemini dependencies not found, install with `poetry install --extras embeddings-gemini`"
|
||||
) from e
|
||||
|
||||
self.embedding_model = GeminiEmbedding(
|
||||
api_key=settings.gemini.api_key,
|
||||
model_name=settings.gemini.embedding_model,
|
||||
)
|
||||
case "mock":
|
||||
# Not a random number, is the dimensionality used by
|
||||
# the default embedding model
|
||||
|
|
|
|||
|
|
@ -190,5 +190,18 @@ class LLMComponent:
|
|||
azure_endpoint=azopenai_settings.azure_endpoint,
|
||||
api_version=azopenai_settings.api_version,
|
||||
)
|
||||
case "gemini":
|
||||
try:
|
||||
from llama_index.llms.gemini import ( # type: ignore
|
||||
Gemini,
|
||||
)
|
||||
except ImportError as e:
|
||||
raise ImportError(
|
||||
"Google Gemini dependencies not found, install with `poetry install --extras llms-gemini`"
|
||||
) from e
|
||||
gemini_settings = settings.gemini
|
||||
self.llm = Gemini(
|
||||
model_name=gemini_settings.model, api_key=gemini_settings.api_key
|
||||
)
|
||||
case "mock":
|
||||
self.llm = MockLLM()
|
||||
|
|
|
|||
|
|
@ -82,7 +82,14 @@ class DataSettings(BaseModel):
|
|||
|
||||
class LLMSettings(BaseModel):
|
||||
mode: Literal[
|
||||
"llamacpp", "openai", "openailike", "azopenai", "sagemaker", "mock", "ollama"
|
||||
"llamacpp",
|
||||
"openai",
|
||||
"openailike",
|
||||
"azopenai",
|
||||
"sagemaker",
|
||||
"mock",
|
||||
"ollama",
|
||||
"gemini",
|
||||
]
|
||||
max_new_tokens: int = Field(
|
||||
256,
|
||||
|
|
@ -157,7 +164,9 @@ class HuggingFaceSettings(BaseModel):
|
|||
|
||||
|
||||
class EmbeddingSettings(BaseModel):
|
||||
mode: Literal["huggingface", "openai", "azopenai", "sagemaker", "ollama", "mock"]
|
||||
mode: Literal[
|
||||
"huggingface", "openai", "azopenai", "sagemaker", "ollama", "mock", "gemini"
|
||||
]
|
||||
ingest_mode: Literal["simple", "batch", "parallel", "pipeline"] = Field(
|
||||
"simple",
|
||||
description=(
|
||||
|
|
@ -220,6 +229,18 @@ class OpenAISettings(BaseModel):
|
|||
)
|
||||
|
||||
|
||||
class GeminiSettings(BaseModel):
|
||||
api_key: str
|
||||
model: str = Field(
|
||||
"models/gemini-pro",
|
||||
description="Google Model to use. Example: 'models/gemini-pro'.",
|
||||
)
|
||||
embedding_model: str = Field(
|
||||
"models/embedding-001",
|
||||
description="Google Embedding Model to use. Example: 'models/embedding-001'.",
|
||||
)
|
||||
|
||||
|
||||
class OllamaSettings(BaseModel):
|
||||
api_base: str = Field(
|
||||
"http://localhost:11434",
|
||||
|
|
@ -426,6 +447,7 @@ class Settings(BaseModel):
|
|||
huggingface: HuggingFaceSettings
|
||||
sagemaker: SagemakerSettings
|
||||
openai: OpenAISettings
|
||||
gemini: GeminiSettings
|
||||
ollama: OllamaSettings
|
||||
azopenai: AzureOpenAISettings
|
||||
vectorstore: VectorstoreSettings
|
||||
|
|
|
|||
|
|
@ -444,6 +444,7 @@ class PrivateGptUi:
|
|||
"sagemaker": config_settings.sagemaker.llm_endpoint_name,
|
||||
"mock": llm_mode,
|
||||
"ollama": config_settings.ollama.llm_model,
|
||||
"gemini": config_settings.gemini.model,
|
||||
}
|
||||
|
||||
if llm_mode not in model_mapping:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue