Merge pull request #9 from lfnovo/gemini

Gemini support
This commit is contained in:
Luis Novo 2024-10-26 05:53:23 -03:00 committed by GitHub
commit e5cc1de4dd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 30 additions and 3 deletions

View file

@ -58,6 +58,7 @@ Go to the [Usage](docs/USAGE.md) page to learn how to use all features.
- **Integrated Search Engines**: Built-in full-text and vector search for faster information retrieval. - **Integrated Search Engines**: Built-in full-text and vector search for faster information retrieval.
- **Fine-Grained Context Management**: Choose exactly what to share with the AI to maintain control. - **Fine-Grained Context Management**: Choose exactly what to share with the AI to maintain control.
- **Podcast Generator**: Automatically convert your notes into a podcast format. - **Podcast Generator**: Automatically convert your notes into a podcast format.
- **Multi-model support**: Open AI, Anthropic, Gemini, Vertex AI, Open Router, Ollama.
## 🚀 New Features ## 🚀 New Features

View file

@ -274,7 +274,7 @@ def extract_youtube_transcript(state: SourceState):
""" """
languages = CONFIG.get("youtube_transcripts", {}).get( languages = CONFIG.get("youtube_transcripts", {}).get(
"preferred_languages", ["pt", "en"] "preferred_languages", ["en", "es", "pt"]
) )
video_id = _extract_youtube_id(state.get("url")) video_id = _extract_youtube_id(state.get("url"))

View file

@ -1,5 +1,6 @@
from open_notebook.llms import ( from open_notebook.llms import (
AnthropicLanguageModel, AnthropicLanguageModel,
GeminiLanguageModel,
LiteLLMLanguageModel, LiteLLMLanguageModel,
OllamaLanguageModel, OllamaLanguageModel,
OpenAILanguageModel, OpenAILanguageModel,
@ -17,6 +18,7 @@ PROVIDER_CLASS_MAP = {
"vertexai": VertexAILanguageModel, "vertexai": VertexAILanguageModel,
"anthropic": AnthropicLanguageModel, "anthropic": AnthropicLanguageModel,
"openai": OpenAILanguageModel, "openai": OpenAILanguageModel,
"gemini": GeminiLanguageModel,
} }

View file

@ -10,6 +10,7 @@ from typing import Any, Dict, Optional
from langchain_anthropic import ChatAnthropic from langchain_anthropic import ChatAnthropic
from langchain_community.chat_models import ChatLiteLLM from langchain_community.chat_models import ChatLiteLLM
from langchain_core.language_models.chat_models import BaseChatModel from langchain_core.language_models.chat_models import BaseChatModel
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain_google_vertexai import ChatVertexAI from langchain_google_vertexai import ChatVertexAI
from langchain_google_vertexai.model_garden import ChatAnthropicVertex from langchain_google_vertexai.model_garden import ChatAnthropicVertex
from langchain_ollama.chat_models import ChatOllama from langchain_ollama.chat_models import ChatOllama
@ -62,7 +63,7 @@ class OllamaLanguageModel(LanguageModel):
base_url=self.base_url, base_url=self.base_url,
# keep_alive="10m", # keep_alive="10m",
num_predict=self.max_tokens, num_predict=self.max_tokens,
temperature=self.temperature, temperature=self.temperature or 0.5,
verbose=True, verbose=True,
top_p=self.top_p, top_p=self.top_p,
) )
@ -90,6 +91,7 @@ class VertexAnthropicLanguageModel(LanguageModel):
streaming=False, streaming=False,
kwargs=self.kwargs, kwargs=self.kwargs,
top_p=self.top_p, top_p=self.top_p,
temperature=self.temperature or 0.5,
) )
@ -136,6 +138,26 @@ class VertexAILanguageModel(LanguageModel):
location=self.location, location=self.location,
project=self.project, project=self.project,
safety_settings=None, safety_settings=None,
temperature=self.temperature or 0.5,
)
@dataclass
class GeminiLanguageModel(LanguageModel):
"""
Language model that uses the Gemini Family of chat models.
"""
model_name: str
def to_langchain(self) -> ChatGoogleGenerativeAI:
"""
Convert the language model to a LangChain chat model.
"""
return ChatGoogleGenerativeAI(
model=self.model_name,
max_tokens=self.max_tokens,
temperature=self.temperature or 0.5,
) )
@ -188,6 +210,7 @@ class AnthropicLanguageModel(LanguageModel):
streaming=False, streaming=False,
timeout=30, timeout=30,
top_p=self.top_p, top_p=self.top_p,
temperature=self.temperature or 0.5,
) )

2
poetry.lock generated
View file

@ -6063,4 +6063,4 @@ type = ["pytest-mypy"]
[metadata] [metadata]
lock-version = "2.0" lock-version = "2.0"
python-versions = "^3.11" python-versions = "^3.11"
content-hash = "b92bbd2ce61e78ccc2e182627cf0ba5d98ccf849898e5e941d5d17e74a7827ab" content-hash = "5f7bdea405c6c6433fa805b3321ac1550e13deee0d3a3c04e38136cd6992f5b1"

View file

@ -39,6 +39,7 @@ langchain-anthropic = "^0.2.3"
langchain-ollama = "^0.2.0" langchain-ollama = "^0.2.0"
langchain-google-vertexai = "^2.0.5" langchain-google-vertexai = "^2.0.5"
sdblpy = "^0.3.0" sdblpy = "^0.3.0"
langchain-google-genai = "^2.0.1"
podcastfy = "^0.2.8" podcastfy = "^0.2.8"
[tool.poetry.group.dev.dependencies] [tool.poetry.group.dev.dependencies]