Skip to content

Commit ac47ec8

Browse files
Updated gemini models (#1528)
* Updated gemini models * added tooltip * updated packages * gds related changes --------- Co-authored-by: Prakriti Solankey <156313631+prakriti-solankey@users.noreply.github.com>
1 parent 4a912a1 commit ac47ec8

19 files changed

Lines changed: 167 additions & 207 deletions

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ Run the application using the default `docker-compose` configuration.
114114
By default, only OpenAI and Diffbot are enabled. Gemini requires additional GCP configurations.
115115
Use the `VITE_LLM_MODELS_PROD` variable to configure the models you need. Example:
116116
```bash
117-
VITE_LLM_MODELS_PROD="gemini_2.5_flash,openai_gpt_5_mini,diffbot,anthropic_claude_4.5_haiku"
117+
VITE_LLM_MODELS_PROD="gemini_flash_latest,openai_gpt_5_mini,diffbot,anthropic_claude_4.5_haiku"
118118
```
119119

120120
2. **Input Sources:**
@@ -267,12 +267,12 @@ gcloud run deploy dev-backend \
267267
| VITE_REACT_APP_SOURCES | Mandatory | local,youtube,wiki,s3 | List of input sources that will be available |
268268
| VITE_CHAT_MODES | Mandatory | vector,graph+vector,graph,hybrid | Chat modes available for Q&A |
269269
| VITE_ENV | Mandatory | DEV or PROD | Environment variable for the app |
270-
| VITE_LLM_MODELS | Optional | openai_gpt_5_mini,gemini_2.5_flash,anthropic_claude_4.5_haiku | Supported models for the application |
270+
| VITE_LLM_MODELS | Optional | openai_gpt_5_mini,gemini_flash_latest,anthropic_claude_4.5_haiku | Supported models for the application |
271271
| VITE_BACKEND_API_URL | Optional | [localhost][backend-url] | URL for backend API |
272272
| VITE_TIME_PER_PAGE | Optional | 50 | Time per page for processing |
273273
| VITE_CHUNK_SIZE | Optional | 5242880 | Size of each chunk of file for upload |
274274
| VITE_GOOGLE_CLIENT_ID | Optional | | Client ID for Google authentication |
275-
| VITE_LLM_MODELS_PROD | Optional | openai_gpt_5_mini,gemini_2.5_flash,anthropic_claude_4.5_haiku | To distinguish models based on environment (PROD or DEV) |
275+
| VITE_LLM_MODELS_PROD | Optional | openai_gpt_5_mini,gemini_flash_latest,anthropic_claude_4.5_haiku | To distinguish models based on environment (PROD or DEV) |
276276
| VITE_AUTH0_CLIENT_ID | Mandatory if you are enabling Authentication otherwise it is optional | | Okta OAuth Client ID for authentication |
277277
| VITE_AUTH0_DOMAIN | Mandatory if you are enabling Authentication otherwise it is optional | | Okta OAuth Client Domain |
278278
| VITE_SKIP_AUTH | Optional | true | Flag to skip authentication |

backend/example.env

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ LLM_MODEL_CONFIG_openai_gpt_5.2="gpt-5.2,openai-key"
2929
LLM_MODEL_CONFIG_openai_gpt_5_mini="gpt-5-mini,openai-key"
3030
LLM_MODEL_CONFIG_openai_gpt_4.1="gpt-4.1,openai-key"
3131
LLM_MODEL_CONFIG_openai_gpt_4.1_mini="gpt-4.1-mini,openai-key"
32-
LLM_MODEL_CONFIG_gemini_2.5_flash="gemini-2.5-flash"
33-
LLM_MODEL_CONFIG_gemini_2.5_pro="gemini-2.5-pro"
32+
LLM_MODEL_CONFIG_gemini_flash_latest="gemini-flash-latest"
33+
LLM_MODEL_CONFIG_gemini_pro_latest="gemini-pro-latest"
3434
LLM_MODEL_CONFIG_diffbot="diffbot,diffbot_api_key"
3535
LLM_MODEL_CONFIG_groq_llama3.1_8b="llama-3.1-8b-instant,base_url,groq_api_key"
3636
LLM_MODEL_CONFIG_anthropic_claude_4.5_sonnet="claude-sonnet-4-5-20250929,anthropic_api_key"

backend/requirements.txt

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,64 @@
1-
accelerate==1.12.0
1+
accelerate==1.13.0
22
asyncio==4.0.0
3-
boto3==1.40.23
4-
botocore==1.40.23
5-
certifi==2025.8.3
6-
fastapi==0.116.1
3+
boto3==1.42.66
4+
botocore==1.42.66
5+
certifi==2026.2.25
6+
fastapi==0.135.1
77
fastapi-health==0.4.0
8-
fireworks-ai==0.15.12
9-
google-api-core==2.25.1
10-
google-auth==2.40.3
11-
google_auth_oauthlib==1.2.2
12-
google-cloud-core==2.4.3
8+
fireworks-ai==0.19.20
9+
google-api-core==2.30.0
10+
google-auth==2.49.0
11+
google_auth_oauthlib==1.3.0
12+
google-cloud-core==2.5.0
1313
json-repair==0.44.1
1414
pip-install==1.3.5
15-
langchain==1.1.2
16-
langchain-aws==1.1.0
17-
langchain-anthropic==1.2.0
15+
langchain==1.2.12
16+
langchain-aws==1.4.0
17+
langchain-anthropic==1.3.4
1818
langchain-fireworks==1.1.0
1919
langchain-community==0.4.1
20-
langchain-core==1.2.5
21-
langchain-experimental==0.4.0
22-
langchain-google-vertexai==3.1.1
23-
langchain-groq==1.1.0
24-
langchain-openai==1.1.0
25-
langchain-text-splitters==1.0.0
26-
langchain-huggingface==1.1.0
20+
langchain-core==1.2.18
21+
langchain-experimental==0.4.1
22+
langchain_google_genai==4.2.1
23+
langchain-groq==1.1.2
24+
langchain-openai==1.1.11
25+
langchain-text-splitters==1.1.1
26+
langchain-huggingface==1.2.1
2727
langchain-classic==1.0.0
2828
langdetect==1.0.9
2929
langsmith==0.4.55
3030
langserve==0.3.3
3131
neo4j-rust-ext==5.28.2.1
32-
nltk==3.9.1
33-
openai==2.9.0
34-
psutil==7.0.0
32+
nltk==3.9.3
33+
openai==2.26.0
34+
psutil==7.2.2
3535
pydantic==2.12.5
3636
python-dotenv==1.1.1
3737
python-magic==0.4.27
3838
PyPDF2==3.0.1
39-
PyMuPDF==1.26.4
39+
PyMuPDF==1.27.2
4040
starlette==0.47.3
4141
sse-starlette==3.0.2
4242
starlette-session==0.4.3
43-
tqdm==4.67.1
44-
unstructured[all-docs]==0.18.14
45-
unstructured-client==0.42.3
46-
unstructured-inference==1.0.5
47-
urllib3==2.6.2
48-
uvicorn==0.35.0
49-
gunicorn==23.0.0
43+
tqdm==4.67.3
44+
unstructured[all-docs]==0.21.5
45+
unstructured-client==0.42.10
46+
unstructured-inference==1.2.0
47+
urllib3==2.2.2
48+
uvicorn==0.41.0
49+
gunicorn==25.1.0
5050
wikipedia==1.4.0
5151
wrapt==1.17.3
5252
yarl==1.20.1
53-
youtube-transcript-api==1.2.2
53+
youtube-transcript-api==1.2.4
5454
zipp==3.23.0
5555
sentence-transformers==5.1.0
5656
google-cloud-logging==3.12.1
57-
pypandoc==1.15
58-
graphdatascience==1.18a1
57+
pypandoc==1.16.2
58+
graphdatascience==1.20
5959
Secweb==1.25.2
60-
ragas==0.4.0
60+
ragas==0.4.3
6161
rouge_score==0.1.2
62-
langchain-neo4j==0.6.0
63-
pypandoc-binary==1.15
62+
langchain-neo4j==0.7.0
63+
pypandoc-binary==1.16.2
6464
chardet==5.2.0

backend/score.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,12 +1019,14 @@ async def calculate_additional_metrics(question: str = Form(),
10191019
reference: str = Form(),
10201020
model: str = Form(),
10211021
mode: str = Form(),
1022+
embedding_provider: str = Form(None),
1023+
embedding_model: str = Form(None)
10221024
):
10231025
try:
10241026
context_list = [str(item).strip() for item in json.loads(context)] if context else []
10251027
answer_list = [str(item).strip() for item in json.loads(answer)] if answer else []
10261028
mode_list = [str(item).strip() for item in json.loads(mode)] if mode else []
1027-
result = await get_additional_metrics(question, context_list,answer_list, reference, model)
1029+
result = await get_additional_metrics(question, context_list,answer_list, reference, model, embedding_provider, embedding_model)
10281030
if result is None or "error" in result:
10291031
return create_api_response(
10301032
'Failed',

backend/src/QA_integration.py

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
from typing import Any
99
from dotenv import load_dotenv
1010

11-
from langchain_neo4j import Neo4jVector
12-
from langchain_neo4j import Neo4jChatMessageHistory
13-
from langchain_neo4j import GraphCypherQAChain
11+
from langchain_neo4j import Neo4jVector, Neo4jChatMessageHistory, GraphCypherQAChain
1412
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
1513
from langchain_core.output_parsers import StrOutputParser
1614
from langchain_core.runnables import RunnableBranch
@@ -20,10 +18,10 @@
2018
from langchain_core.messages import HumanMessage, AIMessage
2119
from langchain_community.chat_message_histories import ChatMessageHistory
2220
from langchain_core.callbacks import StdOutCallbackHandler, BaseCallbackHandler
23-
from src.shared.llm_graph_builder_exception import LLMGraphBuilderException
21+
# from src.shared.llm_graph_builder_exception import LLMGraphBuilderException
2422
# LangChain chat models
2523
from langchain_openai import ChatOpenAI, AzureChatOpenAI
26-
from langchain_google_vertexai import ChatVertexAI
24+
from langchain_google_genai import ChatGoogleGenerativeAI
2725
from langchain_groq import ChatGroq
2826
from langchain_anthropic import ChatAnthropic
2927
from langchain_fireworks import ChatFireworks
@@ -75,8 +73,12 @@ def get_total_tokens(ai_response, llm):
7573
if isinstance(llm, (ChatOpenAI, AzureChatOpenAI, ChatFireworks, ChatGroq)):
7674
total_tokens = ai_response.response_metadata.get('token_usage', {}).get('total_tokens', 0)
7775

78-
elif isinstance(llm, ChatVertexAI):
79-
total_tokens = ai_response.response_metadata.get('usage_metadata', {}).get('prompt_token_count', 0)
76+
elif isinstance(llm, ChatGoogleGenerativeAI):
77+
if hasattr(ai_response, 'usage_metadata') and ai_response.usage_metadata:
78+
total_tokens = ai_response.usage_metadata.get('total_tokens', 0)
79+
else:
80+
usage = ai_response.response_metadata.get('token_usage', {}) or ai_response.response_metadata.get('usage_metadata', {})
81+
total_tokens = usage.get('total_tokens', 0)
8082

8183
elif isinstance(llm, ChatBedrock):
8284
total_tokens = ai_response.response_metadata.get('usage', {}).get('total_tokens', 0)
@@ -224,6 +226,13 @@ def format_documents(documents, model,chat_mode_settings):
224226

225227
return "\n\n".join(formatted_docs), sources,entities,global_communities
226228

229+
def get_clean_text(msg):
230+
if isinstance(msg.content, str):
231+
return msg.content
232+
return msg.additional_kwargs.get("text", "") or "".join(
233+
[p.get("text", "") for p in msg.content if isinstance(p, dict)]
234+
)
235+
227236
def process_documents(docs, question, messages, llm, model,chat_mode_settings):
228237
start_time = time.time()
229238

@@ -256,7 +265,7 @@ def process_documents(docs, question, messages, llm, model,chat_mode_settings):
256265
result["nodedetails"] = node_details
257266
result["entities"] = entities
258267

259-
content = ai_response.content
268+
content = get_clean_text(ai_response)
260269
total_tokens = get_total_tokens(ai_response, llm)
261270

262271
predict_time = time.time() - start_time
@@ -508,33 +517,41 @@ def summarize_and_log(history, stored_messages, llm):
508517
try:
509518
start_time = time.time()
510519

511-
summarization_prompt = ChatPromptTemplate.from_messages(
512-
[
513-
MessagesPlaceholder(variable_name="chat_history"),
514-
(
515-
"human",
516-
"Summarize the above chat messages into a concise message, focusing on key points and relevant details that could be useful for future conversations. Exclude all introductions and extraneous information."
517-
),
518-
]
519-
)
520+
summarization_prompt = ChatPromptTemplate.from_messages([
521+
MessagesPlaceholder(variable_name="chat_history"),
522+
("human", "Summarize the above chat messages into a concise message..."),
523+
])
524+
520525
summarization_chain = summarization_prompt | llm
521526

522-
summary_message = summarization_chain.invoke({"chat_history": stored_messages})
527+
raw_summary = summarization_chain.invoke({"chat_history": stored_messages})
528+
529+
if hasattr(raw_summary, "content"):
530+
content = raw_summary.content
531+
if isinstance(content, list):
532+
summary_text = "".join([
533+
block.get("text", "") if isinstance(block, dict) else str(block)
534+
for block in content
535+
])
536+
else:
537+
summary_text = str(content)
538+
else:
539+
summary_text = str(raw_summary)
540+
541+
summary_message_for_db = AIMessage(content=summary_text)
523542

524543
with threading.Lock():
525544
history.clear()
526545
history.add_user_message("Our current conversation summary till now")
527-
history.add_message(summary_message)
528-
529-
history_summarized_time = time.time() - start_time
530-
logging.info(f"Chat History summarized in {history_summarized_time:.2f} seconds")
546+
history.add_message(summary_message_for_db)
531547

548+
logging.info(f"Chat History summarized in {time.time() - start_time:.2f} seconds")
532549
return True
533550

534551
except Exception as e:
535552
logging.error(f"An error occurred while summarizing messages: {e}", exc_info=True)
536-
return False
537-
553+
return False
554+
538555
def create_graph_chain(model, graph):
539556
try:
540557
logging.info(f"Graph QA Chain using LLM model: {model}")

backend/src/graphDB_dataAccess.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -199,22 +199,27 @@ def check_account_access(self, database):
199199
return False
200200

201201
def check_gds_version(self):
202-
try:
203-
gds_procedure_count = """
204-
SHOW FUNCTIONS YIELD name WHERE name STARTS WITH 'gds.version' RETURN COUNT(*) AS totalGdsProcedures
205-
"""
206-
result = self.graph.query(gds_procedure_count,session_params={"database":self.graph._database})
207-
total_gds_procedures = result[0]['totalGdsProcedures'] if result else 0
202+
try:
203+
gds_check_query = "RETURN gds.version() AS gdsVersion"
204+
result = self.graph.query(gds_check_query, session_params={"database": self.graph._database})
205+
206+
version = result[0]['gdsVersion'] if result else None
208207

209-
if total_gds_procedures > 0:
210-
logging.info("GDS is available in the database.")
211-
return True
212-
else:
213-
logging.info("GDS is not available in the database.")
214-
return False
215-
except Exception as e:
216-
logging.error(f"An error occurred while checking GDS version: {e}")
217-
return False
208+
if version:
209+
logging.info(f"GDS compute engine is available. Version: {version}")
210+
return True
211+
else:
212+
logging.info("GDS check returned empty.")
213+
return False
214+
215+
except Exception as e:
216+
error_msg = str(e)
217+
if "versionless" in error_msg or "Unknown function" in error_msg:
218+
logging.info("GDS compute engine is not provisioned on this database instance.")
219+
return False
220+
else:
221+
logging.error(f"An unexpected error occurred while verifying GDS: {e}")
222+
return False
218223

219224
def connection_check_and_get_vector_dimensions(self, database, email, uri):
220225
"""

backend/src/llm.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
from langchain_core.documents import Document
33
import os
44
from langchain_openai import ChatOpenAI, AzureChatOpenAI
5-
from langchain_google_vertexai import ChatVertexAI
5+
from langchain_google_genai import ChatGoogleGenerativeAI
66
from langchain_groq import ChatGroq
7-
from langchain_google_vertexai import HarmBlockThreshold, HarmCategory
87
from langchain_experimental.graph_transformers.diffbot import DiffbotGraphTransformer
98
from langchain_experimental.graph_transformers import LLMGraphTransformer
109
from langchain_experimental.graph_transformers.llm import _Graph
@@ -39,18 +38,19 @@ def get_llm(model: str):
3938
if "GEMINI" in model:
4039
model_name = env_value
4140
credentials, project_id = google.auth.default()
42-
llm = ChatVertexAI(
43-
model_name=model_name,
41+
llm = ChatGoogleGenerativeAI(
42+
model=model_name,
43+
vertexai=True,
4444
credentials=credentials,
4545
project=project_id,
4646
temperature=0,
4747
callbacks=callback_manager,
4848
safety_settings={
49-
HarmCategory.HARM_CATEGORY_UNSPECIFIED: HarmBlockThreshold.BLOCK_NONE,
50-
HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: HarmBlockThreshold.BLOCK_NONE,
51-
HarmCategory.HARM_CATEGORY_HATE_SPEECH: HarmBlockThreshold.BLOCK_NONE,
52-
HarmCategory.HARM_CATEGORY_HARASSMENT: HarmBlockThreshold.BLOCK_NONE,
53-
HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT: HarmBlockThreshold.BLOCK_NONE,
49+
"HARM_CATEGORY_UNSPECIFIED": "BLOCK_NONE",
50+
"HARM_CATEGORY_DANGEROUS_CONTENT": "BLOCK_NONE",
51+
"HARM_CATEGORY_HATE_SPEECH": "BLOCK_NONE",
52+
"HARM_CATEGORY_HARASSMENT": "BLOCK_NONE",
53+
"HARM_CATEGORY_SEXUALLY_EXPLICIT": "BLOCK_NONE",
5454
},
5555

5656
)

backend/src/shared/common_fn.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import logging
1111
from urllib.parse import urlparse,parse_qs
1212
from src.shared.llm_graph_builder_exception import LLMGraphBuilderException
13-
from langchain_google_vertexai import VertexAIEmbeddings
13+
from langchain_google_genai import GoogleGenerativeAIEmbeddings
1414
from langchain_openai import OpenAIEmbeddings
1515
from langchain_neo4j import Neo4jGraph
1616
from neo4j.exceptions import TransientError
@@ -200,7 +200,7 @@ def load_embedding_model(embedding_provider: str, embedding_model_name: str):
200200
if provider == "openai":
201201
embeddings = OpenAIEmbeddings(model=model)
202202
elif provider == "gemini":
203-
embeddings = VertexAIEmbeddings(model=model)
203+
embeddings = GoogleGenerativeAIEmbeddings(model=model, vertexai= True)
204204
elif provider == "titan":
205205
embeddings = _get_bedrock_embeddings(model)
206206
elif provider == "sentence-transformer":

backend/src/shared/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@
247247
CHAT_EMBEDDING_FILTER_SCORE_THRESHOLD = 0.10
248248

249249
CHAT_TOKEN_CUT_OFF = {
250-
("gemini_2.5_pro", "gemini_2.5_flash","groq-llama3",'groq_llama3_70b','anthropic_claude_4_5_sonnet','anthropic_claude_4') : 4,
250+
("gemini_pro_latest", "gemini_flash_latest","groq-llama3",'groq_llama3_70b','anthropic_claude_4_5_sonnet','anthropic_claude_4') : 4,
251251
("openai_gpt_5.2","diffbot","openai_gpt_5_mini") : 28,
252252
("ollama_llama3") : 2
253253
}

backend/src/shared/schema_extraction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from typing import List
2-
from pydantic.v1 import BaseModel, Field
2+
from pydantic import BaseModel, Field
33
from src.llm import get_llm
44
from langchain_core.prompts import ChatPromptTemplate
55
import logging

0 commit comments

Comments
 (0)